Newer
Older
CVSS_3.0_GUI / node_modules / nwjs-builder-phoenix / dist / lib / Runner.js
root on 7 May 2019 8 KB Initial commit
  1. "use strict";
  2. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  3. return new (P || (P = Promise))(function (resolve, reject) {
  4. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  5. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  6. function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
  7. step((generator = generator.apply(thisArg, _arguments || [])).next());
  8. });
  9. };
  10. var __generator = (this && this.__generator) || function (thisArg, body) {
  11. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  12. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  13. function verb(n) { return function (v) { return step([n, v]); }; }
  14. function step(op) {
  15. if (f) throw new TypeError("Generator is already executing.");
  16. while (_) try {
  17. if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
  18. if (y = 0, t) op = [0, t.value];
  19. switch (op[0]) {
  20. case 0: case 1: t = op; break;
  21. case 4: _.label++; return { value: op[1], done: false };
  22. case 5: _.label++; y = op[1]; op = [0]; continue;
  23. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  24. default:
  25. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  26. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  27. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  28. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  29. if (t[2]) _.ops.pop();
  30. _.trys.pop(); continue;
  31. }
  32. op = body.call(thisArg, _);
  33. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  34. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  35. }
  36. };
  37. Object.defineProperty(exports, "__esModule", { value: true });
  38. var path_1 = require("path");
  39. var fs_extra_1 = require("fs-extra");
  40. var debug = require('debug')('build:runner');
  41. var Downloader_1 = require("./Downloader");
  42. var FFmpegDownloader_1 = require("./FFmpegDownloader");
  43. var config_1 = require("./config");
  44. var util_1 = require("./util");
  45. var Runner = /** @class */ (function () {
  46. function Runner(options, args) {
  47. if (options === void 0) { options = {}; }
  48. this.args = args;
  49. this.options = util_1.mergeOptions(Runner.DEFAULT_OPTIONS, options);
  50. debug('in constructor', 'args', args);
  51. debug('in constructor', 'options', this.options);
  52. }
  53. Runner.prototype.run = function () {
  54. return __awaiter(this, void 0, void 0, function () {
  55. var platform, arch, pkg, config, downloader, runtimeDir, executable, _a, code, signal;
  56. return __generator(this, function (_b) {
  57. switch (_b.label) {
  58. case 0:
  59. platform = process.platform;
  60. arch = this.options.x86 || this.options.x64
  61. ? (this.options.x86 ? 'ia32' : 'x64')
  62. : process.arch;
  63. return [4 /*yield*/, fs_extra_1.readJson(path_1.resolve(this.args[0], this.options.chromeApp ? 'manifest.json' : 'package.json'))];
  64. case 1:
  65. pkg = _b.sent();
  66. config = new config_1.BuildConfig(pkg);
  67. debug('in run', 'config', config);
  68. downloader = new Downloader_1.Downloader({
  69. platform: platform, arch: arch,
  70. version: config.nwVersion,
  71. flavor: 'sdk',
  72. mirror: this.options.mirror,
  73. useCaches: true,
  74. showProgress: this.options.mute ? false : true,
  75. });
  76. if (!this.options.mute) {
  77. console.info('Fetching NW.js binary...', {
  78. platform: downloader.options.platform,
  79. arch: downloader.options.arch,
  80. version: downloader.options.version,
  81. flavor: downloader.options.flavor,
  82. });
  83. }
  84. return [4 /*yield*/, downloader.fetchAndExtract()];
  85. case 2:
  86. runtimeDir = _b.sent();
  87. if (config.ffmpegIntegration) {
  88. // FIXME: Integrate without overwriting extracted files.
  89. //await this.integrateFFmpeg(platform, arch, runtimeDir, pkg, config);
  90. if (!this.options.mute) {
  91. console.warn('Running with FFmpeg integration is not supported.');
  92. }
  93. }
  94. return [4 /*yield*/, util_1.findExecutable(platform, runtimeDir)];
  95. case 3:
  96. executable = _b.sent();
  97. return [4 /*yield*/, fs_extra_1.chmod(executable, 365)];
  98. case 4:
  99. _b.sent();
  100. if (!this.options.mute) {
  101. console.info('Launching NW.js app...');
  102. }
  103. return [4 /*yield*/, util_1.spawnAsync(executable, this.args, {
  104. detached: this.options.detached,
  105. })];
  106. case 5:
  107. _a = _b.sent(), code = _a.code, signal = _a.signal;
  108. if (!!this.options.mute) return [3 /*break*/, 8];
  109. if (!this.options.detached) return [3 /*break*/, 7];
  110. console.info('NW.js app detached.');
  111. return [4 /*yield*/, new Promise(function (resolve, reject) {
  112. setTimeout(resolve, 3000);
  113. })];
  114. case 6:
  115. _b.sent();
  116. return [3 /*break*/, 8];
  117. case 7:
  118. console.info("NW.js app exited with " + code + ".");
  119. _b.label = 8;
  120. case 8: return [2 /*return*/, code];
  121. }
  122. });
  123. });
  124. };
  125. Runner.prototype.integrateFFmpeg = function (platform, arch, runtimeDir, pkg, config) {
  126. return __awaiter(this, void 0, void 0, function () {
  127. var downloader, ffmpegDir, src, dest;
  128. return __generator(this, function (_a) {
  129. switch (_a.label) {
  130. case 0:
  131. downloader = new FFmpegDownloader_1.FFmpegDownloader({
  132. platform: platform, arch: arch,
  133. version: config.nwVersion,
  134. useCaches: true,
  135. showProgress: this.options.mute ? false : true,
  136. });
  137. if (!this.options.mute) {
  138. console.info('Fetching FFmpeg prebuilt...', {
  139. platform: downloader.options.platform,
  140. arch: downloader.options.arch,
  141. version: downloader.options.version,
  142. });
  143. }
  144. return [4 /*yield*/, downloader.fetchAndExtract()];
  145. case 1:
  146. ffmpegDir = _a.sent();
  147. return [4 /*yield*/, util_1.findFFmpeg(platform, ffmpegDir)];
  148. case 2:
  149. src = _a.sent();
  150. return [4 /*yield*/, util_1.findFFmpeg(platform, runtimeDir)];
  151. case 3:
  152. dest = _a.sent();
  153. return [4 /*yield*/, fs_extra_1.copy(src, dest)];
  154. case 4:
  155. _a.sent();
  156. return [2 /*return*/];
  157. }
  158. });
  159. });
  160. };
  161. Runner.DEFAULT_OPTIONS = {
  162. x86: false,
  163. x64: false,
  164. chromeApp: false,
  165. mirror: Downloader_1.Downloader.DEFAULT_OPTIONS.mirror,
  166. detached: false,
  167. mute: true,
  168. };
  169. return Runner;
  170. }());
  171. exports.Runner = Runner;
  172. //# sourceMappingURL=Runner.js.map
Buy Me A Coffee