1 | "use strict";
|
2 | const codeSign_1 = require("./codeSign");
|
3 | const bluebird_1 = require("bluebird");
|
4 | const awaiter_1 = require("./awaiter");
|
5 | const platformPackager_1 = require("./platformPackager");
|
6 | const path = require("path");
|
7 | const util_1 = require("./util");
|
8 | const promisifed_fs_1 = require("./promisifed-fs");
|
9 | const fse = require("fs-extra");
|
10 | const __awaiter = awaiter_1.tsAwaiter;
|
11 | Array.isArray(__awaiter);
|
12 | const emptyDir = bluebird_1.Promise.promisify(fse.emptyDir);
|
13 | class WinPackager extends platformPackager_1.PlatformPackager {
|
14 | constructor(info, cleanupTasks) {
|
15 | super(info);
|
16 | this.isNsis = this.options.target != null && this.options.target.includes("nsis");
|
17 | if (this.isNsis) {
|
18 | const iconPath = this.customDistOptions == null ? null : this.customDistOptions.icon;
|
19 | require("../lib/win").copyAssetsToTmpFolder(iconPath || path.join(this.projectDir, "build", "icon.ico"));
|
20 | }
|
21 | if (this.options.cscLink != null && this.options.cscKeyPassword != null && process.platform !== "darwin") {
|
22 | this.certFilePromise = codeSign_1.downloadCertificate(this.options.cscLink)
|
23 | .then(path => {
|
24 | cleanupTasks.push(() => promisifed_fs_1.deleteFile(path, true));
|
25 | return path;
|
26 | });
|
27 | }
|
28 | else {
|
29 | this.certFilePromise = bluebird_1.Promise.resolve(null);
|
30 | }
|
31 | }
|
32 | getBuildConfigurationKey() {
|
33 | return "win";
|
34 | }
|
35 | pack(platform, arch, outDir) {
|
36 | if (this.options.dist && !this.isNsis) {
|
37 | const installerOut = outDir + "-installer";
|
38 | util_1.log("Removing %s", installerOut);
|
39 | return bluebird_1.Promise.all([
|
40 | super.pack(platform, arch, outDir),
|
41 | emptyDir(installerOut)
|
42 | ]);
|
43 | }
|
44 | else {
|
45 | return super.pack(platform, arch, outDir);
|
46 | }
|
47 | }
|
48 | packageInDistributableFormat(outDir, arch) {
|
49 | return __awaiter(this, void 0, void 0, function* () {
|
50 | let iconUrl = this.metadata.build.iconUrl;
|
51 | if (!iconUrl) {
|
52 | if (this.customDistOptions != null) {
|
53 | iconUrl = this.customDistOptions.iconUrl;
|
54 | }
|
55 | if (!iconUrl) {
|
56 | if (this.info.repositoryInfo != null) {
|
57 | const info = yield this.info.repositoryInfo.getInfo(this);
|
58 | if (info != null) {
|
59 | iconUrl = `https://raw.githubusercontent.com/${info.user}/${info.project}/master/build/icon.ico`;
|
60 | }
|
61 | }
|
62 | if (!iconUrl) {
|
63 | throw new Error("iconUrl is not specified, please see https://github.com/develar/electron-complete-builder#in-short");
|
64 | }
|
65 | }
|
66 | }
|
67 | const certificateFile = yield this.certFilePromise;
|
68 | const version = this.metadata.version;
|
69 | const outputDirectory = outDir + "-" + (this.isNsis ? "nsis" : "installer");
|
70 | const appName = this.metadata.name;
|
71 | const archSuffix = arch === "x64" ? "-x64" : "";
|
72 | const installerExePath = path.join(outputDirectory, appName + "Setup-" + version + archSuffix + ".exe");
|
73 | const options = Object.assign({
|
74 | name: this.metadata.name,
|
75 | appDirectory: outDir,
|
76 | outputDirectory: outputDirectory,
|
77 | productName: appName,
|
78 | version: version,
|
79 | description: this.metadata.description,
|
80 | authors: this.metadata.author,
|
81 | iconUrl: iconUrl,
|
82 | setupIcon: path.join(this.projectDir, "build", "icon.ico"),
|
83 | certificateFile: certificateFile,
|
84 | certificatePassword: this.options.cscKeyPassword,
|
85 | }, this.customDistOptions);
|
86 | if (this.isNsis) {
|
87 | return yield this.nsis(options, installerExePath);
|
88 | }
|
89 | try {
|
90 | yield new bluebird_1.Promise((resolve, reject) => {
|
91 | require("electron-winstaller-temp-fork").build(options, (error) => error == null ? resolve(null) : reject(error));
|
92 | });
|
93 | }
|
94 | catch (e) {
|
95 | if (!e.message.includes("Unable to set icon")) {
|
96 | throw e;
|
97 | }
|
98 | else {
|
99 | let fileInfo;
|
100 | try {
|
101 | fileInfo = yield promisifed_fs_1.stat(options.setupIcon);
|
102 | }
|
103 | catch (e) {
|
104 | throw new Error("Please specify correct setupIcon, file " + options.setupIcon + " not found");
|
105 | }
|
106 | if (fileInfo.isDirectory()) {
|
107 | throw new Error("Please specify correct setupIcon, " + options.setupIcon + " is a directory");
|
108 | }
|
109 | }
|
110 | }
|
111 | return yield bluebird_1.Promise.all([
|
112 | promisifed_fs_1.renameFile(path.join(outputDirectory, appName + "Setup.exe"), installerExePath)
|
113 | .then(it => this.dispatchArtifactCreated(it)),
|
114 | promisifed_fs_1.renameFile(path.join(outputDirectory, appName + "-" + version + "-full.nupkg"), path.join(outputDirectory, appName + "-" + version + archSuffix + "-full.nupkg"))
|
115 | .then(it => this.dispatchArtifactCreated(it))
|
116 | ]);
|
117 | });
|
118 | }
|
119 | nsis(options, installerFile) {
|
120 | return __awaiter(this, void 0, void 0, function* () {
|
121 | const nsisBuild = require("../lib/win").init().build;
|
122 | yield emptyDir(options.outputDirectory);
|
123 | return yield bluebird_1.Promise.promisify(nsisBuild)(Object.assign(options, {
|
124 | log: console.log,
|
125 | appPath: options.appDirectory,
|
126 | out: options.outputDirectory,
|
127 | platform: "win32",
|
128 | outFile: installerFile,
|
129 | copyAssetsToTmpFolder: false,
|
130 | config: {
|
131 | win: Object.assign({
|
132 | title: options.name,
|
133 | version: options.version,
|
134 | icon: options.setupIcon,
|
135 | publisher: options.authors
|
136 | }, this.customDistOptions)
|
137 | }
|
138 | }));
|
139 | });
|
140 | }
|
141 | }
|
142 | Object.defineProperty(exports, "__esModule", { value: true });
|
143 | exports.default = WinPackager;
|
144 |
|
\ | No newline at end of file |