UNPKG

15.6 kBJavaScriptView Raw
1"use strict";
2var __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};
10var __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 = 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;
18 if (y = 0, t) op = [op[0] & 2, 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};
37var __importStar = (this && this.__importStar) || function (mod) {
38 if (mod && mod.__esModule) return mod;
39 var result = {};
40 if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
41 result["default"] = mod;
42 return result;
43};
44var __importDefault = (this && this.__importDefault) || function (mod) {
45 return (mod && mod.__esModule) ? mod : { "default": mod };
46};
47Object.defineProperty(exports, "__esModule", { value: true });
48var asar = __importStar(require("asar"));
49var temp_utils_1 = require("./temp-utils");
50var fs = __importStar(require("fs-extra"));
51var path = __importStar(require("path"));
52var spawn_promise_1 = __importDefault(require("./spawn-promise"));
53var lodash_template_1 = __importDefault(require("lodash.template"));
54var log = require('debug')('electron-windows-installer:main');
55function convertVersion(version) {
56 var parts = version.split('-');
57 var mainVersion = parts.shift();
58 if (parts.length > 0) {
59 return [mainVersion, parts.join('-').replace(/\./g, '')].join('-');
60 }
61 else {
62 return mainVersion;
63 }
64}
65exports.convertVersion = convertVersion;
66function createWindowsInstaller(options) {
67 return __awaiter(this, void 0, void 0, function () {
68 var useMono, monoExe, wineExe, appDirectory, outputDirectory, loadingGif, vendorPath, vendorUpdate, appUpdate, cmd_1, args_1, defaultLoadingGif, certificateFile, certificatePassword, remoteReleases, signWithParams, remoteToken, metadata, appResources, asarFile, appMetadata, templateData, _i, _a, f, nuspecContent, nugetOutput, targetNuspecPath, cmd, args, _b, nupkgPath, _c, _d, setupPath, unfixedSetupPath, msiPath, unfixedMsiPath;
69 return __generator(this, function (_e) {
70 switch (_e.label) {
71 case 0:
72 useMono = false;
73 monoExe = 'mono';
74 wineExe = process.arch === 'x64' ? 'wine64' : 'wine';
75 if (process.platform !== 'win32') {
76 useMono = true;
77 if (!wineExe || !monoExe) {
78 throw new Error('You must install both Mono and Wine on non-Windows');
79 }
80 log("Using Mono: '" + monoExe + "'");
81 log("Using Wine: '" + wineExe + "'");
82 }
83 appDirectory = options.appDirectory, outputDirectory = options.outputDirectory, loadingGif = options.loadingGif;
84 outputDirectory = path.resolve(outputDirectory || 'installer');
85 vendorPath = path.join(__dirname, '..', 'vendor');
86 vendorUpdate = path.join(vendorPath, 'Squirrel.exe');
87 appUpdate = path.join(appDirectory, 'Squirrel.exe');
88 return [4 /*yield*/, fs.copy(vendorUpdate, appUpdate)];
89 case 1:
90 _e.sent();
91 if (!(options.setupIcon && (options.skipUpdateIcon !== true))) return [3 /*break*/, 3];
92 cmd_1 = path.join(vendorPath, 'rcedit.exe');
93 args_1 = [
94 appUpdate,
95 '--set-icon', options.setupIcon
96 ];
97 if (useMono) {
98 args_1.unshift(cmd_1);
99 cmd_1 = wineExe;
100 }
101 return [4 /*yield*/, spawn_promise_1.default(cmd_1, args_1)];
102 case 2:
103 _e.sent();
104 _e.label = 3;
105 case 3:
106 defaultLoadingGif = path.join(__dirname, '..', 'resources', 'install-spinner.gif');
107 loadingGif = loadingGif ? path.resolve(loadingGif) : defaultLoadingGif;
108 certificateFile = options.certificateFile, certificatePassword = options.certificatePassword, remoteReleases = options.remoteReleases, signWithParams = options.signWithParams, remoteToken = options.remoteToken;
109 metadata = {
110 description: '',
111 iconUrl: 'https://raw.githubusercontent.com/electron/electron/master/shell/browser/resources/win/electron.ico'
112 };
113 if (!(options.usePackageJson !== false)) return [3 /*break*/, 8];
114 appResources = path.join(appDirectory, 'resources');
115 asarFile = path.join(appResources, 'app.asar');
116 appMetadata = void 0;
117 return [4 /*yield*/, fs.pathExists(asarFile)];
118 case 4:
119 if (!_e.sent()) return [3 /*break*/, 5];
120 appMetadata = JSON.parse(asar.extractFile(asarFile, 'package.json'));
121 return [3 /*break*/, 7];
122 case 5: return [4 /*yield*/, fs.readJson(path.join(appResources, 'app', 'package.json'))];
123 case 6:
124 appMetadata = _e.sent();
125 _e.label = 7;
126 case 7:
127 Object.assign(metadata, {
128 exe: appMetadata.name + ".exe",
129 title: appMetadata.productName || appMetadata.name
130 }, appMetadata);
131 _e.label = 8;
132 case 8:
133 Object.assign(metadata, options);
134 if (!metadata.authors) {
135 if (typeof (metadata.author) === 'string') {
136 metadata.authors = metadata.author;
137 }
138 else {
139 // eslint-disable-next-line @typescript-eslint/no-object-literal-type-assertion
140 metadata.authors = (metadata.author || {}).name || '';
141 }
142 }
143 metadata.owners = metadata.owners || metadata.authors;
144 metadata.version = convertVersion(metadata.version);
145 metadata.copyright = metadata.copyright ||
146 "Copyright \u00A9 " + new Date().getFullYear() + " " + (metadata.authors || metadata.owners);
147 metadata.additionalFiles = metadata.additionalFiles || [];
148 return [4 /*yield*/, fs.pathExists(path.join(appDirectory, 'swiftshader'))];
149 case 9:
150 if (_e.sent()) {
151 metadata.additionalFiles.push({ src: 'swiftshader\\**', target: 'lib\\net45\\swiftshader' });
152 }
153 return [4 /*yield*/, fs.pathExists(path.join(appDirectory, 'vk_swiftshader_icd.json'))];
154 case 10:
155 if (_e.sent()) {
156 metadata.additionalFiles.push({ src: 'vk_swiftshader_icd.json', target: 'lib\\net45' });
157 }
158 return [4 /*yield*/, fs.readFile(path.join(__dirname, '..', 'template.nuspectemplate'), 'utf8')];
159 case 11:
160 templateData = _e.sent();
161 if (path.sep === '/') {
162 templateData = templateData.replace(/\\/g, '/');
163 for (_i = 0, _a = metadata.additionalFiles; _i < _a.length; _i++) {
164 f = _a[_i];
165 f.src = f.src.replace(/\\/g, '/');
166 f.target = f.target.replace(/\\/g, '/');
167 }
168 }
169 nuspecContent = lodash_template_1.default(templateData)(metadata);
170 log("Created NuSpec file:\n" + nuspecContent);
171 return [4 /*yield*/, temp_utils_1.createTempDir('si-')];
172 case 12:
173 nugetOutput = _e.sent();
174 targetNuspecPath = path.join(nugetOutput, metadata.name + '.nuspec');
175 return [4 /*yield*/, fs.writeFile(targetNuspecPath, nuspecContent)];
176 case 13:
177 _e.sent();
178 cmd = path.join(vendorPath, 'nuget.exe');
179 args = [
180 'pack', targetNuspecPath,
181 '-BasePath', appDirectory,
182 '-OutputDirectory', nugetOutput,
183 '-NoDefaultExcludes'
184 ];
185 if (useMono) {
186 args.unshift(cmd);
187 cmd = monoExe;
188 }
189 // Call NuGet to create our package
190 _b = log;
191 return [4 /*yield*/, spawn_promise_1.default(cmd, args)];
192 case 14:
193 // Call NuGet to create our package
194 _b.apply(void 0, [_e.sent()]);
195 nupkgPath = path.join(nugetOutput, metadata.name + "." + metadata.version + ".nupkg");
196 if (!remoteReleases) return [3 /*break*/, 16];
197 cmd = path.join(vendorPath, 'SyncReleases.exe');
198 args = ['-u', remoteReleases, '-r', outputDirectory];
199 if (useMono) {
200 args.unshift(cmd);
201 cmd = monoExe;
202 }
203 if (remoteToken) {
204 args.push('-t', remoteToken);
205 }
206 _c = log;
207 return [4 /*yield*/, spawn_promise_1.default(cmd, args)];
208 case 15:
209 _c.apply(void 0, [_e.sent()]);
210 _e.label = 16;
211 case 16:
212 cmd = path.join(vendorPath, 'Squirrel.exe');
213 args = [
214 '--releasify', nupkgPath,
215 '--releaseDir', outputDirectory,
216 '--loadingGif', loadingGif
217 ];
218 if (useMono) {
219 args.unshift(path.join(vendorPath, 'Squirrel-Mono.exe'));
220 cmd = monoExe;
221 }
222 if (signWithParams) {
223 args.push('--signWithParams');
224 if (!signWithParams.includes('/f') && !signWithParams.includes('/p') && certificateFile && certificatePassword) {
225 args.push(signWithParams + " /a /f \"" + path.resolve(certificateFile) + "\" /p \"" + certificatePassword + "\"");
226 }
227 else {
228 args.push(signWithParams);
229 }
230 }
231 else if (certificateFile && certificatePassword) {
232 args.push('--signWithParams');
233 args.push("/a /f \"" + path.resolve(certificateFile) + "\" /p \"" + certificatePassword + "\"");
234 }
235 if (options.setupIcon) {
236 args.push('--setupIcon');
237 args.push(path.resolve(options.setupIcon));
238 }
239 if (options.noMsi) {
240 args.push('--no-msi');
241 }
242 if (options.noDelta) {
243 args.push('--no-delta');
244 }
245 if (options.frameworkVersion) {
246 args.push('--framework-version');
247 args.push(options.frameworkVersion);
248 }
249 _d = log;
250 return [4 /*yield*/, spawn_promise_1.default(cmd, args)];
251 case 17:
252 _d.apply(void 0, [_e.sent()]);
253 if (!(options.fixUpPaths !== false)) return [3 /*break*/, 22];
254 log('Fixing up paths');
255 if (!(metadata.productName || options.setupExe)) return [3 /*break*/, 19];
256 setupPath = path.join(outputDirectory, options.setupExe || metadata.productName + "Setup.exe");
257 unfixedSetupPath = path.join(outputDirectory, 'Setup.exe');
258 log("Renaming " + unfixedSetupPath + " => " + setupPath);
259 return [4 /*yield*/, fs.rename(unfixedSetupPath, setupPath)];
260 case 18:
261 _e.sent();
262 _e.label = 19;
263 case 19:
264 if (!(metadata.productName || options.setupMsi)) return [3 /*break*/, 22];
265 msiPath = path.join(outputDirectory, options.setupMsi || metadata.productName + "Setup.msi");
266 unfixedMsiPath = path.join(outputDirectory, 'Setup.msi');
267 return [4 /*yield*/, fs.pathExists(unfixedMsiPath)];
268 case 20:
269 if (!_e.sent()) return [3 /*break*/, 22];
270 log("Renaming " + unfixedMsiPath + " => " + msiPath);
271 return [4 /*yield*/, fs.rename(unfixedMsiPath, msiPath)];
272 case 21:
273 _e.sent();
274 _e.label = 22;
275 case 22: return [2 /*return*/];
276 }
277 });
278 });
279}
280exports.createWindowsInstaller = createWindowsInstaller;
281//# sourceMappingURL=index.js.map
\No newline at end of file