Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. // Public: Maps a process's output into an {Observable}
  6. //
  7. // exe - The program to execute
  8. // params - Arguments passed to the process
  9. // opts - Options that will be passed to child_process.spawn
  10. //
  11. // Returns an {Observable} with a single value, that is the output of the
  12. // spawned process
  13. function spawn(exe, params, opts) {
  14. return new Promise(function (resolve, reject) {
  15. var proc = null;
  16. d("Spawning ".concat(exe, " ").concat(params.join(' ')));
  17. if (!opts) {
  18. proc = (0, child_process_1.spawn)(exe, params);
  19. }
  20. else {
  21. proc = (0, child_process_1.spawn)(exe, params, opts);
  22. }
  23. // We need to wait until all three events have happened:
  24. // * stdout's pipe is closed
  25. // * stderr's pipe is closed
  26. // * We've got an exit code
  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 (chunk) {
  35. stdout += chunk;
  36. };
  37. proc.stdout.setEncoding('utf8').on('data', bufHandler);
  38. proc.stdout.once('close', release);
  39. proc.stderr.setEncoding('utf8').on('data', bufHandler);
  40. proc.stderr.once('close', release);
  41. proc.on('error', function (e) { return reject(e); });
  42. proc.on('close', function (code) {
  43. if (code === 0) {
  44. release();
  45. }
  46. else {
  47. rejected = true;
  48. reject(new Error("Failed with exit code: ".concat(code, "\nOutput:\n").concat(stdout)));
  49. }
  50. });
  51. });
  52. }
  53. exports.default = spawn;
  54. //# sourceMappingURL=spawn-promise.js.map