-
Notifications
You must be signed in to change notification settings - Fork 28
/
build.js
38 lines (33 loc) · 1.15 KB
/
build.js
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
import {build, watch} from "@marijn/buildtool"
import {fileURLToPath} from "url"
import {dirname, join} from "path"
import {readFileSync, writeFileSync, mkdirSync} from "fs"
import {rollup} from "rollup"
let tsOptions = {
lib: ["dom", "es2016"],
types: ["mocha", "node"],
target: "es6"
}
let base = dirname(fileURLToPath(import.meta.url)), src = join(base, "src"), dist = join(base, "dist")
let main = join(src, "index.ts"), mainConf = {tsOptions}
let test = join(src, "test.ts"), testConf = {tsOptions, bundleName: "test"}
let rollupFile = join(src, "rollup-plugin-lezer.js")
try { mkdirSync(dist) } catch {}
writeFileSync(join(dist, "rollup-plugin-lezer.js"), readFileSync(rollupFile, "utf8"))
rollup({
input: rollupFile,
external: () => true
}).then(bundle => bundle.generate({
format: "cjs",
file: join(dist, "rollup-plugin-lezer.cjs"),
paths: id => id.endsWith("/index.js") ? "./index.cjs" : id
})).then(result => {
writeFileSync(join(dist, "rollup-plugin-lezer.cjs"), result.output[0].code)
})
if (process.argv.includes("--watch")) {
watch([main], [], mainConf)
watch([test], [], testConf)
} else {
build(main, mainConf)
build(test, testConf)
}