electron-version-deployer-cli 0.0.10 → 0.0.12
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/installer.d.ts +1 -0
- package/dist/main.js +23 -25
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -495,4 +495,4 @@ async function installPrebuilt(configs) {
|
|
|
495
495
|
}
|
|
496
496
|
commander.program.description(
|
|
497
497
|
"Electron 版本部署 CLI,简化你的 Electron 软件更新,让一切变得简单。"
|
|
498
|
-
).helpOption("-h, --help", "使用帮助").version("0.0.
|
|
498
|
+
).helpOption("-h, --help", "使用帮助").version("0.0.12", "-V, --version", "显示版本号").parse(process.argv);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/main.js
CHANGED
|
@@ -6,6 +6,7 @@ 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");
|
|
9
10
|
function fetchRemoteChangelogJSON(remote_url) {
|
|
10
11
|
return new Promise((res, rej) => {
|
|
11
12
|
node_https.get(`${remote_url}/changelog.json`, (_res) => {
|
|
@@ -68,6 +69,7 @@ function compareObjectsIsEqual(obj1, obj2) {
|
|
|
68
69
|
return true;
|
|
69
70
|
}
|
|
70
71
|
const CLI_NAME = "electron-version-deployer-cli";
|
|
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\nsetTimeout(() => {\n try {\n copyFolderRecursiveSync("__unzipPath__", "__appPath__");\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}, 1);\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';
|
|
71
73
|
const id = `${Date.now()}-${Math.random()}`;
|
|
72
74
|
var EVDEventEnum = /* @__PURE__ */ ((EVDEventEnum2) => {
|
|
73
75
|
EVDEventEnum2["OPEN_LINK"] = "evd-open-link";
|
|
@@ -187,6 +189,7 @@ async function installPkg(zipFile) {
|
|
|
187
189
|
const { netlifyUrl } = getConfigs();
|
|
188
190
|
const appPath = electron.app.getAppPath();
|
|
189
191
|
const unzipPath = node_path.join(appPath, "evdUnzip");
|
|
192
|
+
const installerFile = node_path.join(appPath, "_evdInstallerTmp.js");
|
|
190
193
|
if (node_fs.existsSync(unzipPath)) {
|
|
191
194
|
node_fs.rmSync(unzipPath, {
|
|
192
195
|
force: true,
|
|
@@ -209,8 +212,27 @@ async function installPkg(zipFile) {
|
|
|
209
212
|
);
|
|
210
213
|
await extract(unzipPath + ".zip", { dir: unzipPath });
|
|
211
214
|
await new Promise((res) => setTimeout(res, 1e3));
|
|
212
|
-
|
|
215
|
+
node_fs.writeFileSync(
|
|
216
|
+
installerFile,
|
|
217
|
+
Object.entries({
|
|
218
|
+
__unzipPath__: unzipPath,
|
|
219
|
+
__appPath__: appPath
|
|
220
|
+
}).reduce((prev, current) => {
|
|
221
|
+
const [key, value] = current;
|
|
222
|
+
return prev.replace(key, value.split(node_path.sep).join("/"));
|
|
223
|
+
}, installerCodeStr)
|
|
224
|
+
);
|
|
213
225
|
await new Promise((res) => setTimeout(res, 1e3));
|
|
226
|
+
const child = node_child_process.fork(node_path.join(appPath, "_evdInstallerTmp.js"), {
|
|
227
|
+
cwd: appPath,
|
|
228
|
+
stdio: "inherit"
|
|
229
|
+
});
|
|
230
|
+
await Promise.race([
|
|
231
|
+
new Promise((res) => {
|
|
232
|
+
child.on("exit", () => res);
|
|
233
|
+
}),
|
|
234
|
+
new Promise((res) => setTimeout(res, 10 * 1e3))
|
|
235
|
+
]);
|
|
214
236
|
}
|
|
215
237
|
function bindEvent(promptWindow) {
|
|
216
238
|
const { logo, onBeforeNewPkgInstall } = getConfigs();
|
|
@@ -283,30 +305,6 @@ function getConfigs() {
|
|
|
283
305
|
...globalArgs
|
|
284
306
|
};
|
|
285
307
|
}
|
|
286
|
-
function copyFileSync(source, target) {
|
|
287
|
-
let targetFile = target;
|
|
288
|
-
if (node_fs.existsSync(target)) {
|
|
289
|
-
if (node_fs.statSync(target).isDirectory()) {
|
|
290
|
-
targetFile = node_path.join(target, node_path.basename(source));
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
node_fs.writeFileSync(targetFile, node_fs.readFileSync(source));
|
|
294
|
-
}
|
|
295
|
-
function copyFolderRecursiveSync(source, target) {
|
|
296
|
-
if (!node_fs.existsSync(target)) {
|
|
297
|
-
node_fs.mkdirSync(target);
|
|
298
|
-
}
|
|
299
|
-
const files = node_fs.readdirSync(source);
|
|
300
|
-
files.forEach((file) => {
|
|
301
|
-
const sourcePath = node_path.join(source, file);
|
|
302
|
-
const targetPath = node_path.join(target, file);
|
|
303
|
-
if (node_fs.statSync(sourcePath).isDirectory()) {
|
|
304
|
-
copyFolderRecursiveSync(sourcePath, targetPath);
|
|
305
|
-
} else {
|
|
306
|
-
copyFileSync(sourcePath, targetPath);
|
|
307
|
-
}
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
308
|
exports.EVDCheckUpdate = EVDCheckUpdate;
|
|
311
309
|
exports.EVDEventEnum = EVDEventEnum;
|
|
312
310
|
exports.EVDInit = EVDInit;
|