-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild_sicp_package.sh
executable file
·68 lines (56 loc) · 1.9 KB
/
build_sicp_package.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
#! /bin/bash
SICPJSPATH=sicp_publish/dist/sicp.js
main() {
clean
yarn build
prepare
node dist/sicp-prepare.js
write
}
clean() {
# Prepare to write sicp_publish/dist/sicp.js again
rm -f sicp_publish/prelude.txt
rm -f sicp_publish/names.txt
}
prepare() {
# Copy and keep only necessary files
rm -rf sicp_publish/dist
cp -r dist sicp_publish
mkdir -p sicp_publish/dist
cd sicp_publish/dist
find . -type f ! -name '*.js' -delete
# Remove unnecessary dependencies
rm -r __tests__
rm finder.js index.js scope-refactoring.js sicp-prepare.js
cd ../..
}
write() {
echo "\"use strict\";" >> $SICPJSPATH
echo "Object.defineProperty(exports, \"__esModule\", { value: true });" >> $SICPJSPATH
echo "const createContext_1 = require(\"./createContext\");" >> $SICPJSPATH
echo "const dict = createContext_1.default(4).nativeStorage.builtins;" >> $SICPJSPATH
echo $'\n// Declare functions for prelude\n' >> $SICPJSPATH
while read -r CURRENT_LINE
do
if [ "$CURRENT_LINE" != "undefined" -a "$CURRENT_LINE" != "NaN" -a "$CURRENT_LINE" != "Infinity" ]
then
echo "const $CURRENT_LINE = dict.get(\"$CURRENT_LINE\");" >> $SICPJSPATH
fi
done < "sicp_publish/names.txt"
echo $'\n// Prelude' >> $SICPJSPATH
cat sicp_publish/prelude.txt >> $SICPJSPATH
echo $'\n// Write prelude names\n' >> $SICPJSPATH
while read -r CURRENT_LINE
do
echo "exports.$CURRENT_LINE = $CURRENT_LINE;" >> $SICPJSPATH
done < "sicp_publish/prelude_names.txt"
echo $'\n// Write functions\n' >> $SICPJSPATH
while read -r CURRENT_LINE
do
if [ "$CURRENT_LINE" != "undefined" -a "$CURRENT_LINE" != "NaN" -a "$CURRENT_LINE" != "Infinity" ]
then
echo "exports.$CURRENT_LINE = dict.get(\"$CURRENT_LINE\");" >> $SICPJSPATH
fi
done < "sicp_publish/names.txt"
}
main