forked from okta/okta-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
48 lines (36 loc) · 1.35 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
48
'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`;
shell.echo(`Start building...`);
shell.rm(`-Rf`, `${NPM_DIR}/*`);
// Bundle with rollup
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`, [`package.json`, `LICENSE`, `*.md`], `${NPM_DIR}`);
shell.echo(`Modifying final package.json`);
let packageJSON = JSON.parse(fs.readFileSync(`./${NPM_DIR}/package.json`));
delete packageJSON.private; // remove private flag
delete packageJSON.scripts; // remove all scripts
delete packageJSON.jest; // remove jest section
delete packageJSON['jest-junit']; // remove jest-junit section
delete packageJSON.workspaces; // remove yarn workspace section
// Remove "build/" from the entrypoint paths.
['main', 'module', 'types'].forEach(function(key) {
if (packageJSON[key]) {
packageJSON[key] = packageJSON[key].replace(`${NPM_DIR}/`, '');
}
});
fs.writeFileSync(`./${NPM_DIR}/package.json`, JSON.stringify(packageJSON, null, 4));
shell.echo(chalk.green(`End building`));