-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.js
47 lines (33 loc) · 1.12 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
39
40
41
42
43
44
45
46
47
const fs = require('fs')
require('@babel/register')
const rollup = require('rollup')
const configs = require('./rollup/rollup.config').default
const ASSETS_DIR = 'src/assets'
const VARIANTS = ['chrome', 'edge', 'firefox', 'opera']
const argv = require('minimist')(process.argv.slice(2))
const manifest = JSON.parse(fs.readFileSync('src/manifest.json', 'utf8'))
async function build() {
for (const variant of VARIANTS) {
const options = {
...argv,
variant,
}
for (const config of configs(options)) {
const { output: outputs, ...input } = config
const bundle = await rollup.rollup(input)
for (const output of outputs) {
await bundle.write(output)
}
}
for (const file of fs.readdirSync(ASSETS_DIR)) {
fs.copyFileSync(`${ASSETS_DIR}/${file}`, `build/${variant}/${file}`)
}
const variantManifestPath = `src/manifest.${variant}.json`
const variantManifest = {
...manifest,
...(fs.existsSync(variantManifestPath) ? JSON.parse(fs.readFileSync(variantManifestPath, 'utf8')) : {}),
}
fs.writeFileSync(`build/${variant}/manifest.json`, JSON.stringify(variantManifest, null, 4))
}
}
build()