1 | const updateNotifier = require('update-notifier');
|
2 | const weblog = require('webpack-log');
|
3 |
|
4 | const pkg = require('../package.json');
|
5 |
|
6 | const Command = require('./commands/Command');
|
7 | const compiler = require('./compiler');
|
8 | const { load } = require('./config');
|
9 | const parseEntries = require('./entry');
|
10 | const { apply } = require('./flags');
|
11 |
|
12 | module.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 |
|
37 | for (const sig of ['SIGINT', 'SIGTERM']) {
|
38 | process.on(sig, () => {
|
39 |
|
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 |
|
48 | module.exports.Command = Command;
|