-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·92 lines (75 loc) · 1.96 KB
/
build.sh
File metadata and controls
executable file
·92 lines (75 loc) · 1.96 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
#!/bin/bash
set -eu
OS=$(uname -s)
BUILD="./.build"
DIST="./dist"
# The basename of the target executable
SEA="app"
TARGET="${DIST}/${OS}/${SEA}"
SEA_CONFIG="./sea-config.json"
BLOB="${BUILD}/sea-prep.blob"
# generate_bundler() uses webpack
WEBPACK_CONFIG="./webpack.config.js"
info() {
echo "INFO: " "$@"
}
error() {
echo "ERROR: " "$@"
exit 1
}
setup() {
info "Building ${OS} executable target"
mkdir -p "${BUILD}"
mkdir -p "${DIST}/${OS}"
generate_bundle
generate_blob
generate_executable
}
finish() {
info "Built executable: ${TARGET}"
}
generate_bundle() {
npx webpack --config "${WEBPACK_CONFIG}"
}
generate_blob() {
node --experimental-sea-config "${SEA_CONFIG}"
}
generate_executable() {
case "${OS}" in
Windows*) node -e "require('fs').copyFileSync(process.execPath, '${TARGET}')" ;;
*) cp $(command -v node) "${TARGET}" ;;
esac
}
build_sea_linux() {
setup
npx postject "${TARGET}" NODE_SEA_BLOB "${BLOB}" \
--sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2
finish
}
build_sea_darwin() {
setup
codesign --remove-signature "${TARGET}"
npx postject "${TARGET}" NODE_SEA_BLOB "${BLOB}" \
--sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2 \
--macho-segment-name NODE_SEA
codesign --sign - "${TARGET}"
finish
}
build_sea_windows() {
# I don't work with Windows, so this is just an initial stab based on the following
# link. Maybe it would work with WSL?
# https://nodejs.org/api/single-executable-applications.html#single-executable-applications
error "This error is to alert you that this script has not been tested for Windows and probably won't work as is"
TARGET="${TARGET}.exe"
setup
signtool remove /s "{TARGET}"
npx postject "${TARGET}" NODE_SEA_BLOB "${BLOB}" --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2
codesign --sign - "${TARGET}"
finish
}
case "${OS}" in
Linux*) build_sea_linux ;;
Darwin*) build_sea_darwin ;;
Windows*) build_sea_windows ;;
*) error "Unsupported OS:" "${OS}" ;;
esac