electron-version-deployer-cli 0.3.6 → 0.3.8

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
@@ -698,4 +698,4 @@ async function installPrebuilt(configs) {
698
698
  }
699
699
  commander.program.description(
700
700
  "Electron 版本部署 CLI,简化你的 Electron 软件更新,让一切变得简单。"
701
- ).helpOption("-h, --help", "使用帮助").version("0.3.6", "-V, --version", "显示版本号").parse(process.argv);
701
+ ).helpOption("-h, --help", "使用帮助").version("0.3.8", "-V, --version", "显示版本号").parse(process.argv);
package/dist/main.js CHANGED
@@ -94,7 +94,7 @@ function compareObjectsIsEqual(obj1, obj2) {
94
94
  return true;
95
95
  }
96
96
  const CLI_NAME = "electron-version-deployer-cli";
97
- 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 // 将路径分割成数组\n const initDir = isAbsolute(targetPath) ? sep : "";\n const parts = targetPath.split(sep);\n\n parts.forEach((part, index) => {\n if (!part && index === 0) return; // 如果是绝对路径,跳过第一个空字符串\n const currentPath = join(initDir, ...parts.slice(0, index + 1));\n if (!existsSync(currentPath)) {\n mkdirSync(currentPath);\n }\n });\n}\n';
97
+ 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';
98
98
  function forceDeleteSync(targetPath) {
99
99
  try {
100
100
  const stats = fs.statSync(targetPath);
@@ -278,21 +278,27 @@ async function installPkg(zipFile) {
278
278
  for (let fileName of fullCodeSplitIndexFile) {
279
279
  const tmpFilePath = node_path.join(appPath, fileName);
280
280
  const tmpSplitZip = node_fs.createWriteStream(tmpFilePath);
281
- const response = await netRequest({
282
- url: `${remoteUrl}/fullCodeZipSplitZips/${fileName}?hash=${Math.random()}`,
283
- responseType: "stream"
284
- });
285
- await new Promise((streamRes, streamRej) => {
286
- response.on("data", (chunk) => {
287
- tmpSplitZip.write(chunk);
281
+ await new Promise((_res, _rej) => {
282
+ const request = electron.net.request({
283
+ url: `${remoteUrl}/fullCodeZipSplitZips/${fileName}?hash=${Math.random()}`,
284
+ method: "GET"
288
285
  });
289
- response.on("end", () => {
290
- tmpSplitZip.end(() => {
291
- mergedStream.write(node_fs.readFileSync(tmpFilePath));
292
- streamRes();
286
+ request.on("response", (response) => {
287
+ response.pipe(tmpSplitZip).on("finish", () => {
288
+ tmpSplitZip.end(() => {
289
+ mergedStream.write(node_fs.readFileSync(tmpFilePath));
290
+ _res();
291
+ });
292
+ }).on("error", (error) => {
293
+ _rej(error);
293
294
  });
294
295
  });
295
- response.on("error", streamRej);
296
+ request.on("error", (error) => {
297
+ _rej(error);
298
+ });
299
+ request.end();
300
+ }).catch((error) => {
301
+ rej(error);
296
302
  });
297
303
  forceDeleteSync(tmpFilePath);
298
304
  }
@@ -301,22 +307,23 @@ async function installPkg(zipFile) {
301
307
  });
302
308
  } else {
303
309
  const tmpZipFilePath = node_fs.createWriteStream(unzipPath + ".zip");
304
- const response = await netRequest({
310
+ const request = electron.net.request({
305
311
  url: `${remoteUrl}/${zipFile}?hash=${Math.random()}`,
306
- responseType: "stream"
312
+ method: "GET"
307
313
  });
308
- await new Promise((streamRes, streamRej) => {
309
- response.on("data", (chunk) => {
310
- tmpZipFilePath.write(chunk);
311
- });
312
- response.on("end", () => {
314
+ request.on("response", (response) => {
315
+ response.pipe(tmpZipFilePath).on("finish", () => {
313
316
  tmpZipFilePath.end(() => {
314
- streamRes();
317
+ res();
315
318
  });
319
+ }).on("error", (error) => {
320
+ rej(error);
316
321
  });
317
- response.on("error", streamRej);
318
322
  });
319
- res();
323
+ request.on("error", (error) => {
324
+ rej(error);
325
+ });
326
+ request.end();
320
327
  }
321
328
  });
322
329
  await extract(unzipPath + ".zip", { dir: unzipPath });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "electron-version-deployer-cli",
3
3
  "private": false,
4
- "version": "0.3.6",
4
+ "version": "0.3.8",
5
5
  "types": "./dist/index.d.ts",
6
6
  "main": "./dist/index.cjs.js",
7
7
  "module": "./dist/index.es.js",