-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
executable file
·63 lines (54 loc) · 1.56 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* eslint-disable no-console */
const minimist = require('minimist');
const rollup = require('rollup');
const getRollupConfig = require('./getRollupConfig');
const watch = (config) => {
const watcher = rollup.watch(config);
const eventHandler = (event) => {
switch (event.code) {
case 'START':
console.log('Rollup watcher starting...');
break;
case 'BUNDLE_START':
break;
case 'BUNDLE_END':
break;
case 'END':
console.log(
`Rollup watcher finished bundling in ${event.duration}. Watching for changes...`,
);
break;
case 'ERROR':
console.error('Rollup watcher error', event);
break;
default:
console.error('Rollup watcher unknown event', event);
}
};
watcher.on('event', (event) => eventHandler(event));
};
const build = async (withWatch = false, project) => {
const dirname = process.cwd();
console.log(`Bundling ${dirname}`);
const { input, output } = getRollupConfig(dirname, project);
if (withWatch) {
watch({ ...input, output });
} else {
try {
const bundle = await rollup.rollup(input);
await Promise.all(
output.map(async (outputItem) => {
console.log(`Bundling ${outputItem.format} into ${outputItem.file}`);
return bundle.write(outputItem);
}),
);
} catch (err) {
console.error('ERROR BUNDLING: ', dirname);
console.error(err);
process.exit([1]);
throw err;
}
}
};
const argv = minimist(process.argv.slice(2));
build(argv.w, argv.p);