1 |
|
2 | (function() {
|
3 | var spawn;
|
4 |
|
5 | spawn = require('cross-spawn');
|
6 |
|
7 | module.exports = function() {
|
8 | var i, scripts, stopCmd;
|
9 | this.stopped = true;
|
10 | if (!this.config.scripts || !this.config.scripts.stop) {
|
11 | return 'No scripts for: stop';
|
12 | }
|
13 | console.log("\nSTOP:".bold);
|
14 | scripts = this.config.scripts;
|
15 | i = 0;
|
16 | stopCmd = function() {
|
17 | var arg, cmd, command, description, proc, stop;
|
18 | if (!scripts.stop[i]) {
|
19 | console.log("\nDone!");
|
20 | return;
|
21 | }
|
22 | description = scripts.stop[i].description || scripts.stop[i];
|
23 | command = scripts.stop[i].command || scripts.stop[i];
|
24 | console.log(' STOP SCRIPT '.bgBlack.white + (' ' + description + ' ').bgWhite + " \n" + command.gray);
|
25 | stop = command;
|
26 | stop = [stop.substr(0, stop.indexOf(' ')), stop.substr(stop.indexOf(' ') + 1)];
|
27 | cmd = stop[0];
|
28 | arg = stop[1].split(' ');
|
29 | proc = spawn(cmd, arg);
|
30 | proc.stderr.on('data', function(data) {
|
31 | return console.log(data.toString().red);
|
32 | });
|
33 | proc.stdout.on('error', function(data) {
|
34 | return console.log(data.toString());
|
35 | });
|
36 | proc.stdout.on('data', function(data) {
|
37 | return console.log(data.toString());
|
38 | });
|
39 | proc.on('close', function(err) {
|
40 | return stopCmd();
|
41 | });
|
42 | proc.on('error', function(err) {
|
43 | return console.log(' ERROR '.bgRed.white + (' ' + err.message + ' ').bgWhite);
|
44 | });
|
45 | return i++;
|
46 | };
|
47 | stopCmd();
|
48 | return 'Stopping...';
|
49 | };
|
50 |
|
51 | }).call(this);
|