-
Notifications
You must be signed in to change notification settings - Fork 25
/
build.js
47 lines (35 loc) · 1.23 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
'use strict'
const shell = require('shelljs')
const chalk = require('chalk')
const fs = require('fs')
const NPM_DIR = `dist`
const BUNDLE_CMD = `yarn bundle`
const BANNER_CMD = `yarn banners`
const BUNDLES_DIR = `${NPM_DIR}/bundles`
shell.echo(`Start building...`)
shell.rm(`-Rf`, `${NPM_DIR}/*`)
shell.mkdir(`-p`, `./${BUNDLES_DIR}`)
// Bundle using webpack
if (shell.exec(BUNDLE_CMD).code !== 0) {
shell.echo(chalk.red(`Error: Rollup failed`))
shell.exit(1)
}
// Maintain banners
if (shell.exec(BANNER_CMD).code !== 0) {
shell.echo(chalk.red(`Error: Maintain banners failed`))
shell.exit(1)
}
shell.echo(chalk.green(`Bundling completed`))
shell.cp(`-Rf`, [`src`, `package.json`, `LICENSE`, `THIRD-PARTY-NOTICES`, `*.md`], `${NPM_DIR}`)
shell.echo(`Modifying final package.json`)
const packageJSON = JSON.parse(fs.readFileSync(`./${NPM_DIR}/package.json`))
packageJSON.private = false
packageJSON.scripts.prepare = '';
// Remove "dist/" from the entrypoint paths.
['main', 'module', 'types'].forEach(function (key) {
if (packageJSON[key]) {
packageJSON[key] = packageJSON[key].replace('dist/', '')
}
})
fs.writeFileSync(`./${NPM_DIR}/package.json`, JSON.stringify(packageJSON, null, 4))
shell.echo(chalk.green(`End building`))