|
1 | 1 | var path = require('path');
|
2 | 2 | var os = require('os');
|
| 3 | +var spawn = require('child_process').spawn; |
3 | 4 | var notifier = require('node-notifier');
|
| 5 | +var template = require('es6-template-strings'); |
4 | 6 |
|
5 | 7 | var DEFAULT_LOGO = path.join(__dirname, 'logo.png');
|
6 | 8 |
|
7 | 9 | var WebpackNotifierPlugin = module.exports = function(options) {
|
8 | 10 | this.options = options || {};
|
9 | 11 | this.lastBuildSucceeded = false;
|
| 12 | + |
| 13 | + if (this.options.editor) { |
| 14 | + var editor = this.options.editor; |
| 15 | + editor.args = editor.args || [] |
| 16 | + |
| 17 | + notifier.on('click', function(notifierObject, notifierOptions) { |
| 18 | + var command = template(editor.command, notifierOptions.location); |
| 19 | + var args = editor.args.map(function(arg) { |
| 20 | + return template(arg, notifierOptions.location); |
| 21 | + }); |
| 22 | + |
| 23 | + if (command) { |
| 24 | + spawn(command, args); |
| 25 | + } |
| 26 | + }); |
| 27 | + } |
10 | 28 | };
|
11 | 29 |
|
12 | 30 | WebpackNotifierPlugin.prototype.compileMessage = function(stats) {
|
@@ -64,7 +82,9 @@ WebpackNotifierPlugin.prototype.compilationDone = function(stats) {
|
64 | 82 | title: this.options.title || 'Webpack',
|
65 | 83 | message: msg.body,
|
66 | 84 | contentImage: contentImage,
|
67 |
| - icon: (os.platform() === 'win32') ? contentImage : undefined |
| 85 | + icon: (os.platform() === 'win32') ? contentImage : undefined, |
| 86 | + wait: !!this.options.editor, |
| 87 | + location: msg.location |
68 | 88 | });
|
69 | 89 | }
|
70 | 90 | };
|
|
0 commit comments