-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.js
More file actions
61 lines (52 loc) · 1.58 KB
/
build.js
File metadata and controls
61 lines (52 loc) · 1.58 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
#!/usr/bin/env node
/**
* esbuild configuration for bundling the CLI into a single executable file
*/
const esbuild = require('esbuild');
const { chmod } = require('fs/promises');
const path = require('path');
const isDev = process.argv.includes('--dev');
async function build() {
try {
await esbuild.build({
entryPoints: ['index.ts'],
bundle: true,
platform: 'node',
target: 'node18',
format: 'cjs',
outfile: 'dist/ff1.js',
banner: {
js: '#!/usr/bin/env node',
},
minify: !isDev,
sourcemap: isDev ? 'inline' : false,
external: [],
logLevel: 'info',
// Remove shebangs from source files during bundling
loader: {
'.ts': 'ts',
},
});
// Make the output file executable
const { readFile, writeFile } = require('fs/promises');
const outfile = path.join(__dirname, 'dist', 'ff1.js');
// Remove any duplicate shebangs that may have been bundled from source
const content = await readFile(outfile, 'utf8');
const lines = content.split('\n');
const filteredLines = lines.filter((line, index) => {
// Keep the first shebang, remove any others
if (line.startsWith('#!')) {
return index === 0;
}
return true;
});
await writeFile(outfile, filteredLines.join('\n'));
await chmod(outfile, 0o755);
console.log('\nBuild complete. Single executable: dist/ff1.js');
console.log(' Run with: ./dist/ff1.js or node dist/ff1.js\n');
} catch (error) {
console.error('Build failed:', error);
process.exit(1);
}
}
build();