Builder.js 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139
  1. "use strict";
  2. var __assign = (this && this.__assign) || Object.assign || function(t) {
  3. for (var s, i = 1, n = arguments.length; i < n; i++) {
  4. s = arguments[i];
  5. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
  6. t[p] = s[p];
  7. }
  8. return t;
  9. };
  10. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  11. return new (P || (P = Promise))(function (resolve, reject) {
  12. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  13. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  14. function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
  15. step((generator = generator.apply(thisArg, _arguments || [])).next());
  16. });
  17. };
  18. var __generator = (this && this.__generator) || function (thisArg, body) {
  19. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  20. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  21. function verb(n) { return function (v) { return step([n, v]); }; }
  22. function step(op) {
  23. if (f) throw new TypeError("Generator is already executing.");
  24. while (_) try {
  25. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
  26. if (y = 0, t) op = [op[0] & 2, t.value];
  27. switch (op[0]) {
  28. case 0: case 1: t = op; break;
  29. case 4: _.label++; return { value: op[1], done: false };
  30. case 5: _.label++; y = op[1]; op = [0]; continue;
  31. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  32. default:
  33. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  34. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  35. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  36. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  37. if (t[2]) _.ops.pop();
  38. _.trys.pop(); continue;
  39. }
  40. op = body.call(thisArg, _);
  41. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  42. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  43. }
  44. };
  45. Object.defineProperty(exports, "__esModule", { value: true });
  46. var path_1 = require("path");
  47. var semver = require("semver");
  48. var fs_extra_1 = require("fs-extra");
  49. var Bluebird = require("bluebird");
  50. var debug = require('debug')('build:builder');
  51. var globby = require('globby');
  52. var rcedit = require('rcedit');
  53. var plist = require('plist');
  54. var Downloader_1 = require("./Downloader");
  55. var FFmpegDownloader_1 = require("./FFmpegDownloader");
  56. var config_1 = require("./config");
  57. var common_1 = require("./common");
  58. var nsis_gen_1 = require("./nsis-gen");
  59. var util_1 = require("./util");
  60. var Builder = /** @class */ (function () {
  61. function Builder(options, dir) {
  62. if (options === void 0) { options = {}; }
  63. this.dir = dir;
  64. this.options = util_1.mergeOptions(Builder.DEFAULT_OPTIONS, options);
  65. debug('in constructor', 'dir', dir);
  66. debug('in constructor', 'options', this.options);
  67. }
  68. Builder.prototype.build = function () {
  69. return __awaiter(this, void 0, void 0, function () {
  70. var tasks, _i, _a, task, _b, platform, arch, pkg, config, _c, tasks_1, _d, platform, arch, started, err_1;
  71. var _this = this;
  72. return __generator(this, function (_e) {
  73. switch (_e.label) {
  74. case 0:
  75. tasks = [];
  76. ['win', 'mac', 'linux'].map(function (platform) {
  77. ['x86', 'x64'].map(function (arch) {
  78. if (_this.options[platform] && _this.options[arch]) {
  79. tasks.push([platform, arch]);
  80. }
  81. });
  82. });
  83. for (_i = 0, _a = this.options.tasks; _i < _a.length; _i++) {
  84. task = _a[_i];
  85. _b = task.split('-'), platform = _b[0], arch = _b[1];
  86. if (['win', 'mac', 'linux'].indexOf(platform) >= 0) {
  87. if (['x86', 'x64'].indexOf(arch) >= 0) {
  88. tasks.push([platform, arch]);
  89. }
  90. }
  91. }
  92. if (!this.options.mute) {
  93. console.info('Starting building tasks...', {
  94. tasks: tasks,
  95. concurrent: this.options.concurrent,
  96. });
  97. }
  98. if (tasks.length == 0) {
  99. throw new Error('ERROR_NO_TASK');
  100. }
  101. if (!this.options.concurrent) return [3 /*break*/, 2];
  102. return [4 /*yield*/, Bluebird.map(tasks, function (_a) {
  103. var platform = _a[0], arch = _a[1];
  104. return __awaiter(_this, void 0, void 0, function () {
  105. var options, builder, started;
  106. return __generator(this, function (_b) {
  107. switch (_b.label) {
  108. case 0:
  109. options = {};
  110. options[platform] = true;
  111. options[arch] = true;
  112. options.mirror = this.options.mirror;
  113. options.concurrent = false;
  114. options.mute = true;
  115. builder = new Builder(options, this.dir);
  116. started = Date.now();
  117. if (!this.options.mute) {
  118. console.info("Building for " + platform + ", " + arch + " starts...");
  119. }
  120. return [4 /*yield*/, builder.build()];
  121. case 1:
  122. _b.sent();
  123. if (!this.options.mute) {
  124. console.info("Building for " + platform + ", " + arch + " ends within " + this.getTimeDiff(started) + "s.");
  125. }
  126. return [2 /*return*/];
  127. }
  128. });
  129. });
  130. })];
  131. case 1:
  132. _e.sent();
  133. return [3 /*break*/, 10];
  134. case 2: return [4 /*yield*/, fs_extra_1.readJson(path_1.resolve(this.dir, this.options.chromeApp ? 'manifest.json' : 'package.json'))];
  135. case 3:
  136. pkg = _e.sent();
  137. config = new config_1.BuildConfig(pkg);
  138. debug('in build', 'config', config);
  139. _c = 0, tasks_1 = tasks;
  140. _e.label = 4;
  141. case 4:
  142. if (!(_c < tasks_1.length)) return [3 /*break*/, 10];
  143. _d = tasks_1[_c], platform = _d[0], arch = _d[1];
  144. started = Date.now();
  145. if (!this.options.mute) {
  146. console.info("Building for " + platform + ", " + arch + " starts...");
  147. }
  148. _e.label = 5;
  149. case 5:
  150. _e.trys.push([5, 7, , 8]);
  151. return [4 /*yield*/, this.buildTask(platform, arch, pkg, config)];
  152. case 6:
  153. _e.sent();
  154. return [3 /*break*/, 8];
  155. case 7:
  156. err_1 = _e.sent();
  157. console.warn(err_1);
  158. return [3 /*break*/, 8];
  159. case 8:
  160. if (!this.options.mute) {
  161. console.info("Building for " + platform + ", " + arch + " ends within " + this.getTimeDiff(started) + "s.");
  162. }
  163. _e.label = 9;
  164. case 9:
  165. _c++;
  166. return [3 /*break*/, 4];
  167. case 10: return [2 /*return*/];
  168. }
  169. });
  170. });
  171. };
  172. Builder.prototype.getTimeDiff = function (started) {
  173. return ((Date.now() - started) / 1000).toFixed(2);
  174. };
  175. Builder.prototype.writeStrippedManifest = function (path, pkg, config) {
  176. return __awaiter(this, void 0, void 0, function () {
  177. var json, key;
  178. return __generator(this, function (_a) {
  179. switch (_a.label) {
  180. case 0:
  181. json = {};
  182. for (key in pkg) {
  183. if (pkg.hasOwnProperty(key) && config.strippedProperties.indexOf(key) === -1) {
  184. if (config.overriddenProperties && config.overriddenProperties.hasOwnProperty(key)) {
  185. json[key] = config.overriddenProperties[key];
  186. }
  187. else {
  188. json[key] = pkg[key];
  189. }
  190. }
  191. }
  192. return [4 /*yield*/, fs_extra_1.writeFile(path, JSON.stringify(json))];
  193. case 1:
  194. _a.sent();
  195. return [2 /*return*/];
  196. }
  197. });
  198. });
  199. };
  200. Builder.prototype.parseOutputPattern = function (pattern, options, pkg, config) {
  201. return pattern.replace(/\$\{\s*(\w+)\s*\}/g, function (match, key) {
  202. switch (key.toLowerCase()) {
  203. case 'name':
  204. return options.name;
  205. case 'version':
  206. return options.version;
  207. case 'platform':
  208. return options.platform;
  209. case 'arch':
  210. return options.arch;
  211. default:
  212. throw new Error('ERROR_KEY_UNKNOWN');
  213. }
  214. });
  215. };
  216. Builder.prototype.combineExecutable = function (executable, nwFile) {
  217. return new Promise(function (resolve, reject) {
  218. var nwStream = fs_extra_1.createReadStream(nwFile);
  219. var stream = fs_extra_1.createWriteStream(executable, {
  220. flags: 'a',
  221. });
  222. nwStream.on('error', reject);
  223. stream.on('error', reject);
  224. stream.on('finish', resolve);
  225. nwStream.pipe(stream);
  226. });
  227. };
  228. Builder.prototype.readPlist = function (path) {
  229. return fs_extra_1.readFile(path, {
  230. encoding: 'utf-8',
  231. })
  232. .then(function (data) { return plist.parse(data); });
  233. };
  234. Builder.prototype.writePlist = function (path, p) {
  235. return fs_extra_1.writeFile(path, plist.build(p));
  236. };
  237. Builder.prototype.updateWinResources = function (targetDir, appRoot, pkg, config) {
  238. var _this = this;
  239. var pathResolve = path_1.resolve;
  240. return new Promise(function (resolve, reject) {
  241. var path = pathResolve(targetDir, 'nw.exe');
  242. var rc = {
  243. 'product-version': util_1.fixWindowsVersion(config.win.productVersion),
  244. 'file-version': util_1.fixWindowsVersion(config.win.fileVersion),
  245. 'version-string': __assign({ ProductName: config.win.productName, CompanyName: config.win.companyName, FileDescription: config.win.fileDescription, LegalCopyright: config.win.copyright }, config.win.versionStrings),
  246. 'icon': config.win.icon ? pathResolve(_this.dir, config.win.icon) : undefined,
  247. };
  248. rcedit(path, rc, function (err) { return err ? reject(err) : resolve(); });
  249. });
  250. };
  251. Builder.prototype.renameWinApp = function (targetDir, appRoot, pkg, config) {
  252. var src = path_1.resolve(targetDir, 'nw.exe');
  253. var dest = path_1.resolve(targetDir, config.win.productName + ".exe");
  254. return fs_extra_1.rename(src, dest);
  255. };
  256. Builder.prototype.updatePlist = function (targetDir, appRoot, pkg, config) {
  257. return __awaiter(this, void 0, void 0, function () {
  258. var path, plist, key;
  259. return __generator(this, function (_a) {
  260. switch (_a.label) {
  261. case 0:
  262. path = path_1.resolve(targetDir, './nwjs.app/Contents/Info.plist');
  263. return [4 /*yield*/, this.readPlist(path)];
  264. case 1:
  265. plist = _a.sent();
  266. plist.CFBundleIdentifier = config.appId;
  267. plist.CFBundleName = config.mac.name;
  268. plist.CFBundleExecutable = config.mac.displayName;
  269. plist.CFBundleDisplayName = config.mac.displayName;
  270. plist.CFBundleVersion = config.mac.version;
  271. plist.CFBundleShortVersionString = config.mac.version;
  272. for (key in config.mac.plistStrings) {
  273. if (config.mac.plistStrings.hasOwnProperty(key)) {
  274. plist[key] = config.mac.plistStrings[key];
  275. }
  276. }
  277. return [4 /*yield*/, this.writePlist(path, plist)];
  278. case 2:
  279. _a.sent();
  280. return [2 /*return*/];
  281. }
  282. });
  283. });
  284. };
  285. Builder.prototype.updateHelperPlist = function (targetDir, appRoot, pkg, config) {
  286. return __awaiter(this, void 0, void 0, function () {
  287. var helperPath, path, plist, bin;
  288. return __generator(this, function (_a) {
  289. switch (_a.label) {
  290. case 0:
  291. if (!this.canRenameMacHelperApp(pkg, config)) {
  292. return [2 /*return*/];
  293. }
  294. return [4 /*yield*/, this.findMacHelperApp(targetDir)];
  295. case 1:
  296. helperPath = _a.sent();
  297. path = path_1.resolve(helperPath, 'Contents/Info.plist');
  298. return [4 /*yield*/, this.readPlist(path)];
  299. case 2:
  300. plist = _a.sent();
  301. bin = pkg.product_string + ' Helper';
  302. plist.CFBundleIdentifier = config.appId + '.helper';
  303. plist.CFBundleDisplayName = bin;
  304. plist.CFBundleExecutable = bin;
  305. plist.CFBundleName = bin;
  306. return [4 /*yield*/, this.writePlist(path, plist)];
  307. case 3:
  308. _a.sent();
  309. return [2 /*return*/];
  310. }
  311. });
  312. });
  313. };
  314. Builder.prototype.updateMacIcons = function (targetDir, appRoot, pkg, config) {
  315. return __awaiter(this, void 0, void 0, function () {
  316. var copyIcon;
  317. var _this = this;
  318. return __generator(this, function (_a) {
  319. switch (_a.label) {
  320. case 0:
  321. copyIcon = function (iconPath, dest) { return __awaiter(_this, void 0, void 0, function () {
  322. return __generator(this, function (_a) {
  323. switch (_a.label) {
  324. case 0:
  325. if (!iconPath) {
  326. // use the default
  327. return [2 /*return*/];
  328. }
  329. return [4 /*yield*/, fs_extra_1.copy(path_1.resolve(this.dir, iconPath), dest)];
  330. case 1:
  331. _a.sent();
  332. return [2 /*return*/];
  333. }
  334. });
  335. }); };
  336. return [4 /*yield*/, copyIcon(config.mac.icon, path_1.resolve(targetDir, './nwjs.app/Contents/Resources/app.icns'))];
  337. case 1:
  338. _a.sent();
  339. return [4 /*yield*/, copyIcon(config.mac.documentIcon, path_1.resolve(targetDir, './nwjs.app/Contents/Resources/document.icns'))];
  340. case 2:
  341. _a.sent();
  342. return [2 /*return*/];
  343. }
  344. });
  345. });
  346. };
  347. Builder.prototype.fixMacMeta = function (targetDir, appRoot, pkg, config) {
  348. return __awaiter(this, void 0, void 0, function () {
  349. var files, _i, files_1, file, path, data, encoding, strings, newStrings;
  350. return __generator(this, function (_a) {
  351. switch (_a.label) {
  352. case 0: return [4 /*yield*/, globby(['**/InfoPlist.strings'], {
  353. cwd: targetDir,
  354. })];
  355. case 1:
  356. files = _a.sent();
  357. _i = 0, files_1 = files;
  358. _a.label = 2;
  359. case 2:
  360. if (!(_i < files_1.length)) return [3 /*break*/, 6];
  361. file = files_1[_i];
  362. path = path_1.resolve(targetDir, file);
  363. return [4 /*yield*/, fs_extra_1.readFile(path)];
  364. case 3:
  365. data = _a.sent();
  366. encoding = data.indexOf(Buffer.from('43004600', 'hex')) >= 0
  367. ? 'ucs2' : 'utf-8';
  368. strings = data.toString(encoding);
  369. newStrings = strings.replace(/([A-Za-z]+)\s+=\s+"(.+?)";/g, function (match, key, value) {
  370. switch (key) {
  371. case 'CFBundleName':
  372. return key + " = \"" + config.mac.name + "\";";
  373. case 'CFBundleDisplayName':
  374. return key + " = \"" + config.mac.displayName + "\";";
  375. case 'CFBundleGetInfoString':
  376. return key + " = \"" + config.mac.version + "\";";
  377. case 'NSContactsUsageDescription':
  378. return key + " = \"" + config.mac.description + "\";";
  379. case 'NSHumanReadableCopyright':
  380. return key + " = \"" + config.mac.copyright + "\";";
  381. default:
  382. return key + " = \"" + value + "\";";
  383. }
  384. });
  385. return [4 /*yield*/, fs_extra_1.writeFile(path, Buffer.from(newStrings, encoding))];
  386. case 4:
  387. _a.sent();
  388. _a.label = 5;
  389. case 5:
  390. _i++;
  391. return [3 /*break*/, 2];
  392. case 6: return [2 /*return*/];
  393. }
  394. });
  395. });
  396. };
  397. Builder.prototype.renameMacApp = function (targetDir, appRoot, pkg, config) {
  398. return __awaiter(this, void 0, void 0, function () {
  399. var app, bin, dest;
  400. return __generator(this, function (_a) {
  401. switch (_a.label) {
  402. case 0:
  403. app = path_1.resolve(targetDir, 'nwjs.app');
  404. bin = path_1.resolve(app, './Contents/MacOS/nwjs');
  405. dest = bin.replace(/nwjs$/, config.mac.displayName);
  406. return [4 /*yield*/, fs_extra_1.rename(bin, dest)];
  407. case 1:
  408. _a.sent();
  409. dest = app.replace(/nwjs\.app$/, config.mac.displayName + ".app");
  410. return [2 /*return*/, fs_extra_1.rename(app, dest)];
  411. }
  412. });
  413. });
  414. };
  415. Builder.prototype.renameMacHelperApp = function (targetDir, appRoot, pkg, config) {
  416. return __awaiter(this, void 0, void 0, function () {
  417. var app, bin, dest;
  418. return __generator(this, function (_a) {
  419. switch (_a.label) {
  420. case 0:
  421. if (!this.canRenameMacHelperApp(pkg, config)) {
  422. return [2 /*return*/];
  423. }
  424. return [4 /*yield*/, this.findMacHelperApp(targetDir)];
  425. case 1:
  426. app = _a.sent();
  427. bin = path_1.resolve(app, './Contents/MacOS/nwjs Helper');
  428. dest = bin.replace(/nwjs Helper$/, pkg.product_string + " Helper");
  429. return [4 /*yield*/, fs_extra_1.rename(bin, dest)];
  430. case 2:
  431. _a.sent();
  432. dest = app.replace(/nwjs Helper\.app$/, pkg.product_string + " Helper.app");
  433. return [2 /*return*/, fs_extra_1.rename(app, dest)];
  434. }
  435. });
  436. });
  437. };
  438. Builder.prototype.canRenameMacHelperApp = function (pkg, config) {
  439. if (semver.lt(config.nwVersion, '0.24.4')) {
  440. // this version doesn't support Helper app renaming.
  441. return false;
  442. }
  443. if (!pkg.product_string) {
  444. // we can't rename the Helper app as we don't have a new name.
  445. return false;
  446. }
  447. return true;
  448. };
  449. Builder.prototype.findMacHelperApp = function (targetDir) {
  450. return __awaiter(this, void 0, void 0, function () {
  451. var path, versions;
  452. return __generator(this, function (_a) {
  453. switch (_a.label) {
  454. case 0:
  455. path = path_1.resolve(targetDir, './nwjs.app/Contents/Versions');
  456. return [4 /*yield*/, fs_extra_1.readdir(path)];
  457. case 1:
  458. versions = _a.sent();
  459. if (!versions || versions.length !== 1) {
  460. throw new Error("Can't rename the Helper as we can't find it");
  461. }
  462. return [2 /*return*/, path_1.resolve(path, versions[0], 'nwjs Helper.app')];
  463. }
  464. });
  465. });
  466. };
  467. Builder.prototype.fixLinuxMode = function (targetDir, appRoot, pkg, config) {
  468. return __awaiter(this, void 0, void 0, function () {
  469. var path;
  470. return __generator(this, function (_a) {
  471. switch (_a.label) {
  472. case 0:
  473. path = path_1.resolve(targetDir, 'nw');
  474. return [4 /*yield*/, fs_extra_1.chmod(path, 484)];
  475. case 1:
  476. _a.sent();
  477. return [2 /*return*/];
  478. }
  479. });
  480. });
  481. };
  482. Builder.prototype.renameLinuxApp = function (targetDir, appRoot, pkg, config) {
  483. var src = path_1.resolve(targetDir, 'nw');
  484. var dest = path_1.resolve(targetDir, "" + pkg.name);
  485. return fs_extra_1.rename(src, dest);
  486. };
  487. Builder.prototype.prepareWinBuild = function (targetDir, appRoot, pkg, config) {
  488. return __awaiter(this, void 0, void 0, function () {
  489. return __generator(this, function (_a) {
  490. switch (_a.label) {
  491. case 0: return [4 /*yield*/, this.updateWinResources(targetDir, appRoot, pkg, config)];
  492. case 1:
  493. _a.sent();
  494. return [2 /*return*/];
  495. }
  496. });
  497. });
  498. };
  499. Builder.prototype.prepareMacBuild = function (targetDir, appRoot, pkg, config) {
  500. return __awaiter(this, void 0, void 0, function () {
  501. return __generator(this, function (_a) {
  502. switch (_a.label) {
  503. case 0: return [4 /*yield*/, this.updateHelperPlist(targetDir, appRoot, pkg, config)];
  504. case 1:
  505. _a.sent();
  506. return [4 /*yield*/, this.updatePlist(targetDir, appRoot, pkg, config)];
  507. case 2:
  508. _a.sent();
  509. return [4 /*yield*/, this.updateMacIcons(targetDir, appRoot, pkg, config)];
  510. case 3:
  511. _a.sent();
  512. return [4 /*yield*/, this.fixMacMeta(targetDir, appRoot, pkg, config)];
  513. case 4:
  514. _a.sent();
  515. return [2 /*return*/];
  516. }
  517. });
  518. });
  519. };
  520. Builder.prototype.prepareLinuxBuild = function (targetDir, appRoot, pkg, config) {
  521. return __awaiter(this, void 0, void 0, function () {
  522. return __generator(this, function (_a) {
  523. switch (_a.label) {
  524. case 0: return [4 /*yield*/, this.fixLinuxMode(targetDir, appRoot, pkg, config)];
  525. case 1:
  526. _a.sent();
  527. return [2 /*return*/];
  528. }
  529. });
  530. });
  531. };
  532. Builder.prototype.copyFiles = function (platform, targetDir, appRoot, pkg, config) {
  533. return __awaiter(this, void 0, void 0, function () {
  534. var generalExcludes, dependenciesExcludes, ignore, files, _a, nwFile, tempDir, executable, _i, files_2, file, _b, files_3, file;
  535. return __generator(this, function (_c) {
  536. switch (_c.label) {
  537. case 0:
  538. generalExcludes = [
  539. '**/node_modules/.bin',
  540. '**/node_modules/*/{ example, examples, test, tests }',
  541. '**/{ .DS_Store, .git, .hg, .svn, *.log }',
  542. ];
  543. return [4 /*yield*/, util_1.findExcludableDependencies(this.dir, pkg)
  544. .then(function (excludable) {
  545. return excludable.map(function (excludable) { return [excludable, excludable + "/**/*"]; });
  546. })
  547. .then(function (excludes) {
  548. return Array.prototype.concat.apply([], excludes);
  549. })];
  550. case 1:
  551. dependenciesExcludes = _c.sent();
  552. debug('in copyFiles', 'dependenciesExcludes', dependenciesExcludes);
  553. ignore = config.excludes.concat(generalExcludes, dependenciesExcludes, [config.output, config.output + "/**/*"]);
  554. debug('in copyFiles', 'ignore', ignore);
  555. return [4 /*yield*/, globby(config.files, {
  556. cwd: this.dir,
  557. // TODO: https://github.com/isaacs/node-glob#options, warn for cyclic links.
  558. follow: true,
  559. mark: true,
  560. ignore: ignore,
  561. })];
  562. case 2:
  563. files = _c.sent();
  564. debug('in copyFiles', 'config.files', config.files);
  565. debug('in copyFiles', 'files', files);
  566. if (!config.packed) return [3 /*break*/, 21];
  567. _a = platform;
  568. switch (_a) {
  569. case 'win32': return [3 /*break*/, 3];
  570. case 'win': return [3 /*break*/, 3];
  571. case 'linux': return [3 /*break*/, 3];
  572. case 'darwin': return [3 /*break*/, 13];
  573. case 'osx': return [3 /*break*/, 13];
  574. case 'mac': return [3 /*break*/, 13];
  575. }
  576. return [3 /*break*/, 19];
  577. case 3: return [4 /*yield*/, util_1.tmpName({
  578. postfix: '.zip',
  579. })];
  580. case 4:
  581. nwFile = _c.sent();
  582. return [4 /*yield*/, util_1.compress(this.dir, files.filter(function (file) { return !file.endsWith('/'); }), 'zip', nwFile)];
  583. case 5:
  584. _c.sent();
  585. return [4 /*yield*/, util_1.tmpDir()];
  586. case 6:
  587. tempDir = (_c.sent()).path;
  588. return [4 /*yield*/, this.writeStrippedManifest(path_1.resolve(tempDir, 'package.json'), pkg, config)];
  589. case 7:
  590. _c.sent();
  591. return [4 /*yield*/, util_1.compress(tempDir, ['./package.json'], 'zip', nwFile)];
  592. case 8:
  593. _c.sent();
  594. return [4 /*yield*/, fs_extra_1.remove(tempDir)];
  595. case 9:
  596. _c.sent();
  597. return [4 /*yield*/, util_1.findExecutable(platform, targetDir)];
  598. case 10:
  599. executable = _c.sent();
  600. return [4 /*yield*/, this.combineExecutable(executable, nwFile)];
  601. case 11:
  602. _c.sent();
  603. return [4 /*yield*/, fs_extra_1.remove(nwFile)];
  604. case 12:
  605. _c.sent();
  606. return [3 /*break*/, 20];
  607. case 13:
  608. _i = 0, files_2 = files;
  609. _c.label = 14;
  610. case 14:
  611. if (!(_i < files_2.length)) return [3 /*break*/, 17];
  612. file = files_2[_i];
  613. return [4 /*yield*/, util_1.copyFileAsync(path_1.resolve(this.dir, file), path_1.resolve(appRoot, file))];
  614. case 15:
  615. _c.sent();
  616. _c.label = 16;
  617. case 16:
  618. _i++;
  619. return [3 /*break*/, 14];
  620. case 17: return [4 /*yield*/, this.writeStrippedManifest(path_1.resolve(appRoot, 'package.json'), pkg, config)];
  621. case 18:
  622. _c.sent();
  623. return [3 /*break*/, 20];
  624. case 19: throw new Error('ERROR_UNKNOWN_PLATFORM');
  625. case 20: return [3 /*break*/, 27];
  626. case 21:
  627. _b = 0, files_3 = files;
  628. _c.label = 22;
  629. case 22:
  630. if (!(_b < files_3.length)) return [3 /*break*/, 25];
  631. file = files_3[_b];
  632. return [4 /*yield*/, util_1.copyFileAsync(path_1.resolve(this.dir, file), path_1.resolve(appRoot, file))];
  633. case 23:
  634. _c.sent();
  635. _c.label = 24;
  636. case 24:
  637. _b++;
  638. return [3 /*break*/, 22];
  639. case 25: return [4 /*yield*/, this.writeStrippedManifest(path_1.resolve(appRoot, 'package.json'), pkg, config)];
  640. case 26:
  641. _c.sent();
  642. _c.label = 27;
  643. case 27: return [2 /*return*/];
  644. }
  645. });
  646. });
  647. };
  648. Builder.prototype.integrateFFmpeg = function (platform, arch, targetDir, pkg, config) {
  649. return __awaiter(this, void 0, void 0, function () {
  650. var downloader, ffmpegDir, src, dest;
  651. return __generator(this, function (_a) {
  652. switch (_a.label) {
  653. case 0:
  654. downloader = new FFmpegDownloader_1.FFmpegDownloader({
  655. platform: platform, arch: arch,
  656. version: config.nwVersion,
  657. useCaches: true,
  658. showProgress: this.options.mute ? false : true,
  659. destination: this.options.destination,
  660. });
  661. if (!this.options.mute) {
  662. console.info('Fetching FFmpeg prebuilt...', {
  663. platform: downloader.options.platform,
  664. arch: downloader.options.arch,
  665. version: downloader.options.version,
  666. });
  667. }
  668. return [4 /*yield*/, downloader.fetchAndExtract()];
  669. case 1:
  670. ffmpegDir = _a.sent();
  671. return [4 /*yield*/, util_1.findFFmpeg(platform, ffmpegDir)];
  672. case 2:
  673. src = _a.sent();
  674. return [4 /*yield*/, util_1.findFFmpeg(platform, targetDir)];
  675. case 3:
  676. dest = _a.sent();
  677. return [4 /*yield*/, fs_extra_1.copy(src, dest)];
  678. case 4:
  679. _a.sent();
  680. return [2 /*return*/];
  681. }
  682. });
  683. });
  684. };
  685. Builder.prototype.buildNsisDiffUpdater = function (platform, arch, versionInfo, fromVersion, toVersion, pkg, config) {
  686. return __awaiter(this, void 0, void 0, function () {
  687. var diffNsis, fromDir, _a, _b, toDir, _c, _d, data, script;
  688. return __generator(this, function (_e) {
  689. switch (_e.label) {
  690. case 0:
  691. diffNsis = path_1.resolve(this.dir, config.output, pkg.name + "-" + toVersion + "-from-" + fromVersion + "-" + platform + "-" + arch + "-Update.exe");
  692. _a = path_1.resolve;
  693. _b = [this.dir, config.output];
  694. return [4 /*yield*/, versionInfo.getVersion(fromVersion)];
  695. case 1:
  696. fromDir = _a.apply(void 0, _b.concat([(_e.sent()).source]));
  697. _c = path_1.resolve;
  698. _d = [this.dir, config.output];
  699. return [4 /*yield*/, versionInfo.getVersion(toVersion)];
  700. case 2:
  701. toDir = _c.apply(void 0, _d.concat([(_e.sent()).source]));
  702. return [4 /*yield*/, (new nsis_gen_1.NsisDiffer(fromDir, toDir, {
  703. // Basic.
  704. appName: config.win.productName,
  705. companyName: config.win.companyName,
  706. description: config.win.fileDescription,
  707. version: util_1.fixWindowsVersion(config.win.productVersion),
  708. copyright: config.win.copyright,
  709. icon: config.nsis.icon ? path_1.resolve(this.dir, config.nsis.icon) : undefined,
  710. unIcon: config.nsis.unIcon ? path_1.resolve(this.dir, config.nsis.unIcon) : undefined,
  711. // Compression.
  712. compression: 'lzma',
  713. solid: true,
  714. languages: config.nsis.languages,
  715. installDirectory: config.nsis.installDirectory,
  716. // Output.
  717. output: diffNsis,
  718. })).make()];
  719. case 3:
  720. data = _e.sent();
  721. return [4 /*yield*/, util_1.tmpName()];
  722. case 4:
  723. script = _e.sent();
  724. return [4 /*yield*/, fs_extra_1.writeFile(script, data)];
  725. case 5:
  726. _e.sent();
  727. return [4 /*yield*/, nsis_gen_1.nsisBuild(toDir, script, {
  728. mute: this.options.mute,
  729. })];
  730. case 6:
  731. _e.sent();
  732. return [4 /*yield*/, fs_extra_1.remove(script)];
  733. case 7:
  734. _e.sent();
  735. return [4 /*yield*/, versionInfo.addUpdater(toVersion, fromVersion, arch, diffNsis)];
  736. case 8:
  737. _e.sent();
  738. return [2 /*return*/];
  739. }
  740. });
  741. });
  742. };
  743. Builder.prototype.buildDirTarget = function (platform, arch, runtimeDir, pkg, config) {
  744. return __awaiter(this, void 0, void 0, function () {
  745. var targetDir, runtimeRoot, appRoot, _a;
  746. return __generator(this, function (_b) {
  747. switch (_b.label) {
  748. case 0:
  749. targetDir = path_1.resolve(this.dir, config.output, this.parseOutputPattern(config.outputPattern, {
  750. name: pkg.name,
  751. version: pkg.version,
  752. platform: platform, arch: arch,
  753. }, pkg, config));
  754. return [4 /*yield*/, util_1.findRuntimeRoot(platform, runtimeDir)];
  755. case 1:
  756. runtimeRoot = _b.sent();
  757. appRoot = path_1.resolve(targetDir, (function () {
  758. switch (platform) {
  759. case 'win32':
  760. case 'win':
  761. case 'linux':
  762. return './';
  763. case 'darwin':
  764. case 'osx':
  765. case 'mac':
  766. return './nwjs.app/Contents/Resources/app.nw/';
  767. default:
  768. throw new Error('ERROR_UNKNOWN_PLATFORM');
  769. }
  770. })());
  771. return [4 /*yield*/, fs_extra_1.emptyDir(targetDir)];
  772. case 2:
  773. _b.sent();
  774. return [4 /*yield*/, fs_extra_1.copy(runtimeRoot, targetDir, {
  775. //dereference: true,
  776. })];
  777. case 3:
  778. _b.sent();
  779. if (!config.ffmpegIntegration) return [3 /*break*/, 5];
  780. return [4 /*yield*/, this.integrateFFmpeg(platform, arch, targetDir, pkg, config)];
  781. case 4:
  782. _b.sent();
  783. _b.label = 5;
  784. case 5: return [4 /*yield*/, fs_extra_1.ensureDir(appRoot)];
  785. case 6:
  786. _b.sent();
  787. _a = platform;
  788. switch (_a) {
  789. case 'win32': return [3 /*break*/, 7];
  790. case 'win': return [3 /*break*/, 7];
  791. case 'darwin': return [3 /*break*/, 11];
  792. case 'osx': return [3 /*break*/, 11];
  793. case 'mac': return [3 /*break*/, 11];
  794. case 'linux': return [3 /*break*/, 16];
  795. }
  796. return [3 /*break*/, 20];
  797. case 7: return [4 /*yield*/, this.prepareWinBuild(targetDir, appRoot, pkg, config)];
  798. case 8:
  799. _b.sent();
  800. return [4 /*yield*/, this.copyFiles(platform, targetDir, appRoot, pkg, config)];
  801. case 9:
  802. _b.sent();
  803. return [4 /*yield*/, this.renameWinApp(targetDir, appRoot, pkg, config)];
  804. case 10:
  805. _b.sent();
  806. return [3 /*break*/, 21];
  807. case 11: return [4 /*yield*/, this.prepareMacBuild(targetDir, appRoot, pkg, config)];
  808. case 12:
  809. _b.sent();
  810. return [4 /*yield*/, this.copyFiles(platform, targetDir, appRoot, pkg, config)];
  811. case 13:
  812. _b.sent();
  813. // rename Helper before main app rename.
  814. return [4 /*yield*/, this.renameMacHelperApp(targetDir, appRoot, pkg, config)];
  815. case 14:
  816. // rename Helper before main app rename.
  817. _b.sent();
  818. return [4 /*yield*/, this.renameMacApp(targetDir, appRoot, pkg, config)];
  819. case 15:
  820. _b.sent();
  821. return [3 /*break*/, 21];
  822. case 16: return [4 /*yield*/, this.prepareLinuxBuild(targetDir, appRoot, pkg, config)];
  823. case 17:
  824. _b.sent();
  825. return [4 /*yield*/, this.copyFiles(platform, targetDir, appRoot, pkg, config)];
  826. case 18:
  827. _b.sent();
  828. return [4 /*yield*/, this.renameLinuxApp(targetDir, appRoot, pkg, config)];
  829. case 19:
  830. _b.sent();
  831. return [3 /*break*/, 21];
  832. case 20: throw new Error('ERROR_UNKNOWN_PLATFORM');
  833. case 21: return [2 /*return*/, targetDir];
  834. }
  835. });
  836. });
  837. };
  838. Builder.prototype.buildArchiveTarget = function (type, sourceDir) {
  839. return __awaiter(this, void 0, void 0, function () {
  840. var targetArchive, files;
  841. return __generator(this, function (_a) {
  842. switch (_a.label) {
  843. case 0:
  844. targetArchive = path_1.resolve(path_1.dirname(sourceDir), path_1.basename(sourceDir) + "." + type);
  845. return [4 /*yield*/, fs_extra_1.remove(targetArchive)];
  846. case 1:
  847. _a.sent();
  848. return [4 /*yield*/, globby(['**/*'], {
  849. cwd: sourceDir,
  850. })];
  851. case 2:
  852. files = _a.sent();
  853. return [4 /*yield*/, util_1.compress(sourceDir, files, type, targetArchive)];
  854. case 3:
  855. _a.sent();
  856. return [2 /*return*/, targetArchive];
  857. }
  858. });
  859. });
  860. };
  861. Builder.prototype.buildNsisTarget = function (platform, arch, sourceDir, pkg, config) {
  862. return __awaiter(this, void 0, void 0, function () {
  863. var versionInfo, targetNsis, data, script, _i, _a, version;
  864. return __generator(this, function (_b) {
  865. switch (_b.label) {
  866. case 0:
  867. if (platform != 'win') {
  868. if (!this.options.mute) {
  869. console.info("Skip building nsis target for " + platform + ".");
  870. }
  871. return [2 /*return*/];
  872. }
  873. versionInfo = new common_1.NsisVersionInfo(path_1.resolve(this.dir, config.output, 'versions.nsis.json'));
  874. targetNsis = path_1.resolve(path_1.dirname(sourceDir), path_1.basename(sourceDir) + "-Setup.exe");
  875. return [4 /*yield*/, (new nsis_gen_1.NsisComposer({
  876. // Basic.
  877. appName: config.win.productName,
  878. companyName: config.win.companyName,
  879. description: config.win.fileDescription,
  880. version: util_1.fixWindowsVersion(config.win.productVersion),
  881. copyright: config.win.copyright,
  882. icon: config.nsis.icon ? path_1.resolve(this.dir, config.nsis.icon) : undefined,
  883. unIcon: config.nsis.unIcon ? path_1.resolve(this.dir, config.nsis.unIcon) : undefined,
  884. // Compression.
  885. compression: 'lzma',
  886. solid: true,
  887. languages: config.nsis.languages,
  888. installDirectory: config.nsis.installDirectory,
  889. // Output.
  890. output: targetNsis,
  891. })).make()];
  892. case 1:
  893. data = _b.sent();
  894. return [4 /*yield*/, util_1.tmpName()];
  895. case 2:
  896. script = _b.sent();
  897. return [4 /*yield*/, fs_extra_1.writeFile(script, data)];
  898. case 3:
  899. _b.sent();
  900. return [4 /*yield*/, nsis_gen_1.nsisBuild(sourceDir, script, {
  901. mute: this.options.mute,
  902. })];
  903. case 4:
  904. _b.sent();
  905. return [4 /*yield*/, fs_extra_1.remove(script)];
  906. case 5:
  907. _b.sent();
  908. return [4 /*yield*/, versionInfo.addVersion(pkg.version, '', sourceDir)];
  909. case 6:
  910. _b.sent();
  911. return [4 /*yield*/, versionInfo.addInstaller(pkg.version, arch, targetNsis)];
  912. case 7:
  913. _b.sent();
  914. if (!config.nsis.diffUpdaters) return [3 /*break*/, 12];
  915. _i = 0;
  916. return [4 /*yield*/, versionInfo.getVersions()];
  917. case 8:
  918. _a = _b.sent();
  919. _b.label = 9;
  920. case 9:
  921. if (!(_i < _a.length)) return [3 /*break*/, 12];
  922. version = _a[_i];
  923. if (!semver.gt(pkg.version, version)) return [3 /*break*/, 11];
  924. return [4 /*yield*/, this.buildNsisDiffUpdater(platform, arch, versionInfo, version, pkg.version, pkg, config)];
  925. case 10:
  926. _b.sent();
  927. _b.label = 11;
  928. case 11:
  929. _i++;
  930. return [3 /*break*/, 9];
  931. case 12: return [4 /*yield*/, versionInfo.save()];
  932. case 13:
  933. _b.sent();
  934. return [2 /*return*/];
  935. }
  936. });
  937. });
  938. };
  939. Builder.prototype.buildNsis7zTarget = function (platform, arch, sourceDir, pkg, config) {
  940. return __awaiter(this, void 0, void 0, function () {
  941. var sourceArchive, versionInfo, targetNsis, data, script, _i, _a, version;
  942. return __generator(this, function (_b) {
  943. switch (_b.label) {
  944. case 0:
  945. if (platform != 'win') {
  946. if (!this.options.mute) {
  947. console.info("Skip building nsis7z target for " + platform + ".");
  948. }
  949. return [2 /*return*/];
  950. }
  951. return [4 /*yield*/, this.buildArchiveTarget('7z', sourceDir)];
  952. case 1:
  953. sourceArchive = _b.sent();
  954. versionInfo = new common_1.NsisVersionInfo(path_1.resolve(this.dir, config.output, 'versions.nsis.json'));
  955. targetNsis = path_1.resolve(path_1.dirname(sourceDir), path_1.basename(sourceDir) + "-Setup.exe");
  956. return [4 /*yield*/, (new nsis_gen_1.Nsis7Zipper(sourceArchive, {
  957. // Basic.
  958. appName: config.win.productName,
  959. companyName: config.win.companyName,
  960. description: config.win.fileDescription,
  961. version: util_1.fixWindowsVersion(config.win.productVersion),
  962. copyright: config.win.copyright,
  963. icon: config.nsis.icon ? path_1.resolve(this.dir, config.nsis.icon) : undefined,
  964. unIcon: config.nsis.unIcon ? path_1.resolve(this.dir, config.nsis.unIcon) : undefined,
  965. // Compression.
  966. compression: 'lzma',
  967. solid: true,
  968. languages: config.nsis.languages,
  969. installDirectory: config.nsis.installDirectory,
  970. // Output.
  971. output: targetNsis,
  972. })).make()];
  973. case 2:
  974. data = _b.sent();
  975. return [4 /*yield*/, util_1.tmpName()];
  976. case 3:
  977. script = _b.sent();
  978. return [4 /*yield*/, fs_extra_1.writeFile(script, data)];
  979. case 4:
  980. _b.sent();
  981. return [4 /*yield*/, nsis_gen_1.nsisBuild(sourceDir, script, {
  982. mute: this.options.mute,
  983. })];
  984. case 5:
  985. _b.sent();
  986. return [4 /*yield*/, fs_extra_1.remove(script)];
  987. case 6:
  988. _b.sent();
  989. return [4 /*yield*/, versionInfo.addVersion(pkg.version, '', sourceDir)];
  990. case 7:
  991. _b.sent();
  992. return [4 /*yield*/, versionInfo.addInstaller(pkg.version, arch, targetNsis)];
  993. case 8:
  994. _b.sent();
  995. if (!config.nsis.diffUpdaters) return [3 /*break*/, 13];
  996. _i = 0;
  997. return [4 /*yield*/, versionInfo.getVersions()];
  998. case 9:
  999. _a = _b.sent();
  1000. _b.label = 10;
  1001. case 10:
  1002. if (!(_i < _a.length)) return [3 /*break*/, 13];
  1003. version = _a[_i];
  1004. if (!semver.gt(pkg.version, version)) return [3 /*break*/, 12];
  1005. return [4 /*yield*/, this.buildNsisDiffUpdater(platform, arch, versionInfo, version, pkg.version, pkg, config)];
  1006. case 11:
  1007. _b.sent();
  1008. _b.label = 12;
  1009. case 12:
  1010. _i++;
  1011. return [3 /*break*/, 10];
  1012. case 13: return [4 /*yield*/, versionInfo.save()];
  1013. case 14:
  1014. _b.sent();
  1015. return [2 /*return*/];
  1016. }
  1017. });
  1018. });
  1019. };
  1020. Builder.prototype.buildTask = function (platform, arch, pkg, config) {
  1021. return __awaiter(this, void 0, void 0, function () {
  1022. var downloader, runtimeDir, started, targetDir, _i, _a, target, started_1, _b;
  1023. return __generator(this, function (_c) {
  1024. switch (_c.label) {
  1025. case 0:
  1026. if (platform === 'mac' && arch === 'x86' && !config.nwVersion.includes('0.12.3')) {
  1027. if (!this.options.mute) {
  1028. console.info("The NW.js binary for " + platform + ", " + arch + " isn't available for " + config.nwVersion + ", skipped.");
  1029. }
  1030. throw new Error('ERROR_TASK_MAC_X86_SKIPPED');
  1031. }
  1032. downloader = new Downloader_1.Downloader({
  1033. platform: platform, arch: arch,
  1034. version: config.nwVersion,
  1035. flavor: config.nwFlavor,
  1036. mirror: this.options.mirror,
  1037. useCaches: true,
  1038. showProgress: this.options.mute ? false : true,
  1039. forceCaches: this.options.forceCaches,
  1040. destination: this.options.destination,
  1041. });
  1042. if (!this.options.mute) {
  1043. console.info('Fetching NW.js binary...', {
  1044. platform: downloader.options.platform,
  1045. arch: downloader.options.arch,
  1046. version: downloader.options.version,
  1047. flavor: downloader.options.flavor,
  1048. });
  1049. }
  1050. return [4 /*yield*/, downloader.fetchAndExtract()];
  1051. case 1:
  1052. runtimeDir = _c.sent();
  1053. if (!this.options.mute) {
  1054. console.info('Building targets...');
  1055. }
  1056. started = Date.now();
  1057. if (!this.options.mute) {
  1058. console.info("Building directory target starts...");
  1059. }
  1060. return [4 /*yield*/, this.buildDirTarget(platform, arch, runtimeDir, pkg, config)];
  1061. case 2:
  1062. targetDir = _c.sent();
  1063. if (!this.options.mute) {
  1064. console.info("Building directory target ends within " + this.getTimeDiff(started) + "s.");
  1065. }
  1066. _i = 0, _a = config.targets;
  1067. _c.label = 3;
  1068. case 3:
  1069. if (!(_i < _a.length)) return [3 /*break*/, 12];
  1070. target = _a[_i];
  1071. started_1 = Date.now();
  1072. _b = target;
  1073. switch (_b) {
  1074. case 'zip': return [3 /*break*/, 4];
  1075. case '7z': return [3 /*break*/, 4];
  1076. case 'nsis': return [3 /*break*/, 6];
  1077. case 'nsis7z': return [3 /*break*/, 8];
  1078. }
  1079. return [3 /*break*/, 10];
  1080. case 4:
  1081. if (!this.options.mute) {
  1082. console.info("Building " + target + " archive target starts...");
  1083. }
  1084. return [4 /*yield*/, this.buildArchiveTarget(target, targetDir)];
  1085. case 5:
  1086. _c.sent();
  1087. if (!this.options.mute) {
  1088. console.info("Building " + target + " archive target ends within " + this.getTimeDiff(started_1) + "s.");
  1089. }
  1090. return [3 /*break*/, 11];
  1091. case 6:
  1092. if (!this.options.mute) {
  1093. console.info("Building nsis target starts...");
  1094. }
  1095. return [4 /*yield*/, this.buildNsisTarget(platform, arch, targetDir, pkg, config)];
  1096. case 7:
  1097. _c.sent();
  1098. if (!this.options.mute) {
  1099. console.info("Building nsis target ends within " + this.getTimeDiff(started_1) + "s.");
  1100. }
  1101. return [3 /*break*/, 11];
  1102. case 8:
  1103. if (!this.options.mute) {
  1104. console.info("Building nsis7z target starts...");
  1105. }
  1106. return [4 /*yield*/, this.buildNsis7zTarget(platform, arch, targetDir, pkg, config)];
  1107. case 9:
  1108. _c.sent();
  1109. if (!this.options.mute) {
  1110. console.info("Building nsis7z target ends within " + this.getTimeDiff(started_1) + "s.");
  1111. }
  1112. return [3 /*break*/, 11];
  1113. case 10: throw new Error('ERROR_UNKNOWN_TARGET');
  1114. case 11:
  1115. _i++;
  1116. return [3 /*break*/, 3];
  1117. case 12: return [2 /*return*/];
  1118. }
  1119. });
  1120. });
  1121. };
  1122. Builder.DEFAULT_OPTIONS = {
  1123. win: false,
  1124. mac: false,
  1125. linux: false,
  1126. x86: false,
  1127. x64: false,
  1128. tasks: [],
  1129. chromeApp: false,
  1130. mirror: Downloader_1.Downloader.DEFAULT_OPTIONS.mirror,
  1131. concurrent: false,
  1132. mute: true,
  1133. forceCaches: Downloader_1.Downloader.DEFAULT_OPTIONS.forceCaches,
  1134. destination: common_1.DownloaderBase.DEFAULT_DESTINATION,
  1135. };
  1136. return Builder;
  1137. }());
  1138. exports.Builder = Builder;
  1139. //# sourceMappingURL=Builder.js.map