-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathbuild.sh
executable file
·125 lines (101 loc) · 4.41 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/bash
set -e # exit immediately on error
set -o nounset # abort on unbound variable
set -o pipefail # don't hide errors within pipes
# set -x # for debuging, trace what is being executed.
export BASENAME="\033[40m Compute Engine \033[0;0m " # `basename "$0"`
# export DOT="\033[32m \033[0m" # Gear
# export DOT="\033[32m \033[0m" # Watch
# export DOT="\033[32m 羽 😀 ⧖⧗⏳⌛️⚙⛭⚙️\033[0;0m" # Hourglass
export DOT="\033[32m ⚙ \033[0;0m" # Gear
export CHECK="\033[32m ✔ \033[0;0m"
export ERROR="\033[31;7m ERROR \033[0;0m"
export LINECLEAR="\033[1G\033[2K" # position to column 1; erase whole line
export DIM="\033[0;2m"
export RESET="\033[0;0m"
# Note on the `sed` command:
# On Linux, the -i switch can be used without an extension argument
# On macOS, the -i switch must be followed by an extension argument (which can be empty)
# On Windows, the argument of the -i switch is optional, but if present it must follow it immediately without a space in between
sedi () {
sed --version >/dev/null 2>&1 && sed -i -- "$@" || sed -i '' "$@"
}
export -f sedi
cd "$(dirname "$0")/.."
if [ "$#" -gt 1 ]; then
echo -e "$BASENAME$ERROR Expected at most one argument: 'development' (default), 'watch' or 'production'"
exit 1
fi
# Check that correct version of npm and node are installed
npx check-node-version --package
# If no "node_modules" directory, do an install first
if [ ! -d "./node_modules" ]; then
printf "$BASENAME${DOT}Installing dependencies"
npm install
echo -e "$LINECLEAR$BASENAME${CHECK}Dependencies installed"
fi
# Read the first argument, set it to "production" if not set
# (Note: we use es-build (via `npm start`) for development builds usually)
export BUILD="${1-production}"
# export TARGETS="math-json cortex compute-engine"
export TARGETS="math-json compute-engine"
# export GIT_VERSION=`git describe --long --dirty`
export SDK_VERSION=$(cat package.json \
| grep version \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g' \
| tr -d '[[:space:]]')
# Clean output directories
# printf "$BASENAME$DOT${RESET} Cleaning output directories"
rm -rf ./dist
rm -rf ./declarations
rm -rf ./build
rm -rf ./coverage
mkdir -p dist
# echo -e $LINECLEAR$BASENAME$CHECK${DIM}" Cleaning output directories"$RESET
#
# Build declaration files (.d.ts)
#
printf "$BASENAME$DOT Building TypeScript declaration files (.d.ts)"
# Even though we only generate declaration file, the target must be set high-enough
# to prevent tsc from complaining (!)
if [[ "$TARGETS" == *math-json* ]]; then
npx tsc --target "es2020" -d --moduleResolution "node" --allowImportingTsExtensions "true" \
--emitDeclarationOnly --outDir ./dist/types ./src/math-json.ts
fi
if [[ "$TARGETS" == *compute-engine* ]]; then
npx tsc --target "es2020" -d --moduleResolution "node" --allowImportingTsExtensions "true" \
--emitDeclarationOnly --outDir ./dist/types ./src/compute-engine.ts
fi
if [[ "$TARGETS" == *cortex* ]]; then
npx tsc --target "es2020" -d --moduleResolution "node" --allowImportingTsExtensions "true" \
--emitDeclarationOnly --outDir ./dist/types ./src/cortex.ts
fi
echo -e $LINECLEAR$BASENAME$CHECK$DIM" Building TypeScript declaration files$RESET"
#
# Do build (development or production)
#
printf $BASENAME$DOT$RESET" Making a \033[33m$BUILD\033[0m build"
# To get more details about errors, uncomment the following line
# export NODE_DEBUG=esm
# The '--no-warnings' option is used to suppress a warning about importing
# the package.json file in build.mjs.
node --no-warnings ./scripts/build.mjs
if [ "$BUILD" = "production" ]; then
# Linting
# printf "$BASENAME$DOT Linting"
# npm run lint
# echo -e $LINECLEAR$BASENAME$CHECK$DIM" Linting$RESET"
# Stamp the SDK version number
find ./dist -type f \( -name '*.js' -o -name '*.mjs' -name '*.cjs'\) -exec bash -c 'sedi s/{{SDK_VERSION}}/$SDK_VERSION/g {}' \;
find ./dist -type f -name '*.d.ts' -exec bash -c 'sedi "1s/^/\/\* $SDK_VERSION \*\/$(printf '"'"'\r'"'"')/" {}' \;
find ./dist -type f -name '*.d.ts' -exec bash -c 'sedi "s/{{SDK_VERSION}}/$SDK_VERSION/" {}' \;
# Build the docs
bash ./scripts/doc.sh
# Run test suite
# printf "$BASENAME$DOT Running test suite"
# npx jest --config ./config/jest.config.cjs ./test --silent --reporters jest-silent-reporter
# echo -e $LINECLEAR$BASENAME$CHECK$DIM" Running test suite$RESET"
fi
echo -e $LINECLEAR$BASENAME$CHECK$DIM" Making a \033[33m$BUILD$DIM build"