electron-version-deployer-cli 0.4.12 → 0.4.14

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 CHANGED
@@ -138,13 +138,13 @@ async function bundleConfigFileAndRead(configFilePath) {
138
138
  }
139
139
  }
140
140
  }).then((data) => {
141
- const script = new vm.Script(data[0].output[0].code);
142
- const ctx = {
143
- require,
144
- module
145
- };
146
- script.runInNewContext(ctx);
147
- resolve(ctx.module.exports);
141
+ const m = { exports: {} };
142
+ const wrapper = `(function(require, module, exports) { ${data[0].output[0].code}
143
+ })`;
144
+ const script = new vm.Script(wrapper);
145
+ const fn = script.runInThisContext();
146
+ fn(require, m, m.exports);
147
+ resolve(m.exports.default || m.exports);
148
148
  });
149
149
  });
150
150
  }
@@ -820,4 +820,4 @@ async function installPrebuilt(configs) {
820
820
  }
821
821
  commander.program.description(
822
822
  "Electron 版本部署 CLI,简化你的 Electron 软件更新,让一切变得简单。"
823
- ).helpOption("-h, --help", "使用帮助").version("0.4.12", "-V, --version", "显示版本号").parse(process.argv);
823
+ ).helpOption("-h, --help", "使用帮助").version("0.4.14", "-V, --version", "显示版本号").parse(process.argv);
package/dist/main.js CHANGED
@@ -156,6 +156,7 @@ function compareObjectsIsEqual(obj1, obj2) {
156
156
  }
157
157
  const CLI_NAME = "electron-version-deployer-cli";
