forked from banga/git-split-diffs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.mjs
More file actions
76 lines (67 loc) · 1.82 KB
/
build.mjs
File metadata and controls
76 lines (67 loc) · 1.82 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
69
70
71
72
73
74
75
76
import * as esbuild from 'esbuild';
import fs from 'fs';
/** @type {esbuild.BuildOptions} */
const commonOptions = {
outdir: './build',
bundle: true,
platform: 'node',
target: 'node18',
format: 'esm',
external: [
'benchmark',
...Object.keys(
JSON.parse(fs.readFileSync('package.json', 'utf-8')).dependencies
),
],
banner: { js: '#!/usr/bin/env node' },
outExtension: { '.js': '.mjs' },
sourcemap: false,
logLevel: 'info',
};
/** @type {esbuild.BuildOptions} */
const devOptions = {
...commonOptions,
entryPoints: ['src/index.ts', 'src/benchmark.ts', 'src/previewTheme.ts'],
};
/** @type {esbuild.BuildOptions} */
const prodOptions = {
...commonOptions,
entryPoints: ['src/index.ts'],
minify: true,
};
async function main(args) {
let isProd = false;
let shouldWatch = false;
let shouldProfile = false;
for (const arg of args) {
switch (arg) {
case '--prod':
isProd = true;
break;
case '--watch':
shouldWatch = true;
break;
case '--profile':
shouldProfile = true;
break;
default:
throw new Error(`Unknown arg: ${arg}`);
}
}
/** @type {esbuild.BuildOptions} */
const buildOptions = {
...(isProd ? prodOptions : devOptions),
...(shouldProfile
? { banner: { js: '#!/usr/bin/env node --cpu-prof' } }
: {}),
};
console.log('Building with options:', buildOptions);
if (shouldWatch) {
const context = await esbuild.context(buildOptions);
await context.watch();
console.log('Watching...');
} else {
await esbuild.build(buildOptions);
}
}
main(process.argv.slice(2));