-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.mjs
54 lines (43 loc) · 1.41 KB
/
build.mjs
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
/// <reference types="@types/node" />
import { fork } from 'child_process'
import { context } from 'esbuild'
import path from 'path'
import { fileURLToPath } from 'url'
// No __dirname in ESM scope, make it ourselves.
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
// Script arguments.
const args = process.argv.slice(2)
// REALLY REALLY basic argument parsing.
const watchBuild = args.at(0) === '--watch'
let buildNotify = {
name: 'notify_the_boys',
setup (build) {
build.onEnd(async (result) => {
console.log(`build complete, ${result.errors.length} errors`)
const chld = fork(path.join(__dirname, 'dist', 'frawgs.mjs'))
await new Promise((resolve) => {
chld.on('close', resolve)
})
if (watchBuild === false) {
process.exit(0)
}
})
},
}
async function watch () {
let ctx = await context({
bundle: true,
packages: 'external', // XXX: Need this else +500 packages for satanic Node.js polyfills.
format: 'esm',
target: 'esnext',
platform: 'node',
entryPoints: [path.join(__dirname, 'src', 'frawgs.ts')],
outdir: path.join(__dirname, 'dist'),
outExtension: { '.js': '.mjs' },
plugins: [buildNotify],
})
await ctx.watch()
console.log('Watching for changes...')
}
watch()