Skip to content

Commit ee059e4

Browse files
committed
code quality update.
1 parent 3b9ff01 commit ee059e4

File tree

2 files changed

+37
-20
lines changed

2 files changed

+37
-20
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
node_modules
22
npm-debug.log
3+
*.swf
4+
.idea/
5+
.eslintrc.json
6+

index.js

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,63 @@
11
var exec = require('child_process').exec;
22

33
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+
}
510
}
611

712
function WebpackShellPlugin(options) {
813
var defaultOptions = {
914
onBuildStart: [],
1015
onBuildEnd: [],
11-
dev: false
16+
dev: false,
17+
verbose: false
1218
};
1319
if (!options.onBuildStart) {
1420
options.onBuildStart = defaultOptions.onBuildStart;
1521
}
1622

17-
if(!options.onBuildEnd) {
23+
if (!options.onBuildEnd) {
1824
options.onBuildEnd = defaultOptions.onBuildEnd;
1925
}
2026

2127
this.options = options;
2228

2329
}
2430

25-
WebpackShellPlugin.prototype.apply = function(compiler) {
26-
const options = this.options;
31+
WebpackShellPlugin.prototype.apply = function (compiler) {
32+
var options = this.options;
2733

2834
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);
3437
}
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+
});
3748

3849
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+
}
4458
}
45-
}
46-
callback();
47-
});
59+
callback();
60+
});
4861
};
4962

5063
module.exports = WebpackShellPlugin;

0 commit comments

Comments
 (0)