@vbarbarosh/node-helpers 3.23.6 → 3.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/shell_spawn.js +27 -21
package/package.json
CHANGED
package/src/shell_spawn.js
CHANGED
|
@@ -1,33 +1,39 @@
|
|
|
1
|
+
const Promise = require('bluebird');
|
|
1
2
|
const child_process = require('child_process');
|
|
2
3
|
|
|
3
4
|
function shell_spawn(args, options)
|
|
4
5
|
{
|
|
5
|
-
let promise;
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
let init, promise;
|
|
7
|
+
const out = child_process.spawn(args[0], args.slice(1), options);
|
|
8
|
+
out.init = function () {
|
|
9
|
+
return init = init || new Promise(function (resolve, reject) {
|
|
10
|
+
out.once('error', init_error);
|
|
11
|
+
out.once('spawn', init_spawn);
|
|
12
|
+
function init_error(error) {
|
|
13
|
+
out.off('spawn', init_spawn);
|
|
14
|
+
reject(error);
|
|
15
|
+
}
|
|
16
|
+
function init_spawn() {
|
|
17
|
+
out.off('error', init_error);
|
|
18
|
+
resolve(out);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
out.promise = function () {
|
|
9
23
|
return promise = promise || new Promise(function (resolve, reject) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
proc.off('error', on_error);
|
|
16
|
-
proc.off('exit', on_exit);
|
|
17
|
-
reject(error);
|
|
18
|
-
}
|
|
24
|
+
out.once('error', promise_error);
|
|
25
|
+
out.once('exit', promise_exit);
|
|
26
|
+
function promise_error(error) {
|
|
27
|
+
out.off('exit', promise_exit);
|
|
28
|
+
reject(error);
|
|
19
29
|
}
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
proc.off('error', on_error);
|
|
24
|
-
proc.off('exit', on_exit);
|
|
25
|
-
resolve({code, signal});
|
|
26
|
-
}
|
|
30
|
+
function promise_exit(code, signal) {
|
|
31
|
+
out.off('error', promise_error);
|
|
32
|
+
resolve({code, signal});
|
|
27
33
|
}
|
|
28
34
|
});
|
|
29
35
|
};
|
|
30
|
-
return
|
|
36
|
+
return out;
|
|
31
37
|
}
|
|
32
38
|
|
|
33
39
|
module.exports = shell_spawn;
|