Skip to content

Commit c540a6f

Browse files
committed
finalize build.
1 parent 9210d6d commit c540a6f

File tree

3 files changed

+50
-139
lines changed

3 files changed

+50
-139
lines changed

index-es6.js

Lines changed: 0 additions & 86 deletions
This file was deleted.

index.js

Lines changed: 50 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
var exec = require('child_process').exec;
1+
const exec = require('child_process').exec;
2+
3+
const defaultOptions = {
4+
onBuildStart: [],
5+
onBuildEnd: [],
6+
onBuildExit: [],
7+
dev: true,
8+
verbose: false
9+
};
210

311
function puts(error, stdout, stderr) {
412
if (error) {
@@ -21,66 +29,56 @@ function validateInput(options) {
2129
}
2230

2331
function mergeOptions(options, defaults) {
24-
for (key in defaults) {
32+
for (var key in defaults) {
2533
if (options.hasOwnProperty(key)) {
26-
defaults[key] = options[key];
34+
defaults[key] = options[key];
2735
}
2836
}
29-
3037
return defaults;
3138
}
3239

33-
function WebpackShellPlugin(options) {
34-
var defaults = {
35-
onBuildStart: [],
36-
onBuildEnd: [],
37-
onBuildExit: [],
38-
dev: true,
39-
verbose: false
40-
};
41-
42-
this.options = validateInput(mergeOptions(options, defaults));
43-
}
40+
export default class WebpackShellPlugin {
41+
constructor(options) {
42+
this.options = validateInput(mergeOptions(options, defaultOptions));
43+
}
4444

45-
WebpackShellPlugin.prototype.apply = function (compiler) {
46-
var options = this.options;
45+
apply(compiler) {
4746

48-
compiler.plugin('compilation', function (compilation) {
49-
if (options.verbose) {
50-
console.log('Report compilation:', compilation);
51-
}
52-
if (options.onBuildStart.length) {
53-
console.log('Executing pre-build scripts');
54-
options.onBuildStart.forEach(function (script) {
55-
exec(script, puts);
56-
});
57-
if (options.dev) {
58-
options.onBuildStart = [];
47+
compiler.plugin('compilation', (compilation) => {
48+
if (this.options.verbose) {
49+
console.log(`Report compilation: ${compilation}`);
5950
}
60-
}
61-
});
62-
63-
compiler.plugin('emit', function (compilation, callback) {
64-
if (options.onBuildEnd.length) {
65-
console.log('Executing post-build scripts');
66-
options.onBuildEnd.forEach(function (script) {
67-
exec(script, puts);
68-
});
69-
if (options.dev) {
70-
options.onBuildEnd = [];
51+
if (this.options.onBuildStart.length) {
52+
console.log('Executing pre-build scripts');
53+
this.options.onBuildStart.forEach(script => {
54+
exec(script, puts);
55+
});
56+
if (this.options.dev) {
57+
this.options.onBuildStart = [];
58+
}
7159
}
72-
}
73-
callback();
74-
});
60+
});
7561

76-
compiler.plugin("done", function () {
77-
if (options.onBuildExit.length) {
78-
console.log("Executing addiotn scripts befor exit");
79-
options.onBuildExit.forEach(function (script) {
80-
exec(script, puts);
81-
});
82-
}
83-
});
84-
};
62+
compiler.plugin('emit', (compilation, callback) => {
63+
if (this.options.onBuildEnd.length) {
64+
console.log('Executing post-build scripts');
65+
this.options.onBuildEnd.forEach(script => {
66+
exec(script, puts);
67+
});
68+
if (this.options.dev) {
69+
this.options.onBuildEnd = [];
70+
}
71+
}
72+
callback();
73+
});
8574

86-
module.exports = WebpackShellPlugin;
75+
compiler.plugin('done', () => {
76+
if (this.options.onBuildExit.length) {
77+
console.log('Executing addiotn scripts befor exit');
78+
this.options.onBuildExit.forEach(script => {
79+
exec(script, puts);
80+
});
81+
}
82+
});
83+
}
84+
}

lib/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ var WebpackShellPlugin = function () {
7272
babelHelpers.classCallCheck(this, WebpackShellPlugin);
7373

7474
this.options = validateInput(mergeOptions(options, defaultOptions));
75-
console.log(this.options);
7675
}
7776

7877
babelHelpers.createClass(WebpackShellPlugin, [{

0 commit comments

Comments
 (0)