UNPKG

1.1 kBJavaScriptView Raw
1const updateNotifier = require('update-notifier');
2const weblog = require('webpack-log');
3
4const pkg = require('../package.json');
5
6const Command = require('./commands/Command');
7const compiler = require('./compiler');
8const { load } = require('./config');
9const parseEntries = require('./entry');
10const { apply } = require('./flags');
11
12module.exports = (cli) => {
13 updateNotifier({ pkg }).notify();
14
15 process.env.WEBPACK_COMMAND = true;
16
17 const { argv } = cli;
18 const log = weblog({
19 name: 'webpack',
20 id: 'webpack-command',
21 level: argv.logLevel || 'info',
22 timestamp: argv.logTime,
23 });
24
25 const options = apply(argv, {});
26 const entry = parseEntries(cli);
27
28 if (entry) {
29 options.entry = entry;
30 }
31
32 if (!options) {
33 process.exit(1);
34 }
35
36 /* istanbul ignore next */
37 for (const sig of ['SIGINT', 'SIGTERM']) {
38 process.on(sig, () => {
39 // eslint-disable-line no-loop-func
40 log.info(`Process Ended via ${sig}`);
41 process.exit(0);
42 });
43 }
44
45 return load(argv, options).then((target) => compiler(target).run());
46};
47
48module.exports.Command = Command;