1
- const WASM_BUILDER_CONTAINER =
2
- "ghcr.io/nodejs/wasm-builder@sha256:975f391d907e42a75b8c72eb77c782181e941608687d4d8694c3e9df415a0970" ; // v0.0.9
3
-
4
1
const { execSync, execFileSync } = require ( "node:child_process" ) ;
5
2
const { resolve } = require ( "node:path" ) ;
6
3
4
+ const WASM_BUILDER_CONTAINER =
5
+ "ghcr.io/nodejs/wasm-builder@sha256:975f391d907e42a75b8c72eb77c782181e941608687d4d8694c3e9df415a0970" ; // v0.0.9
6
+
7
7
const ROOT = resolve ( __dirname , "../" ) ;
8
8
9
- let platform = process . env . WASM_PLATFORM ;
10
- if ( ! platform && process . argv [ 2 ] ) {
11
- platform = execFileSync ( "docker" , [
12
- "info" ,
13
- "-f" ,
14
- "{{.OSType}}/{{.Architecture}}" ,
15
- ] )
16
- . toString ( )
17
- . trim ( ) ;
9
+ function getPlatformFromDocker ( ) {
10
+ try {
11
+ return execFileSync ( "docker" , [
12
+ "info" ,
13
+ "-f" ,
14
+ "{{.OSType}}/{{.Architecture}}" ,
15
+ ] )
16
+ . toString ( )
17
+ . trim ( ) ;
18
+ } catch ( error ) {
19
+ console . error (
20
+ "Error retrieving platform information from Docker:" ,
21
+ error . message ,
22
+ ) ;
23
+ }
18
24
}
19
25
20
- if ( process . argv [ 2 ] === "--docker" ) {
26
+ function runDockerContainer ( ) {
21
27
const args = [ ] ;
22
28
args . push ( "run" ) ;
23
29
args . push ( "--rm" ) ;
@@ -43,14 +49,34 @@ if (process.argv[2] === "--docker") {
43
49
args . push ( "./tools/build-wasm.js" ) ;
44
50
console . log ( `> docker ${ args } \n\n` ) ;
45
51
execFileSync ( "docker" , args , { stdio : "inherit" } ) ;
52
+ }
53
+
54
+ let platform = process . env . WASM_PLATFORM ;
55
+ if ( ! platform && process . argv [ 2 ] ) {
56
+ platform = getPlatformFromDocker ( ) ;
57
+ }
58
+
59
+ // If "--docker" is passed, run the Docker container with the specified mounts
60
+ if ( process . argv [ 2 ] === "--docker" ) {
61
+ runDockerContainer ( ) ;
46
62
process . exit ( 0 ) ;
47
63
}
48
64
49
- execSync (
50
- `cd bindings/binding_typescript_wasm && \
51
- cargo install --locked wasm-pack && \
52
- PATH=/home/node/.cargo/bin:$PATH && \
53
- ./scripts/build.sh && \
54
- cp -r pkg/* ../../lib` ,
55
- { stdio : "inherit" } ,
56
- ) ;
65
+ const wasmBindingPath = `${ ROOT } /bindings/binding_typescript_wasm` ;
66
+
67
+ const commands = [
68
+ `cd ${ wasmBindingPath } ` ,
69
+ "cargo install --locked wasm-pack" ,
70
+ "export PATH=/home/node/.cargo/bin:$PATH" ,
71
+ `sh ${ wasmBindingPath } /scripts/build.sh` ,
72
+ `cp -r ${ wasmBindingPath } /pkg/* ${ ROOT } /lib` ,
73
+ ] ;
74
+
75
+ try {
76
+ for ( const command of commands ) {
77
+ execSync ( command , { stdio : "inherit" } ) ;
78
+ }
79
+ } catch ( error ) {
80
+ console . error ( "Error executing build command:" , error . message ) ;
81
+ process . exit ( 1 ) ;
82
+ }
0 commit comments