-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·56 lines (47 loc) · 1.48 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·56 lines (47 loc) · 1.48 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
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")"
GIT_HASH=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown")
# Bundle TypeScript → single JS file
npx esbuild src/app.ts \
--bundle \
--minify \
--target=es2022 \
--format=iife \
--define:"__GIT_HASH__=\"$GIT_HASH\"" \
--define:"__BUILD_HASH__=\"building...\"" \
--outfile=dist/app.js
# Inline JS into HTML using Python (avoids sed issues with special chars)
python3 -c "
import pathlib
html = pathlib.Path('src/index.html').read_text()
js = pathlib.Path('dist/app.js').read_text()
out = html.replace('<!-- APP_SCRIPT_PLACEHOLDER -->', f'<script>{js}</script>')
pathlib.Path('dist/signthat.html').write_text(out)
"
# Compute sha256
BUILD_HASH=$(sha256sum dist/signthat.html | cut -d' ' -f1)
SHORT_HASH="${BUILD_HASH:0:16}"
# Re-bundle with real build hash
npx esbuild src/app.ts \
--bundle \
--minify \
--target=es2022 \
--format=iife \
--define:"__GIT_HASH__=\"$GIT_HASH\"" \
--define:"__BUILD_HASH__=\"$SHORT_HASH\"" \
--outfile=dist/app.js
# Re-inline
python3 -c "
import pathlib
html = pathlib.Path('src/index.html').read_text()
js = pathlib.Path('dist/app.js').read_text()
out = html.replace('<!-- APP_SCRIPT_PLACEHOLDER -->', f'<script>{js}</script>')
pathlib.Path('dist/signthat.html').write_text(out)
"
FINAL_HASH=$(sha256sum dist/signthat.html | cut -d' ' -f1)
echo ""
echo "Built: dist/signthat.html"
echo "Git: $GIT_HASH"
echo "SHA256: $FINAL_HASH"
echo "Size: $(wc -c < dist/signthat.html) bytes"