forked from SchematicHQ/schematic-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
68 lines (60 loc) · 1.8 KB
/
build.js
File metadata and controls
68 lines (60 loc) · 1.8 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
// build.js
const esbuild = require('esbuild');
const { execSync } = require('child_process');
const { cpSync, mkdirSync, existsSync } = require('fs');
const sharedConfig = {
entryPoints: ['src/index.ts'],
bundle: true,
platform: 'node',
target: 'node18.19',
minify: true,
sourcemap: 'external',
external: [
// Keep dependencies external since this is a library
'form-data',
'formdata-node',
'node-fetch',
'readable-stream',
// Optional peer dependencies - resolved from consumer's node_modules
'redis',
'ws',
// WASM rules engine — loaded dynamically at runtime in Node.js only
'./wasm/rulesengine.js',
],
tsconfig: './tsconfig.json',
};
async function build() {
try {
// Build CommonJS version with esbuild
await esbuild.build({
...sharedConfig,
outfile: 'dist/index.js',
format: 'cjs',
});
console.log('✅ JavaScript build completed with esbuild');
// Copy WASM artifacts to dist so they ship with the package
mkdirSync('dist/wasm', { recursive: true });
const wasmFiles = [
'rulesengine_bg.wasm',
'rulesengine.js',
'rulesengine.d.ts',
'rulesengine_bg.wasm.d.ts',
];
for (const file of wasmFiles) {
const src = `src/wasm/${file}`;
if (existsSync(src)) {
cpSync(src, `dist/wasm/${file}`);
}
}
console.log('✅ WASM artifacts copied to dist/wasm/');
// Generate TypeScript declarations with tsc
console.log('🔧 Generating TypeScript declarations...');
execSync('tsc --emitDeclarationOnly --outDir dist', { stdio: 'inherit' });
console.log('✅ TypeScript declarations generated');
console.log('🎉 Build completed successfully!');
} catch (error) {
console.error('❌ Build failed:', error);
process.exit(1);
}
}
build();