system_assignation/node_modules/electron-winstaller/lib/index.js

281 lines
15 KiB
JavaScript

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
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;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var asar = __importStar(require("asar"));
var temp_utils_1 = require("./temp-utils");
var fs = __importStar(require("fs-extra"));
var path = __importStar(require("path"));
var spawn_promise_1 = __importDefault(require("./spawn-promise"));
var lodash_template_1 = __importDefault(require("lodash.template"));
var log = require('debug')('electron-windows-installer:main');
function convertVersion(version) {
var parts = version.split('-');
var mainVersion = parts.shift();
if (parts.length > 0) {
return [mainVersion, parts.join('-').replace(/\./g, '')].join('-');
}
else {
return mainVersion;
}
}
exports.convertVersion = convertVersion;
function createWindowsInstaller(options) {
return __awaiter(this, void 0, void 0, function () {
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;
return __generator(this, function (_e) {
switch (_e.label) {
case 0:
useMono = false;
monoExe = 'mono';
wineExe = process.arch === 'x64' ? 'wine64' : 'wine';
if (process.platform !== 'win32') {
useMono = true;
if (!wineExe || !monoExe) {
throw new Error('You must install both Mono and Wine on non-Windows');
}
log("Using Mono: '" + monoExe + "'");
log("Using Wine: '" + wineExe + "'");
}
appDirectory = options.appDirectory, outputDirectory = options.outputDirectory, loadingGif = options.loadingGif;
outputDirectory = path.resolve(outputDirectory || 'installer');
vendorPath = path.join(__dirname, '..', 'vendor');
vendorUpdate = path.join(vendorPath, 'Squirrel.exe');
appUpdate = path.join(appDirectory, 'Squirrel.exe');
return [4 /*yield*/, fs.copy(vendorUpdate, appUpdate)];
case 1:
_e.sent();
if (!(options.setupIcon && (options.skipUpdateIcon !== true))) return [3 /*break*/, 3];
cmd_1 = path.join(vendorPath, 'rcedit.exe');
args_1 = [
appUpdate,
'--set-icon', options.setupIcon
];
if (useMono) {
args_1.unshift(cmd_1);
cmd_1 = wineExe;
}
return [4 /*yield*/, spawn_promise_1.default(cmd_1, args_1)];
case 2:
_e.sent();
_e.label = 3;
case 3:
defaultLoadingGif = path.join(__dirname, '..', 'resources', 'install-spinner.gif');
loadingGif = loadingGif ? path.resolve(loadingGif) : defaultLoadingGif;
certificateFile = options.certificateFile, certificatePassword = options.certificatePassword, remoteReleases = options.remoteReleases, signWithParams = options.signWithParams, remoteToken = options.remoteToken;
metadata = {
description: '',
iconUrl: 'https://raw.githubusercontent.com/electron/electron/master/shell/browser/resources/win/electron.ico'
};
if (!(options.usePackageJson !== false)) return [3 /*break*/, 8];
appResources = path.join(appDirectory, 'resources');
asarFile = path.join(appResources, 'app.asar');
appMetadata = void 0;
return [4 /*yield*/, fs.pathExists(asarFile)];
case 4:
if (!_e.sent()) return [3 /*break*/, 5];
appMetadata = JSON.parse(asar.extractFile(asarFile, 'package.json'));
return [3 /*break*/, 7];
case 5: return [4 /*yield*/, fs.readJson(path.join(appResources, 'app', 'package.json'))];
case 6:
appMetadata = _e.sent();
_e.label = 7;
case 7:
Object.assign(metadata, {
exe: appMetadata.name + ".exe",
title: appMetadata.productName || appMetadata.name
}, appMetadata);
_e.label = 8;
case 8:
Object.assign(metadata, options);
if (!metadata.authors) {
if (typeof (metadata.author) === 'string') {
metadata.authors = metadata.author;
}
else {
// eslint-disable-next-line @typescript-eslint/no-object-literal-type-assertion
metadata.authors = (metadata.author || {}).name || '';
}
}
metadata.owners = metadata.owners || metadata.authors;
metadata.version = convertVersion(metadata.version);
metadata.copyright = metadata.copyright ||
"Copyright \u00A9 " + new Date().getFullYear() + " " + (metadata.authors || metadata.owners);
metadata.additionalFiles = metadata.additionalFiles || [];
return [4 /*yield*/, fs.pathExists(path.join(appDirectory, 'swiftshader'))];
case 9:
if (_e.sent()) {
metadata.additionalFiles.push({ src: 'swiftshader\\**', target: 'lib\\net45\\swiftshader' });
}
return [4 /*yield*/, fs.pathExists(path.join(appDirectory, 'vk_swiftshader_icd.json'))];
case 10:
if (_e.sent()) {
metadata.additionalFiles.push({ src: 'vk_swiftshader_icd.json', target: 'lib\\net45' });
}
return [4 /*yield*/, fs.readFile(path.join(__dirname, '..', 'template.nuspectemplate'), 'utf8')];
case 11:
templateData = _e.sent();
if (path.sep === '/') {
templateData = templateData.replace(/\\/g, '/');
for (_i = 0, _a = metadata.additionalFiles; _i < _a.length; _i++) {
f = _a[_i];
f.src = f.src.replace(/\\/g, '/');
f.target = f.target.replace(/\\/g, '/');
}
}
nuspecContent = lodash_template_1.default(templateData)(metadata);
log("Created NuSpec file:\n" + nuspecContent);
return [4 /*yield*/, temp_utils_1.createTempDir('si-')];
case 12:
nugetOutput = _e.sent();
targetNuspecPath = path.join(nugetOutput, metadata.name + '.nuspec');
return [4 /*yield*/, fs.writeFile(targetNuspecPath, nuspecContent)];
case 13:
_e.sent();
cmd = path.join(vendorPath, 'nuget.exe');
args = [
'pack', targetNuspecPath,
'-BasePath', appDirectory,
'-OutputDirectory', nugetOutput,
'-NoDefaultExcludes'
];
if (useMono) {
args.unshift(cmd);
cmd = monoExe;
}
// Call NuGet to create our package
_b = log;
return [4 /*yield*/, spawn_promise_1.default(cmd, args)];
case 14:
// Call NuGet to create our package
_b.apply(void 0, [_e.sent()]);
nupkgPath = path.join(nugetOutput, metadata.name + "." + metadata.version + ".nupkg");
if (!remoteReleases) return [3 /*break*/, 16];
cmd = path.join(vendorPath, 'SyncReleases.exe');
args = ['-u', remoteReleases, '-r', outputDirectory];
if (useMono) {
args.unshift(cmd);
cmd = monoExe;
}
if (remoteToken) {
args.push('-t', remoteToken);
}
_c = log;
return [4 /*yield*/, spawn_promise_1.default(cmd, args)];
case 15:
_c.apply(void 0, [_e.sent()]);
_e.label = 16;
case 16:
cmd = path.join(vendorPath, 'Squirrel.exe');
args = [
'--releasify', nupkgPath,
'--releaseDir', outputDirectory,
'--loadingGif', loadingGif
];
if (useMono) {
args.unshift(path.join(vendorPath, 'Squirrel-Mono.exe'));
cmd = monoExe;
}
if (signWithParams) {
args.push('--signWithParams');
if (!signWithParams.includes('/f') && !signWithParams.includes('/p') && certificateFile && certificatePassword) {
args.push(signWithParams + " /a /f \"" + path.resolve(certificateFile) + "\" /p \"" + certificatePassword + "\"");
}
else {
args.push(signWithParams);
}
}
else if (certificateFile && certificatePassword) {
args.push('--signWithParams');
args.push("/a /f \"" + path.resolve(certificateFile) + "\" /p \"" + certificatePassword + "\"");
}
if (options.setupIcon) {
args.push('--setupIcon');
args.push(path.resolve(options.setupIcon));
}
if (options.noMsi) {
args.push('--no-msi');
}
if (options.noDelta) {
args.push('--no-delta');
}
if (options.frameworkVersion) {
args.push('--framework-version');
args.push(options.frameworkVersion);
}
_d = log;
return [4 /*yield*/, spawn_promise_1.default(cmd, args)];
case 17:
_d.apply(void 0, [_e.sent()]);
if (!(options.fixUpPaths !== false)) return [3 /*break*/, 22];
log('Fixing up paths');
if (!(metadata.productName || options.setupExe)) return [3 /*break*/, 19];
setupPath = path.join(outputDirectory, options.setupExe || metadata.productName + "Setup.exe");
unfixedSetupPath = path.join(outputDirectory, 'Setup.exe');
log("Renaming " + unfixedSetupPath + " => " + setupPath);
return [4 /*yield*/, fs.rename(unfixedSetupPath, setupPath)];
case 18:
_e.sent();
_e.label = 19;
case 19:
if (!(metadata.productName || options.setupMsi)) return [3 /*break*/, 22];
msiPath = path.join(outputDirectory, options.setupMsi || metadata.productName + "Setup.msi");
unfixedMsiPath = path.join(outputDirectory, 'Setup.msi');
return [4 /*yield*/, fs.pathExists(unfixedMsiPath)];
case 20:
if (!_e.sent()) return [3 /*break*/, 22];
log("Renaming " + unfixedMsiPath + " => " + msiPath);
return [4 /*yield*/, fs.rename(unfixedMsiPath, msiPath)];
case 21:
_e.sent();
_e.label = 22;
case 22: return [2 /*return*/];
}
});
});
}
exports.createWindowsInstaller = createWindowsInstaller;
//# sourceMappingURL=index.js.map