|
2 | 2 | import {
|
3 | 3 | EOL
|
4 | 4 | } from 'os';
|
5 |
| -import { spawn } from 'child_process'; |
| 5 | +import { spawning } from 'node-sys'; |
6 | 6 | import when from 'when';
|
7 | 7 | import {
|
8 | 8 | normalize,
|
@@ -92,34 +92,38 @@ export default function (binary = '7z', command = null, switches = {}, override
|
92 | 92 | // error's message. Otherwise progress with stdout message.
|
93 | 93 | let err;
|
94 | 94 | let reg = new RegExp('Error:(' + EOL + '|)?(.*)', 'i');
|
| 95 | + let onprogress = (object) => { |
| 96 | + progress(object.output); |
| 97 | + return args; |
| 98 | + }; |
| 99 | + |
| 100 | + let onerror = (data) => { |
| 101 | + let res = reg.exec(data); |
| 102 | + if (res) { |
| 103 | + err = new Error(res[2].substr(0, res[2].length - 1)); |
| 104 | + return err; |
| 105 | + } |
| 106 | + }; |
| 107 | + |
95 | 108 | let res = {
|
96 | 109 | cmd: cmd,
|
97 | 110 | args: args,
|
98 | 111 | options: {
|
99 |
| - stdio: 'pipe' |
| 112 | + stdio: 'pipe', |
| 113 | + onprogress: onprogress, |
| 114 | + onerror: onerror |
100 | 115 | }
|
101 | 116 | };
|
102 | 117 |
|
103 |
| - //console.log('>> ', res.cmd, res.args.join(' '), res.options,' <<'); |
104 |
| - let run = spawn(res.cmd, res.args, res.options); |
105 |
| - run.stderr.on('data', function (data) { |
106 |
| - let res = reg.exec(data.toString()); |
107 |
| - if (res) { |
108 |
| - err = new Error(res[2].substr(0, res[2].length - 1)); |
109 |
| - } |
110 |
| - }); |
111 |
| - run.stdout.on('data', function (data) { |
112 |
| - return progress(data.toString()); |
113 |
| - }); |
114 |
| - run.on('error', function (err) { |
115 |
| - reject(err); |
116 |
| - }); |
117 |
| - run.on('close', function (code) { |
118 |
| - if (code === 0) { |
119 |
| - return fulfill(args); |
120 |
| - } |
121 |
| - return reject(err, code); |
122 |
| - }); |
| 118 | + spawning(res.cmd, res.args, res.options) |
| 119 | + .then((data) => { |
| 120 | + if (data === args) |
| 121 | + return fulfill(args); |
123 | 122 |
|
| 123 | + return reject(err); |
| 124 | + }) |
| 125 | + .catch((err) => { |
| 126 | + return reject(err); |
| 127 | + }); |
124 | 128 | });
|
125 | 129 | };
|
0 commit comments