-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathts-build.sh
executable file
·104 lines (89 loc) · 2.05 KB
/
ts-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
#!/bin/sh
set -e
# Purposefully not using `set -o xtrace`, for friendlier output.
# Presentational variables and functions declaration.
BLUE="\033[0;34m"
GREEN="\033[0;32m"
YELLOW="\033[0;33m"
RED="\033[0;31m"
NOCOLOR="\033[0m"
DIM="\033[2m"
blue() {
printf "${BLUE}$1${NOCOLOR}"
}
green() {
printf "${GREEN}$1${NOCOLOR}"
}
yellow() {
printf "${YELLOW}$1${NOCOLOR}"
}
red() {
printf "${RED}$1${NOCOLOR}"
}
dim() {
printf "${DIM}$1${NOCOLOR}"
}
# Build function declaration.
build_node() {
blue "[Node build] "
echo "Adding ./dist/cjs/package.json"
if ! [ -d ./dist/cjs ];
then
mkdir ./dist/cjs
fi
rm -f ./dist/cjs/package.json
cat <<EOT >> ./dist/cjs/package.json
{
"type": "commonjs"
}
EOT
echo "> npm run build:node"
printf "${BLUE}[Node build] Working...\n"
# Transpile ESM code to CJS using Babel and place in dist/cjs
npx babel --config-file ./.babelrc dist/esm --out-dir dist/cjs --copy-files
green "DONE"
echo "\n";
}
build_esm() {
if [ -f ./tsconfig.prod.esm.json ];
then
blue "[ESM build] "
echo "Using tsconfig.prod.esm.json"
echo "> tsc --build ./tsconfig.prod.esm.json"
printf "${BLUE}[ESM build] Working... "
# Compile ESM code using Typescript compiler
npx tsc --build ./tsconfig.prod.esm.json
# Copy WASM wrapper code to ESM build
cp -rf ./src.ts/wasm ./dist/esm
green "DONE"
else
echo "Skipping ESM build (no config available)."
fi
echo "\n";
}
post_build_fixes() {
blue "[Post Build Fixes]"
if [ -f ./dist/esm/index.js ];
then
echo "Adding ./dist/cjs/package.json"
rm -f ./dist/cjs/package.json
cat <<EOT >> ./dist/cjs/package.json
{
"type": "commonjs"
}
EOT
echo "Adding ./dist/esm/package.json"
rm -f ./dist/esm/package.json
cat <<EOT >> ./dist/esm/package.json
{
"type": "module"
}
EOT
else
echo "Skipping post build fixes (no ESM setup yet)."
fi
echo "\n";
}
build_esm
build_node
post_build_fixes