Skip to content

Commit 9115179

Browse files
committed
Add “quiet” option
1 parent a65ae75 commit 9115179

File tree

4 files changed

+118
-149
lines changed

4 files changed

+118
-149
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ Once the build finishes, a child process is spawned firing both a python and nod
7979
* `dev`: switch for development environments. This causes scripts to execute once. Useful for running HMR on webpack-dev-server or webpack watch mode. **Default: true**
8080
* `safe`: switches script execution process from spawn to exec. If running into problems with spawn, turn this setting on. **Default: false**
8181
* `verbose`: **DEPRECATED** enable for verbose output. **Default: false**
82+
* `quiet`: disables output for internal messages. **Default: false**
8283

8384
### Developing
8485

lib/index.js

+72-131
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,5 @@
11
'use strict';
22

3-
var asyncGenerator = function () {
4-
function AwaitValue(value) {
5-
this.value = value;
6-
}
7-
8-
function AsyncGenerator(gen) {
9-
var front, back;
10-
11-
function send(key, arg) {
12-
return new Promise(function (resolve, reject) {
13-
var request = {
14-
key: key,
15-
arg: arg,
16-
resolve: resolve,
17-
reject: reject,
18-
next: null
19-
};
20-
21-
if (back) {
22-
back = back.next = request;
23-
} else {
24-
front = back = request;
25-
resume(key, arg);
26-
}
27-
});
28-
}
29-
30-
function resume(key, arg) {
31-
try {
32-
var result = gen[key](arg);
33-
var value = result.value;
34-
35-
if (value instanceof AwaitValue) {
36-
Promise.resolve(value.value).then(function (arg) {
37-
resume("next", arg);
38-
}, function (arg) {
39-
resume("throw", arg);
40-
});
41-
} else {
42-
settle(result.done ? "return" : "normal", result.value);
43-
}
44-
} catch (err) {
45-
settle("throw", err);
46-
}
47-
}
48-
49-
function settle(type, value) {
50-
switch (type) {
51-
case "return":
52-
front.resolve({
53-
value: value,
54-
done: true
55-
});
56-
break;
57-
58-
case "throw":
59-
front.reject(value);
60-
break;
61-
62-
default:
63-
front.resolve({
64-
value: value,
65-
done: false
66-
});
67-
break;
68-
}
69-
70-
front = front.next;
71-
72-
if (front) {
73-
resume(front.key, front.arg);
74-
} else {
75-
back = null;
76-
}
77-
}
78-
79-
this._invoke = send;
80-
81-
if (typeof gen.return !== "function") {
82-
this.return = undefined;
83-
}
84-
}
85-
86-
if (typeof Symbol === "function" && Symbol.asyncIterator) {
87-
AsyncGenerator.prototype[Symbol.asyncIterator] = function () {
88-
return this;
89-
};
90-
}
91-
92-
AsyncGenerator.prototype.next = function (arg) {
93-
return this._invoke("next", arg);
94-
};
95-
96-
AsyncGenerator.prototype.throw = function (arg) {
97-
return this._invoke("throw", arg);
98-
};
99-
100-
AsyncGenerator.prototype.return = function (arg) {
101-
return this._invoke("return", arg);
102-
};
103-
104-
return {
105-
wrap: function (fn) {
106-
return function () {
107-
return new AsyncGenerator(fn.apply(this, arguments));
108-
};
109-
},
110-
await: function (value) {
111-
return new AwaitValue(value);
112-
}
113-
};
114-
}();
115-
1163
var classCallCheck = function (instance, Constructor) {
1174
if (!(instance instanceof Constructor)) {
1185
throw new TypeError("Cannot call a class as a function");
@@ -137,6 +24,44 @@ var createClass = function () {
13724
};
13825
}();
13926

27+
28+
29+
30+
31+
32+
33+
34+
35+
36+
37+
38+
39+
40+
41+
42+
43+
44+
45+
46+
47+
48+
49+
50+
51+
52+
53+
54+
55+
56+
57+
58+
59+
60+
61+
62+
63+
64+
14065
var toArray = function (arr) {
14166
return Array.isArray(arr) ? arr : Array.from(arr);
14267
};
@@ -151,7 +76,8 @@ var defaultOptions = {
15176
onBuildExit: [],
15277
dev: true,
15378
verbose: false,
154-
safe: false
79+
safe: false,
80+
quiet: false
15581
};
15682

15783
var WebpackShellPlugin = function () {
@@ -163,7 +89,7 @@ var WebpackShellPlugin = function () {
16389

16490
createClass(WebpackShellPlugin, [{
16591
key: 'puts',
166-
value: function puts(error, stdout, stderr) {
92+
value: function puts(error) {
16793
if (error) {
16894
throw error;
16995
}
@@ -220,13 +146,13 @@ var WebpackShellPlugin = function () {
220146
}
221147
}, {
222148
key: 'mergeOptions',
223-
value: function mergeOptions(options, defaults) {
224-
for (var key in defaults) {
149+
value: function mergeOptions(options, defaults$$1) {
150+
for (var key in defaults$$1) {
225151
if (options.hasOwnProperty(key)) {
226-
defaults[key] = options[key];
152+
defaults$$1[key] = options[key];
227153
}
228154
}
229-
return defaults;
155+
return defaults$$1;
230156
}
231157
}, {
232158
key: 'apply',
@@ -235,13 +161,20 @@ var WebpackShellPlugin = function () {
235161

236162
compiler.plugin('compilation', function (compilation) {
237163
if (_this.options.verbose) {
238-
console.log('Report compilation: ' + compilation);
239-
console.warn('WebpackShellPlugin [' + new Date() + ']: Verbose is being deprecated, please remove.');
164+
if (!_this.options.quiet) {
165+
console.log('Report compilation: ' + compilation);
166+
//eslint-disable-next-line
167+
console.warn('WebpackShellPlugin [' + new Date() + ']: Verbose is being deprecated, please remove.');
168+
}
240169
}
241170
if (_this.options.onBuildStart.length) {
242-
console.log('Executing pre-build scripts');
243-
for (var i = 0; i < _this.options.onBuildStart.length; i++) {
244-
_this.handleScript(_this.options.onBuildStart[i]);
171+
if (!_this.options.quiet) {
172+
console.log('Executing pre-build scripts');
173+
}
174+
for (var index = 0; index < _this.options.onBuildStart.length;
175+
// eslint-disable-next-line
176+
index += 1) {
177+
_this.handleScript(_this.options.onBuildStart[index]);
245178
}
246179
if (_this.options.dev) {
247180
_this.options.onBuildStart = [];
@@ -251,9 +184,13 @@ var WebpackShellPlugin = function () {
251184

252185
compiler.plugin('after-emit', function (compilation, callback) {
253186
if (_this.options.onBuildEnd.length) {
254-
console.log('Executing post-build scripts');
255-
for (var i = 0; i < _this.options.onBuildEnd.length; i++) {
256-
_this.handleScript(_this.options.onBuildEnd[i]);
187+
if (!_this.options.quiet) {
188+
console.log('Executing post-build scripts');
189+
}
190+
for (var index = 0; index < _this.options.onBuildEnd.length;
191+
// eslint-disable-next-line
192+
index += 1) {
193+
_this.handleScript(_this.options.onBuildEnd[index]);
257194
}
258195
if (_this.options.dev) {
259196
_this.options.onBuildEnd = [];
@@ -264,9 +201,13 @@ var WebpackShellPlugin = function () {
264201

265202
compiler.plugin('done', function () {
266203
if (_this.options.onBuildExit.length) {
267-
console.log('Executing additional scripts before exit');
268-
for (var i = 0; i < _this.options.onBuildExit.length; i++) {
269-
_this.handleScript(_this.options.onBuildExit[i]);
204+
if (!_this.options.quiet) {
205+
console.log('Executing additional scripts before exit');
206+
}
207+
for (var index = 0; index < _this.options.onBuildExit.length;
208+
// eslint-disable-next-line
209+
index += 1) {
210+
_this.handleScript(_this.options.onBuildExit[index]);
270211
}
271212
}
272213
});
@@ -275,4 +216,4 @@ var WebpackShellPlugin = function () {
275216
return WebpackShellPlugin;
276217
}();
277218

278-
module.exports = WebpackShellPlugin;
219+
module.exports = WebpackShellPlugin;

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@
3434
},
3535
"homepage": "https://github.com/1337programming/webpack-shell-plugin",
3636
"devDependencies": {
37-
"babel-core": "^6.7.6",
38-
"babel-preset-es2015-rollup": "^1.1.1",
37+
"babel-core": "^6.24.1",
38+
"babel-preset-es2015-rollup": "^3.0.0",
3939
"css-loader": "^0.23.1",
4040
"eslint": "^2.7.0",
41-
"rollup": "^0.25.8",
42-
"rollup-plugin-babel": "^2.4.0",
41+
"rollup": "^0.41.6",
42+
"rollup-plugin-babel": "^2.7.1",
4343
"style-loader": "^0.13.1",
4444
"webpack": "^1.13.1"
4545
}

src/webpack-shell-plugin.js

+41-14
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,18 @@ const defaultOptions = {
88
onBuildExit: [],
99
dev: true,
1010
verbose: false,
11-
safe: false
11+
safe: false,
12+
quiet: false
1213
};
1314

1415
export default class WebpackShellPlugin {
1516
constructor(options) {
16-
this.options = this.validateInput(this.mergeOptions(options, defaultOptions));
17+
this.options = this.validateInput(
18+
this.mergeOptions(options, defaultOptions)
19+
);
1720
}
1821

19-
puts(error, stdout, stderr) {
22+
puts(error) {
2023
if (error) {
2124
throw error;
2225
}
@@ -72,13 +75,23 @@ export default class WebpackShellPlugin {
7275

7376
compiler.plugin('compilation', (compilation) => {
7477
if (this.options.verbose) {
75-
console.log(`Report compilation: ${compilation}`);
76-
console.warn(`WebpackShellPlugin [${new Date()}]: Verbose is being deprecated, please remove.`);
78+
if (!this.options.quiet) {
79+
console.log(`Report compilation: ${compilation}`);
80+
//eslint-disable-next-line
81+
console.warn(`WebpackShellPlugin [${new Date()}]: Verbose is being deprecated, please remove.`);
82+
}
7783
}
7884
if (this.options.onBuildStart.length) {
79-
console.log('Executing pre-build scripts');
80-
for (let i = 0; i < this.options.onBuildStart.length; i++) {
81-
this.handleScript(this.options.onBuildStart[i]);
85+
if (!this.options.quiet) {
86+
console.log('Executing pre-build scripts');
87+
}
88+
for (
89+
let index = 0;
90+
index < this.options.onBuildStart.length;
91+
// eslint-disable-next-line
92+
index += 1
93+
) {
94+
this.handleScript(this.options.onBuildStart[index]);
8295
}
8396
if (this.options.dev) {
8497
this.options.onBuildStart = [];
@@ -88,9 +101,16 @@ export default class WebpackShellPlugin {
88101

89102
compiler.plugin('after-emit', (compilation, callback) => {
90103
if (this.options.onBuildEnd.length) {
91-
console.log('Executing post-build scripts');
92-
for (let i = 0; i < this.options.onBuildEnd.length; i++) {
93-
this.handleScript(this.options.onBuildEnd[i]);
104+
if (!this.options.quiet) {
105+
console.log('Executing post-build scripts');
106+
}
107+
for (
108+
let index = 0;
109+
index < this.options.onBuildEnd.length;
110+
// eslint-disable-next-line
111+
index += 1
112+
) {
113+
this.handleScript(this.options.onBuildEnd[index]);
94114
}
95115
if (this.options.dev) {
96116
this.options.onBuildEnd = [];
@@ -101,9 +121,16 @@ export default class WebpackShellPlugin {
101121

102122
compiler.plugin('done', () => {
103123
if (this.options.onBuildExit.length) {
104-
console.log('Executing additional scripts before exit');
105-
for (let i = 0; i < this.options.onBuildExit.length; i++) {
106-
this.handleScript(this.options.onBuildExit[i]);
124+
if (!this.options.quiet) {
125+
console.log('Executing additional scripts before exit');
126+
}
127+
for (
128+
let index = 0;
129+
index < this.options.onBuildExit.length;
130+
// eslint-disable-next-line
131+
index += 1
132+
) {
133+
this.handleScript(this.options.onBuildExit[index]);
107134
}
108135
}
109136
});

0 commit comments

Comments
 (0)