@@ -2,14 +2,40 @@ const { execSync } = require('child_process');
22const fs = require ( 'fs' ) ;
33const path = require ( 'path' ) ;
44
5+ // Install Rust if not installed
6+ console . log ( 'Installing Rust toolchain...' ) ;
7+ try {
8+ execSync ( 'rustc --version' ) ;
9+ console . log ( 'Rust already installed' ) ;
10+ } catch {
11+ console . log ( 'Installing Rust...' ) ;
12+ execSync ( 'curl --proto "=https" --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y' , {
13+ stdio : 'inherit'
14+ } ) ;
15+ // Add cargo to PATH
16+ process . env . PATH = `${ process . env . HOME } /.cargo/bin:${ process . env . PATH } ` ;
17+ }
18+
19+ // Install wasm-pack if not installed
20+ console . log ( 'Installing wasm-pack...' ) ;
21+ try {
22+ execSync ( 'wasm-pack --version' ) ;
23+ console . log ( 'wasm-pack already installed' ) ;
24+ } catch {
25+ console . log ( 'Installing wasm-pack...' ) ;
26+ execSync ( 'curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh' , {
27+ stdio : 'inherit'
28+ } ) ;
29+ }
30+
531if ( ! fs . existsSync ( 'server/pkg' ) ) {
6- fs . mkdirSync ( 'server/pkg' ) ;
32+ fs . mkdirSync ( 'server/pkg' , { recursive : true } ) ;
733}
834
935console . log ( 'Building WebAssembly module...' ) ;
1036execSync ( 'wasm-pack build --target web --out-dir server/pkg --no-default-features --features worker' , {
1137 stdio : 'inherit' ,
12- cwd : path . resolve ( __dirname , '..' ) ,
38+ cwd : process . cwd ( ) ,
1339} ) ;
1440
1541console . log ( 'Generating TypeScript types...' ) ;
@@ -23,6 +49,6 @@ export interface AnalyzeOptions {
2349export function analyze_url(url: string, options: AnalyzeOptions): Promise<any>;
2450` ;
2551
26- fs . writeFileSync ( path . join ( __dirname , 'pkg' , 'bytes_radar.d.ts' ) , typesContent ) ;
52+ fs . writeFileSync ( path . join ( process . cwd ( ) , 'server/ pkg' , 'bytes_radar.d.ts' ) , typesContent ) ;
2753
28- console . log ( 'Build complete!' ) ;
54+ console . log ( 'Build complete!' ) ;
0 commit comments