158
158
  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, sep, dirname, isAbsolute } = require("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 mkdirRecursiveSync(target);\n }\n\n // 获取源目录的文件列表\n const files = readdirSync(source);\n\n // 遍历文件列表,处理每个文件或子目录\n files.forEach((folderOrFile) => {\n const sourcePath = join(source, folderOrFile);\n const targetPath = join(target, folderOrFile);\n\n // 如果当前文件是文件夹,则递归复制文件夹\n if (statSync(sourcePath).isDirectory()) {\n if (folderOrFile === "node_modules") {\n replaceChangedModuleSync(sourcePath, targetPath);\n } else {\n copyFolderRecursiveSync(sourcePath, targetPath);\n }\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\nfunction replaceChangedModuleSync(\n sourceNodeModulesFolder,\n destNodeModulesFolder\n) {\n // 读取 evdUnzip/node_modules 所有子文件\n const fileOrFolder = readdirSync(sourceNodeModulesFolder);\n\n // 遍历文件列表,处理每个文件或子目录\n fileOrFolder.forEach((folderOrFileName) => {\n const sourcePath = join(sourceNodeModulesFolder, folderOrFileName);\n const targetPath = join(destNodeModulesFolder, folderOrFileName);\n\n // 如果当前文件是文件夹,则判断是否要更新\n if (statSync(sourcePath).isDirectory()) {\n // 如果是组织文件夹比如\n if (folderOrFileName.startsWith("@")) {\n replaceChangedModuleSync(sourcePath, targetPath);\n } else {\n // 如果不存在,或者版本不一样则进行替换\n if (shouldReplaceModule(sourcePath, targetPath)) {\n copyFolderRecursiveSync(sourcePath, targetPath);\n }\n }\n } else {\n copyFileSync(sourcePath, targetPath);\n }\n });\n}\n\nfunction shouldReplaceModule(sourcePath, destPath) {\n const sourceVersion = getPackageVersion(sourcePath);\n const destVersion = getPackageVersion(destPath);\n return sourceVersion !== destVersion;\n}\n\nfunction getPackageVersion(packagePath) {\n try {\n const packageJsonPath = join(packagePath, "package.json");\n const packageJsonContent = readFileSync(packageJsonPath, "utf-8");\n const packageJson = JSON.parse(packageJsonContent);\n return packageJson.version;\n } catch (error) {\n console.error(`Error reading package.json in ${packagePath}:`, error);\n return null;\n }\n}\n\nfunction mkdirRecursiveSync(targetPath) {\n mkdirSync(targetPath, { recursive: true });\n}\n';
159
+ const templateHtmlStr = '<!DOCTYPE html>\n<html lang="zh">\n <head>\n <meta charset="UTF-8" />\n <meta\n name="viewport"\n content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"\n />\n <link\n rel="icon"\n type="image/png"\n sizes="32x32"\n href="https://chat.openai.com/favicon-32x32.png"\n />\n <meta http-equiv="X-UA-Compatible" content="ie=edge" />\n <title>有可用的更新</title>\n <style>\n * {\n margin: 0;\n padding: 0;\n }\n\n body {\n font-family: -apple-system, Helvetica, Arial, sans-serif,\n "Microsoft YaHei", "ST Heiti";\n color: #333;\n padding: 20px;\n background-color: #f5f5f5;\n }\n\n .title {\n font-size: 18px;\n font-weight: bold;\n margin-bottom: 10px;\n }\n\n .content {\n margin-top: 8px;\n margin-bottom: 12px;\n margin-left: -20px;\n margin-right: -20px;\n height: 200px;\n overflow: auto;\n padding: 0 20px;\n }\n\n .content ul {\n padding-left: 20px;\n margin-top: 5px;\n margin-bottom: 10px;\n }\n\n .content ul li {\n margin-bottom: 4px;\n }\n\n .buttons-box {\n display: flex;\n justify-content: flex-end;\n }\n\n .buttons-box button {\n padding: 10px 20px;\n font-size: 14px;\n font-weight: bold;\n border-radius: 5px;\n border: none;\n cursor: pointer;\n margin-left: 12px;\n }\n\n .buttons-box button:first-child {\n background-color: #007bff;\n color: #fff;\n }\n\n .buttons-box button:last-child {\n background-color: #ccc;\n color: #333;\n }\n\n .buttons-box button:first-child:hover {\n background-color: #0056b3;\n }\n\n .buttons-box button:last-child:hover {\n background-color: #b3b3b3;\n }\n\n .title-bar {\n display: flex;\n flex-direction: row;\n justify-content: flex-start;\n align-items: center;\n }\n\n .title-bar img {\n margin-right: 12px;\n }\n\n .loading-box {\n position: fixed;\n left: 0;\n top: 0;\n bottom: 0;\n right: 0;\n background: rgba(255, 255, 255, 0.9);\n font-size: 18px;\n flex-direction: row;\n align-items: center;\n justify-content: center;\n display: none;\n font-weight: bold;\n }\n </style>\n </head>\n <body>\n <div class="loading-box">软件更新中……</div>\n <div class="title-bar">\n <img src="" width="34" class="logo" style="display: none" />\n <span>有可用的新版本:</span>\n <a\n href="#"\n class="see-all-changes"\n style="text-decoration: underline; font-size: 14px"\n >(所有版本更新记录)</a\n >\n </div>\n <div class="content">具体更新内容请查看 Changelogs</div>\n <div class="buttons-box">\n <button id="updateBtn">现在更新</button>\n <button id="skipBtn">稍后再提醒我</button>\n </div>\n\n <script>\n const { ipcRenderer } = require("electron");\n\n document.querySelector("#updateBtn").addEventListener("click", () => {\n ipcRenderer.send("evd-update-now");\n document.querySelector(".loading-box").style.display = "flex";\n });\n\n document.querySelector("#skipBtn").addEventListener("click", () => {\n ipcRenderer.send("evd-skip");\n });\n\n ipcRenderer.invoke("evd-get-logo").then((link) => {\n if (link) {\n const imgRef = document.querySelector(".logo");\n imgRef.src = link;\n imgRef.style.display = "inline-block";\n }\n });\n\n ipcRenderer.invoke("evd-get-changelogs-link").then((link) => {\n const aTag = document.querySelector(".see-all-changes");\n if (link) {\n aTag.href = link;\n } else {\n aTag.remove();\n }\n });\n\n ipcRenderer.invoke("evd-get-change-logs").then((data) => {\n // 如果没有数据就不渲染\n if (!data) return;\n\n const contentRef = document.querySelector(".content");\n\n contentRef.innerHTML = `\n <p class="title">${data.title}</p>\n ${data.changes}\n `;\n\n // 监听所有 A 链接点击\n Array.from(document.querySelectorAll("a")).map((a) => {\n a.addEventListener("click", (ev) => {\n ev.preventDefault();\n\n ipcRenderer.send("evd-open-link", ev.target.href);\n });\n });\n });\n <\/script>\n </body>\n</html>\n';
159
160
  function forceDeleteSync(targetPath) {
160
161
  try {
161
162
  const stats = fs.statSync(targetPath);
@@ -263,17 +264,26 @@ async function showNewVersionDialog() {
263
264
  });
264
265
  promptWindow.setMenu(null);
265
266
  promptWindow.setMenuBarVisibility(false);
267
+ const appPath = electron.app.getAppPath();
268
+ const nodeModulesTemplatePath = node_path.join(
269
+ appPath,
270
+ "node_modules",
271
+ CLI_NAME,
272
+ "dist",
273
+ "templates",
274
+ "newVersionDialog.html"
275
+ );
276
+ let templatePath;
277
+ if (node_fs.existsSync(nodeModulesTemplatePath)) {
278
+ templatePath = nodeModulesTemplatePath;
279
+ } else {
280
+ templatePath = node_path.join(appPath, "_evdDialogTemplate.html");
281
+ node_fs.writeFileSync(templatePath, templateHtmlStr, "utf-8");
282
+ }
266
283
  const promptUrl = node_url.format({
267
284
  protocol: "file",
268
285
  slashes: true,
269
- pathname: node_path.join(
270
- electron.app.getAppPath(),
271
- "node_modules",
272
- CLI_NAME,
273
- "dist",
274
- "templates",
275
- "newVersionDialog.html"
276
- ),
286
+ pathname: templatePath,
277
287
  hash: id
278
288
  });
279
289
  promptWindow.loadURL(promptUrl);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "electron-version-deployer-cli",
3
3
  "private": false,
4
- "version": "0.4.12",
4
+ "version": "0.4.14",
5
5
  "types": "./dist/index.d.ts",
6
6
  "main": "./dist/index.cjs.js",
7
7
  "module": "./dist/index.es.js",