-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.js
43 lines (39 loc) · 1.33 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
const fs = require('fs')
const {ncp} = require('ncp')
const Bundler = require('parcel-bundler')
const Path = require('path')
// parcel build --no-minify --public-url / --out-dir integration-test/build integration-test/index.html && cp -R manifest.json icons/ dist/
async function bundle(file, options = {}) {
options = Object.assign({
minify: false,
publicUrl: '/',
outDir: 'dist',
watch: false,
cache: false // Causes more trouble than it saves
}, options)
let bundler = new Bundler(Path.join(__dirname, file), options)
bundler.on('buildError', () => {process.exit(1)})
let bundled = await bundler.bundle()
if (!bundled) throw new Error('Bundling failure')
return bundled
}
async function build () {
await bundle('inpage.js', {
outDir: 'build'
})
let inPageScript = fs.readFileSync(Path.join(__dirname, 'build/inpage.js'), 'utf-8')
fs.writeFileSync(Path.join(__dirname, 'build/inpage.json'), JSON.stringify(inPageScript))
await bundle('content.js')
await bundle('options.html')
await bundle('integration-test/index.html', {
outDir: 'integration-test/build'
})
fs.copyFileSync('manifest.json', 'dist/manifest.json')
await new Promise((resolve, reject) => {
ncp('icons', 'dist/icons', {clobber: true}, (err, res) => {
if (err) reject(err)
else resolve(res)
})
})
}
build()