This repository has been archived by the owner on Jun 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
package_it.sh
executable file
·69 lines (53 loc) · 2.35 KB
/
package_it.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
#!/usr/bin/env bash
set -e
# change these :)
SCOPE="nomad-xyz"
PKG_NAME="configuration"
# Check if jq is installed
if ! [ -x "$(command -v jq)" ]; then
echo "jq is not installed" >& 2
echo "how do you live with yourself"
exit 1
fi
# Check if jq is installed
if ! [ -x "$(command -v wasm-pack)" ]; then
echo "wasm-pack is not installed" >& 2
exit 1
fi
# Cleanup any old generated code
rm -rf ./ts
mkdir -p ./ts
# build
wasm-pack build --target browser --scope $SCOPE --out-dir ts/web --out-name configuration
wasm-pack build --target nodejs --scope $SCOPE --out-dir ts/node --out-name configuration
# use the browser package.json as a base
mv ts/web/package.json ts/
mv ts/web/LICENSE* ts/
# Get the README in the root, delete the spare
mv ts/web/README* ts/
# clean redundant files
rm ts/node/README*
rm ts/node/LICENSE*
rm ts/node/package.json
# set the package.json main key (affects how nodejs loads this)
cat ts/package.json | jq --arg main "node/$PKG_NAME.js" '.main = $main'> TMP_FILE && mv TMP_FILE ts/package.json
# set the package.json browser key (affects how bundlers load this)
cat ts/package.json | jq --arg browser "web/$PKG_NAME.js" '.browser = $browser'> TMP_FILE && mv TMP_FILE ts/package.json
# set the package.json module key (affects how bundlers load this)
cat ts/package.json | jq --arg m "web/$PKG_NAME.js" '.module = $m' > TMP_FILE && mv TMP_FILE ts/package.json
# set the package.json name key (correct module name)
cat ts/package.json | jq --arg n "@$SCOPE/$PKG_NAME" '.name = $n' > TMP_FILE && mv TMP_FILE ts/package.json
# set the package.json types key
cat ts/package.json | jq --arg types "web/$PKG_NAME.d.ts" '.types = $types' > TMP_FILE && mv TMP_FILE ts/package.json
# empty the package.json files list
cat ts/package.json | jq '.files = []' > TMP_FILE && mv TMP_FILE ts/package.json
# add each web file to the package.json files list
for F in "web/$PKG_NAME""_bg.wasm" "web/$PKG_NAME""_bg.d.ts" "web/$PKG_NAME.js" "web/$PKG_NAME.d.ts" "web/$PKG_NAME""_bg.js"
do
cat ts/package.json | jq --arg f "$F" '.files += [$f]' > TMP_FILE && mv TMP_FILE ts/package.json
done
# add each node file to the package.json files list
for F in "node/$PKG_NAME""_bg.wasm" "node/$PKG_NAME""_bg.d.ts" "node/$PKG_NAME.js" "node/$PKG_NAME.d.ts"
do
cat ts/package.json | jq --arg f "$F" '.files += [$f]' > TMP_FILE && mv TMP_FILE ts/package.json
done