1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var child_process_1 = require("child_process");
|
4 | var d = require('debug')('electron-windows-installer:spawn');
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | function spawn(exe, params, opts) {
|
14 | return new Promise(function (resolve, reject) {
|
15 | var proc = null;
|
16 | d("Spawning " + exe + " " + params.join(' '));
|
17 | if (!opts) {
|
18 | proc = child_process_1.spawn(exe, params);
|
19 | }
|
20 | else {
|
21 | proc = child_process_1.spawn(exe, params, opts);
|
22 | }
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | var rejected = false;
|
28 | var refCount = 3;
|
29 | var stdout = '';
|
30 | var release = function () {
|
31 | if (--refCount <= 0 && !rejected)
|
32 | resolve(stdout);
|
33 | };
|
34 | var bufHandler = function (b) {
|
35 | var chunk = b.toString();
|
36 | stdout += chunk;
|
37 | };
|
38 | proc.stdout.on('data', bufHandler);
|
39 | proc.stdout.once('close', release);
|
40 | proc.stderr.on('data', bufHandler);
|
41 | proc.stderr.once('close', release);
|
42 | proc.on('error', function (e) { return reject(e); });
|
43 | proc.on('close', function (code) {
|
44 | if (code === 0) {
|
45 | release();
|
46 | }
|
47 | else {
|
48 | rejected = true;
|
49 | reject(new Error("Failed with exit code: " + code + "\nOutput:\n" + stdout));
|
50 | }
|
51 | });
|
52 | });
|
53 | }
|
54 | exports.default = spawn;
|
55 |
|
\ | No newline at end of file |