|
1 | 1 | var exec = require('child_process').exec; |
2 | 2 |
|
3 | 3 | function puts(error, stdout, stderr) { |
4 | | - console.log(stdout); |
| 4 | + if (error) { |
| 5 | + console.log('Error: ', error, stderr); |
| 6 | + } |
| 7 | + if (this.options.verbose) { |
| 8 | + console.log(stdout); |
| 9 | + } |
5 | 10 | } |
6 | 11 |
|
7 | 12 | function WebpackShellPlugin(options) { |
8 | 13 | var defaultOptions = { |
9 | 14 | onBuildStart: [], |
10 | 15 | onBuildEnd: [], |
11 | | - dev: false |
| 16 | + dev: false, |
| 17 | + verbose: false |
12 | 18 | }; |
13 | 19 | if (!options.onBuildStart) { |
14 | 20 | options.onBuildStart = defaultOptions.onBuildStart; |
15 | 21 | } |
16 | 22 |
|
17 | | - if(!options.onBuildEnd) { |
| 23 | + if (!options.onBuildEnd) { |
18 | 24 | options.onBuildEnd = defaultOptions.onBuildEnd; |
19 | 25 | } |
20 | 26 |
|
21 | 27 | this.options = options; |
22 | 28 |
|
23 | 29 | } |
24 | 30 |
|
25 | | -WebpackShellPlugin.prototype.apply = function(compiler) { |
26 | | - const options = this.options; |
| 31 | +WebpackShellPlugin.prototype.apply = function (compiler) { |
| 32 | + var options = this.options; |
27 | 33 |
|
28 | 34 | compiler.plugin("compilation", function (compilation) { |
29 | | - if(options.onBuildStart.length){ |
30 | | - console.log("Executing pre-build scripts"); |
31 | | - options.onBuildStart.forEach(function (script) { exec(script, puts)}); |
32 | | - if (options.dev) { |
33 | | - options.onBuildStart = []; |
| 35 | + if (options.verbose) { |
| 36 | + console.log('Report compilation:', compilation); |
34 | 37 | } |
35 | | - } |
36 | | -}); |
| 38 | + if (options.onBuildStart.length) { |
| 39 | + console.log("Executing pre-build scripts"); |
| 40 | + options.onBuildStart.forEach(function (script) { |
| 41 | + exec(script, puts) |
| 42 | + }); |
| 43 | + if (options.dev) { |
| 44 | + options.onBuildStart = []; |
| 45 | + } |
| 46 | + } |
| 47 | + }); |
37 | 48 |
|
38 | 49 | compiler.plugin("emit", function (compilation, callback) { |
39 | | - if(options.onBuildEnd.length){ |
40 | | - console.log("Executing post-build scripts"); |
41 | | - options.onBuildEnd.forEach(function(script){ exec(script, puts)}); |
42 | | - if (options.dev) { |
43 | | - options.onBuildEnd = []; |
| 50 | + if (options.onBuildEnd.length) { |
| 51 | + console.log("Executing post-build scripts"); |
| 52 | + options.onBuildEnd.forEach(function (script) { |
| 53 | + exec(script, puts) |
| 54 | + }); |
| 55 | + if (options.dev) { |
| 56 | + options.onBuildEnd = []; |
| 57 | + } |
44 | 58 | } |
45 | | - } |
46 | | - callback(); |
47 | | -}); |
| 59 | + callback(); |
| 60 | + }); |
48 | 61 | }; |
49 | 62 |
|
50 | 63 | module.exports = WebpackShellPlugin; |
|
0 commit comments