-
Notifications
You must be signed in to change notification settings - Fork 2
/
build
executable file
·62 lines (50 loc) · 1.62 KB
/
build
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
#! /usr/bin/env node
"use strict";
const { ArgumentParser } = require('argparse')
, { build, serve } = require('esbuild')
, docsPlugin = require('./docs-plugin')
const parser = new ArgumentParser({
description: 'DrEdGE build script',
})
parser.add_argument('-o', '--output-file', { help: 'File to output', required: true })
parser.add_argument('input_file', { help: 'Entry point' })
parser.add_argument('--production', { help: 'Build for production', action: 'store_true' })
parser.add_argument('--compress', { help: 'Compress output', action: 'store_true' })
parser.add_argument('--serve', { help: 'Serve bundle from directory and rebuild when requested' })
const args = parser.parse_args()
const opts = {
entryPoints: [args.input_file],
bundle: true,
outfile: args.output_file,
define: {
'process.env.NODE_ENV': args.production ? '"production"' : '""',
},
plugins: [docsPlugin],
}
if (args.production) {
opts.minify = true
}
if (args.serve) {
opts.sourcemap = 'inline'
serve({
servedir: args.serve,
port: 9999,
onRequest({ method, path, status, timeInMS }) {
const date = new Date()
, message = `${date.toLocaleString()} | ${status} | ${method} ${path} (${timeInMS}ms)`
// eslint-disable-next-line no-console
console.log(message)
},
}, opts).then(({ host, port, stop }) => {
// eslint-disable-next-line no-console
console.log(`Serving on http://${host}:${port}/`)
process.on('SIGINT', () => {
// eslint-disable-next-line no-console
console.log('\nStopping server.')
stop()
process.exit();
})
})
} else {
build(opts)
}