Repository navigation
Expand file tree
/
Copy pathbuild.ts
More file actions
39 lines (35 loc) · 1.43 KB
/
Copy pathbuild.ts
File metadata and controls
39 lines (35 loc) · 1.43 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
// Build entry point. `node scripts/build.ts [app|desktop|package] [--debug] [--dir] [--arch <arch>]`
import { buildUserscript } from './build/userscript.ts';
import { buildApp } from './build/app.ts';
import { buildDesktop } from './build/desktop.ts';
import { packageDesktop } from './build/package.ts';
import { buildExtension } from './build/extension.ts';
const args = process.argv.slice(2);
const debug = args.includes('--debug');
const dir = args.includes('--dir');
const archIndex = args.indexOf('--arch');
const arch = archIndex < 0 ? undefined : args[archIndex + 1];
if (archIndex >= 0 && (!arch || arch.startsWith('--'))) {
console.error('--arch needs a value');
process.exit(1);
}
// Without the -1 guard, archIndex + 1 is 0 and eats the first positional arg.
const archValueIndex = archIndex < 0 ? -1 : archIndex + 1;
const targets = args.filter((arg, index) => !arg.startsWith('--') && index !== archValueIndex);
const all = {
app: buildApp,
userscript: buildUserscript,
desktop: buildDesktop,
package: packageDesktop,
firefox: buildExtension,
chromium: (options: { debug: boolean }) => buildExtension({ ...options, browser: 'chromium' }),
};
const chosen = targets.length ? targets : ['desktop'];
for (const target of chosen) {
const fn = all[target as keyof typeof all];
if (!fn) {
console.error(`unknown target: ${target} (try: ${Object.keys(all).join(', ')})`);
process.exit(1);
}
await fn({ debug, arch, dir });
}