Repository navigation
Expand file tree
/
Copy pathts-build.sh
More file actions
executable file
·123 lines (101 loc) · 2.29 KB
/
Copy pathts-build.sh
File metadata and controls
executable file
·123 lines (101 loc) · 2.29 KB
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
#!/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 "Using tsconfig.prod.cjs.json"
echo "> tsc --build ./tsconfig.prod.cjs.json"
printf "${BLUE}[Node build] Working... "
tsc --build ./tsconfig.prod.cjs.json
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... "
tsc --build ./tsconfig.prod.esm.json
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_browser() {
if [ -f ./tsconfig.browser.json ];
then
blue "[Browser build] "
echo "Using tsconfig.browser.json"
echo "> tsc -p ./tsconfig.browser.json"
blue "[Browser build] "
printf "Working... "
tsc -p ./tsconfig.browser.json
RETURN_CODE=$?
if [ $RETURN_CODE -eq 0 ]; then
green "DONE"
else
exit $RETURN_CODE
fi
else
dim "Skipping browser build, because no tsconfig.browser.json file is present."
fi
echo "\n";
}
# Begin build process.
if [ "$1" = "browser" ];
then
build_browser
else
build_node
build_esm
post_build_fixes
fi