-
Notifications
You must be signed in to change notification settings - Fork 2
/
SoundNotificationWebpackPlugin.js
57 lines (42 loc) · 1.21 KB
/
SoundNotificationWebpackPlugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
/**
* WebpackSoundNotificationPlugin
*
* @type {exports|module.exports}
*/
var sys = require('util');
var exect = require('child_process').exec;
var player = 'paplay';
var successSound = '/usr/share/sounds/ubuntu/stereo/dialog-information.ogg';
var errorSound = '/usr/share/sounds/ubuntu/stereo/dialog-error.ogg';
function SoundNotificationWebpackPlugin(options) {
if(!options){
return;
}
player = options.player || player;
successSound = options.successSound || successSound;
errorSound = options.errorSound || errorSound;
}
SoundNotificationWebpackPlugin.prototype.apply = function (compiler) {
compiler.plugin('done', function(stats) {
if(stats.compilation.errors.length > 0){
return playErrorSound();
}
playSuccessSound();
});
compiler.plugin('failed', playErrorSound);
};
function playSuccessSound() {
playSound(successSound);
}
function playErrorSound() {
playSound(errorSound);
}
function playSound(soundFile) {
exec(player + ' ' + soundFile);
}
function exec(cmd) {
exect(cmd, function (error, stdout, stderr) {
console.log(stdout);
});
}
module.exports = SoundNotificationWebpackPlugin;