-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.cjs
executable file
·52 lines (47 loc) · 1.31 KB
/
build.cjs
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
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
if (fs.existsSync(path.join(__dirname, '.git'))) {
try {
console.log("Activating Husky's Git hooks...");
execSync(path.join(__dirname, 'node_modules', '.bin', 'husky'), ['install', '.husky'], {
stdio: 'inherit',
});
} catch (e) {
console.warn('Failed to activate Husky Git hooks:', e.message);
}
}
const build = async () => {
const esbuild = await import('esbuild');
try {
await esbuild.build({
entryPoints: ['cli/index.ts'],
bundle: true,
outdir: 'dist',
minify: true,
sourcemap: true,
platform: 'node',
target: ['node18'],
external: [],
loader: {
'.node': 'file', // TODO: This is a hack to prevent esbuild from trying to bundle .node files
},
});
} catch (error) {
console.error('Build failed:', error);
}
};
const watch = async () => {
if (process.argv.includes('--watch')) {
const chokidar = await import('chokidar');
console.log('Watching for changes...');
chokidar.watch('src/**/*.{ts,js}', { ignoreInitial: true }).on('all', (event, path) => {
console.log(`${event} detected at ${path}. Rebuilding...`);
build();
});
}
};
// Initial build
build();
watch();