Skip to content

Commit be28343

Browse files
committed
Add onclick listener on notifier that runs editor
1 parent 9ca6e99 commit be28343

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

index.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,30 @@
11
var path = require('path');
22
var os = require('os');
3+
var spawn = require('child_process').spawn;
34
var notifier = require('node-notifier');
5+
var template = require('es6-template-strings');
46

57
var DEFAULT_LOGO = path.join(__dirname, 'logo.png');
68

79
var WebpackNotifierPlugin = module.exports = function(options) {
810
this.options = options || {};
911
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+
}
1028
};
1129

1230
WebpackNotifierPlugin.prototype.compileMessage = function(stats) {
@@ -64,7 +82,9 @@ WebpackNotifierPlugin.prototype.compilationDone = function(stats) {
6482
title: this.options.title || 'Webpack',
6583
message: msg.body,
6684
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
6888
});
6989
}
7090
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"author": "Tobias Bieniek <[email protected]>",
2222
"license": "ISC",
2323
"dependencies": {
24+
"es6-template-strings": "^2.0.0",
2425
"node-notifier": "^4.1.0"
2526
},
2627
"devDependencies": {

0 commit comments

Comments
 (0)