1 | #! /usr/bin/env node
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | var run = require('../index').run,
|
7 | path = require('path'),
|
8 | chalk = require('chalk'),
|
9 | argv = require('minimist')(process.argv.slice(2), {
|
10 | '--': true,
|
11 | default: {
|
12 | watch: false,
|
13 | 'max-retries': Infinity,
|
14 | config: 'webpack.config.js',
|
15 | 'parallel': require('os').cpus().length,
|
16 | json: false,
|
17 | colors: require('supports-color'),
|
18 | bail: true,
|
19 | stats: true
|
20 | },
|
21 | alias: {
|
22 | 'm': 'max-retries',
|
23 | 'p': 'parallel',
|
24 | 'v': 'version'
|
25 | }
|
26 | }),
|
27 | configPath;
|
28 |
|
29 | if(argv.version) {
|
30 | process.stdout.write('parallel-webpack ' + chalk.blue(require('../package').version) + "\n");
|
31 | } else {
|
32 | try {
|
33 | chalk.enabled = argv.colors;
|
34 | configPath = path.resolve(argv.config);
|
35 | run(configPath, {
|
36 | watch: argv.watch,
|
37 | maxRetries: Number.parseInt(argv['max-retries'], 10),
|
38 | maxConcurrentWorkers: Number.parseInt(argv['parallel'], 10),
|
39 | bail: argv.bail,
|
40 | json: argv.json,
|
41 | modulesSort: argv['sort-modules-by'],
|
42 | chunksSort: argv['sort-chunks-by'],
|
43 | assetsSort: argv['sort-assets-by'],
|
44 | exclude: argv['display-exclude'],
|
45 | colors: argv['colors'],
|
46 | stats: argv['stats'],
|
47 | argv: argv['--']
|
48 | }).then(function(stats) {
|
49 | if(argv.json && stats) {
|
50 | process.stdout.write(JSON.stringify(stats.map(function(stat) {
|
51 | return JSON.parse(stat);
|
52 | }), null, 2) + "\n");
|
53 | }
|
54 | }).catch(function(err) {
|
55 | if(err.message) {
|
56 | process.stdout.write(err.message + "\n");
|
57 | if(err.error) {
|
58 | console.error(err.error);
|
59 | }
|
60 | } else {
|
61 | console.error(err);
|
62 | }
|
63 | process.exit(1);
|
64 | });
|
65 | } catch (e) {
|
66 | if(e.message) {
|
67 | process.stdout.write(e.message + "\n");
|
68 | console.error(e.error);
|
69 | } else {
|
70 | process.stdout.write(chalk.red('[WEBPACK]') + ' Could not load configuration ' + chalk.underline(process.cwd() + '/' + argv.config) + "\n");
|
71 | }
|
72 | process.exit(1);
|
73 | }
|
74 | }
|