1 |
|
2 | (function() {
|
3 | var path, spawn;
|
4 |
|
5 | path = require('path');
|
6 |
|
7 | spawn = require('cross-spawn');
|
8 |
|
9 | module.exports = function() {
|
10 | var cwd, i, scripts, stopCmd;
|
11 | this.stopped = true;
|
12 | if (!this.config.scripts || !this.config.scripts.stop) {
|
13 | return 'No scripts for: stop';
|
14 | }
|
15 | cwd = this.path;
|
16 | console.log("\nSTOP:".bold);
|
17 | scripts = this.config.scripts;
|
18 | i = 0;
|
19 | stopCmd = function() {
|
20 | var command, description, dir, proc;
|
21 | if (!scripts.stop[i]) {
|
22 | console.log("\nDone!");
|
23 | return;
|
24 | }
|
25 | if (scripts.stop[i].title && !scripts.stop[i].command) {
|
26 | console.log(' STOP TITLE '.bgGreen.white + (' ' + scripts.stop[i].title + ' ').bgWhite + " \n");
|
27 | i++;
|
28 | stopCmd();
|
29 | return;
|
30 | }
|
31 | description = scripts.stop[i].description || scripts.stop[i];
|
32 | command = scripts.stop[i].command || scripts.stop[i];
|
33 | if (scripts.stop[i].path) {
|
34 | if (scripts.stop[i].path.match(/^\//)) {
|
35 | dir = scripts.stop[i].path;
|
36 | } else {
|
37 | dir = cwd + "/" + scripts.stop[i].path;
|
38 | }
|
39 | dir = path.normalize(dir);
|
40 | } else {
|
41 | dir = cwd;
|
42 | }
|
43 | console.log(' STOP SCRIPT '.bgGreen.white + (' ' + description + ' ').bgWhite + " \n" + command.gray);
|
44 | proc = spawn('bash', ['-c', command], {
|
45 | cwd: dir
|
46 | });
|
47 | proc.stderr.on('data', function(data) {
|
48 | return console.log(data.toString().red);
|
49 | });
|
50 | proc.stdout.on('error', function(data) {
|
51 | return console.log(data.toString());
|
52 | });
|
53 | proc.stdout.on('data', function(data) {
|
54 | return console.log(data.toString());
|
55 | });
|
56 | proc.on('close', function(err) {
|
57 | return stopCmd();
|
58 | });
|
59 | proc.on('error', function(err) {
|
60 | return console.log(' ERROR '.bgRed.white + (' ' + err.message + ' ').bgWhite);
|
61 | });
|
62 | return i++;
|
63 | };
|
64 | stopCmd();
|
65 | return 'Stopping...';
|
66 | };
|
67 |
|
68 | }).call(this);
|