11#! /usr/bin/env bash
2-
3- # - If bindings are missing, try `npm run check:bindings` (downloads CI artifacts).
4- # - If that fails, fall back to `npm run build:bindings-node` (local build).
5- # - Subsequent steps (copy/clean/builds) are critical: failures stop the script with a clear message.
6-
72set -Eeuo pipefail
83
9- # ---------- paths ----------
10- ROOT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) /../../.." && pwd) "
11- BINDINGS_CHECK_PATH=" ${BINDINGS_CHECK_PATH:- $ROOT_DIR / src/ bindings/ compiled} " # presence gate
12-
13- # ---------- shared libraries ----------
4+ # shared libraries
145source ./scripts/lib/ux.sh
6+
7+ # paths
8+ ROOT_DIR=" $( get_repo_root) "
9+ BINDINGS_CHECK_PATH=" ${BINDINGS_CHECK_PATH:- $ROOT_DIR / src/ bindings/ compiled} "
10+
11+ # setup
1512setup_script " ${BASH_SOURCE[0]} " " Build"
1613
17- # ---------- steps ----------
18- ensure_bindings () {
19- bold " [1/5] Ensuring compiled bindings"
14+ # steps
15+ bold " Starting build"
2016
21- if [[ -d " $BINDINGS_CHECK_PATH " ]]; then
22- ok " Found compiled bindings at: $BINDINGS_CHECK_PATH "
23- return 0
24- fi
17+ bold " [1/4] Ensuring compiled bindings"
2518
19+ if [[ -d " $BINDINGS_CHECK_PATH " ]]; then
20+ ok " Found compiled bindings at: $BINDINGS_CHECK_PATH "
21+ else
2622 warn " Compiled bindings not found at: $BINDINGS_CHECK_PATH "
2723 warn " Trying npm run check:bindings (downloads prebuilt artifacts)..."
2824
@@ -31,49 +27,36 @@ ensure_bindings() {
3127
3228 if [[ -d " $BINDINGS_CHECK_PATH " ]]; then
3329 ok " Bindings downloaded successfully at: $BINDINGS_CHECK_PATH "
34- return 0
35- fi
36-
37- warn " check:bindings did not produce bindings. Falling back to local build via npm run build:bindings-node (fatal)..."
38-
39- # FATAL fallback: if this fails, the ERR trap will abort the build
40- ( cd " $ROOT_DIR " && npm run build:bindings-node )
41-
42- # Extra safety: ensure the directory actually exists after a 'successful' run
43- if [[ -d " $BINDINGS_CHECK_PATH " ]]; then
44- ok " Bindings built locally at: $BINDINGS_CHECK_PATH "
4530 else
46- error " Local bindings build completed but ${BINDINGS_CHECK_PATH} is still missing."
47- exit 1
31+ warn " check:bindings did not produce bindings. Falling back to local build via npm run build:bindings-node (fatal)..."
32+
33+ # FATAL fallback: if this fails, the ERR trap will abort the build
34+ ( cd " $ROOT_DIR " && npm run build:bindings-node )
35+
36+ # Extra safety: ensure the directory actually exists after a 'successful' run
37+ if [[ -d " $BINDINGS_CHECK_PATH " ]]; then
38+ ok " Bindings built locally at: $BINDINGS_CHECK_PATH "
39+ else
40+ error " Local bindings build completed but ${BINDINGS_CHECK_PATH} is still missing."
41+ exit 1
42+ fi
4843 fi
49- }
44+ fi
5045
51- clean_dist_node () {
52- bold " [3/5] Cleaning dist/node"
53- if command -v npx > /dev/null 2>&1 ; then
54- npx rimraf " $ROOT_DIR /dist/node"
55- else
56- rm -rf " $ROOT_DIR /dist/node"
57- fi
58- ok " dist/node cleaned."
59- }
46+ bold " [2/4] Cleaning dist/node"
47+ if command -v npx > /dev/null 2>&1 ; then
48+ npx rimraf " $ROOT_DIR /dist/node"
49+ else
50+ rm -rf " $ROOT_DIR /dist/node"
51+ fi
52+ ok " dist/node cleaned."
6053
61- build_dev () {
62- bold " [4/5] Running npm run build:dev"
63- (cd " $ROOT_DIR " && npm run build:dev)
64- ok " build:dev completed."
65- }
54+ bold " [3/4] Running npm run build:dev"
55+ (cd " $ROOT_DIR " && npm run build:dev)
56+ ok " build:dev completed."
6657
67- build_node () {
68- bold " [5/5] Building Node bundle"
69- node " $ROOT_DIR /src/build/build-node.js"
70- ok " Node build completed."
71- }
58+ bold " [4/4] Building Node bundle"
59+ node " $ROOT_DIR /src/build/build-node.js"
60+ ok " Node build completed."
7261
73- # ---------- main ----------
74- bold " Starting build"
75- ensure_bindings # use check:bindings first(non-fatal on error), then fallback to build:bindings-node(fatal on error)
76- clean_dist_node # fatal on error
77- build_dev # fatal on error
78- build_node # fatal on error
7962success " Build finished successfully."
0 commit comments