electron-version-deployer-cli 0.0.16 → 0.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.cjs +1 -1
- package/dist/main.js +18 -15
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -507,4 +507,4 @@ async function installPrebuilt(configs) {
|
|
|
507
507
|
}
|
|
508
508
|
commander.program.description(
|
|
509
509
|
"Electron 版本部署 CLI,简化你的 Electron 软件更新,让一切变得简单。"
|
|
510
|
-
).helpOption("-h, --help", "使用帮助").version("0.0.
|
|
510
|
+
).helpOption("-h, --help", "使用帮助").version("0.0.18", "-V, --version", "显示版本号").parse(process.argv);
|
package/dist/main.js
CHANGED
|
@@ -6,7 +6,6 @@ const node_path = require("node:path");
|
|
|
6
6
|
const node_https = require("node:https");
|
|
7
7
|
const node_fs = require("node:fs");
|
|
8
8
|
const extract = require("extract-zip");
|
|
9
|
-
const node_child_process = require("node:child_process");
|
|
10
9
|
const node_process = require("node:process");
|
|
11
10
|
function fetchRemoteChangelogJSON(remote_url) {
|
|
12
11
|
return new Promise((res, rej) => {
|
|
@@ -70,7 +69,7 @@ function compareObjectsIsEqual(obj1, obj2) {
|
|
|
70
69
|
return true;
|
|
71
70
|
}
|
|
72
71
|
const CLI_NAME = "electron-version-deployer-cli";
|
|
73
|
-
const installerCodeStr = '// 该文件用于 fork 使用,将会写入到\n// app.getAppPath() + \'/_evdInstallerTmp.js\' 路径中\n// 从避免 window 上替换时出现的资源占用问题\nconst {\n existsSync,\n mkdirSync,\n readdirSync,\n statSync,\n appendFileSync,\n writeFileSync,\n readFileSync,\n} = require("fs");\nconst { join, resolve, basename } = require("node:path");\n\
|
|
72
|
+
const installerCodeStr = '// 该文件用于 fork 使用,将会写入到\n// app.getAppPath() + \'/_evdInstallerTmp.js\' 路径中\n// 从避免 window 上替换时出现的资源占用问题\nconst {\n existsSync,\n mkdirSync,\n readdirSync,\n statSync,\n appendFileSync,\n writeFileSync,\n readFileSync,\n} = require("fs");\nconst { join, resolve, basename } = require("node:path");\n\ntry {\n copyFolderRecursiveSync("__unzipPath__", "__appPath__");\n process.parentPort.postMessage("exitManually");\n process.exit(0);\n} catch (error) {\n appendFileSync(\n resolve(__dirname, "evdInstallerErrors.txt"),\n `\n ${new Date().toString()}\\n\n ${error.toString()}\\n\n -- stack\\n\n ${error.stack}\\n\n ----------------------------------------------------------------\\n\n `\n );\n process.parentPort.postMessage("exitManually");\n process.exit(0);\n}\n\n// 复制文件夹及其内容的函数\nfunction copyFolderRecursiveSync(source, target) {\n // 如果目标目录不存在,则创建目标目录\n if (!existsSync(target)) {\n mkdirSync(target);\n }\n\n // 获取源目录的文件列表\n const files = readdirSync(source);\n\n // 遍历文件列表,处理每个文件或子目录\n files.forEach((file) => {\n const sourcePath = join(source, file);\n const targetPath = join(target, file);\n\n // 如果当前文件是文件夹,则递归复制文件夹\n if (statSync(sourcePath).isDirectory()) {\n copyFolderRecursiveSync(sourcePath, targetPath);\n } else {\n // 否则,复制文件\n try {\n copyFileSync(sourcePath, targetPath);\n } catch (error) {\n appendFileSync(\n resolve(__dirname, "evdInstallerErrors.txt"),\n `\n ${new Date().toString()}\\n\n ${error.toString()}\\n\n -- stack\\n\n ${error.stack}\\n\n ----------------------------------------------------------------\\n\n `\n );\n }\n }\n });\n}\n\nfunction copyFileSync(source, target) {\n let targetFile = target;\n\n if (existsSync(target)) {\n if (statSync(target).isDirectory()) {\n targetFile = join(target, basename(source));\n }\n }\n\n writeFileSync(targetFile, readFileSync(source));\n}\n';
|
|
74
73
|
const id = `${Date.now()}-${Math.random()}`;
|
|
75
74
|
var EVDEventEnum = /* @__PURE__ */ ((EVDEventEnum2) => {
|
|
76
75
|
EVDEventEnum2["OPEN_LINK"] = "evd-open-link";
|
|
@@ -178,7 +177,7 @@ async function showNewVersionDialog() {
|
|
|
178
177
|
promptWindow.once("close", () => {
|
|
179
178
|
cleanup(promptWindow);
|
|
180
179
|
});
|
|
181
|
-
bindEvent(promptWindow);
|
|
180
|
+
bindEvent(promptWindow, onError);
|
|
182
181
|
} catch (e) {
|
|
183
182
|
onError(e);
|
|
184
183
|
}
|
|
@@ -235,18 +234,22 @@ async function installPkg(zipFile) {
|
|
|
235
234
|
}, installerCodeStr)
|
|
236
235
|
);
|
|
237
236
|
await new Promise((res) => setTimeout(res, 1e3));
|
|
238
|
-
const child =
|
|
239
|
-
cwd: appPath,
|
|
240
|
-
stdio: "inherit"
|
|
241
|
-
});
|
|
237
|
+
const child = electron.utilityProcess.fork(node_path.join(appPath, "_evdInstallerTmp.js"));
|
|
242
238
|
await Promise.race([
|
|
243
239
|
new Promise((res) => {
|
|
244
240
|
child.on("exit", () => res);
|
|
245
241
|
}),
|
|
246
|
-
new Promise((res) =>
|
|
242
|
+
new Promise((res) => {
|
|
243
|
+
child.on("message", (msg) => {
|
|
244
|
+
if (msg === "exitManually") {
|
|
245
|
+
res(void 0);
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
}),
|
|
249
|
+
new Promise((res) => setTimeout(res, 5 * 60 * 1e3))
|
|
247
250
|
]);
|
|
248
251
|
}
|
|
249
|
-
function bindEvent(promptWindow) {
|
|
252
|
+
function bindEvent(promptWindow, onError) {
|
|
250
253
|
const { logo, onBeforeNewPkgInstall } = getConfigs();
|
|
251
254
|
electron.ipcMain.on("evd-open-link", (_, link) => {
|
|
252
255
|
electron.shell.openExternal(link);
|
|
@@ -257,9 +260,11 @@ function bindEvent(promptWindow) {
|
|
|
257
260
|
electron.ipcMain.on("evd-update-now", (_) => {
|
|
258
261
|
onBeforeNewPkgInstall(() => {
|
|
259
262
|
installNewVersion().then(() => {
|
|
260
|
-
promptWindow.close();
|
|
261
|
-
electron.app.relaunch();
|
|
262
|
-
electron.app.exit();
|
|
263
|
+
setTimeout(() => promptWindow.close(), 1);
|
|
264
|
+
setTimeout(() => electron.app.relaunch(), 1);
|
|
265
|
+
setTimeout(() => electron.app.exit(), 1);
|
|
266
|
+
}).catch((e) => {
|
|
267
|
+
onError(e);
|
|
263
268
|
});
|
|
264
269
|
});
|
|
265
270
|
});
|
|
@@ -294,9 +299,7 @@ function cleanup(promptWindow) {
|
|
|
294
299
|
);
|
|
295
300
|
try {
|
|
296
301
|
promptWindow == null ? void 0 : promptWindow.focus();
|
|
297
|
-
|
|
298
|
-
promptWindow.destroy();
|
|
299
|
-
}
|
|
302
|
+
promptWindow == null ? void 0 : promptWindow.destroy();
|
|
300
303
|
} catch (e) {
|
|
301
304
|
}
|
|
302
305
|
}
|