Merge branch 'main' into dev_v4

This commit is contained in:
gaoshuaixing
2025-05-24 10:29:16 +08:00
2 changed files with 51 additions and 1 deletions

View File

@@ -205,6 +205,35 @@ function getArgumentByName(name, args) {
}
}
function getExtraResourcesDir() {
const dir = path.join(_basePath, "build", "extraResources")
return dir;
}
function getModuleNameFromPath(modulePath) {
// 分割路径段(处理不同系统的分隔符)
const segments = path.normalize(modulePath).split(path.sep);
// 从后往前查找 node_modules
for (let i = segments.length - 1; i >= 0; i--) {
if (segments[i] === 'node_modules') {
// 普通模块node_modules/dayjs
if (i + 1 < segments.length) {
return segments[i + 1];
}
// 作用域模块node_modules/@scope/module
if (i + 2 < segments.length && segments[i + 1].startsWith('@')) {
return `${segments[i + 1]}/${segments[i + 2]}`;
}
break; // 找到 node_modules 但后面没有模块名
}
}
return null;
}
module.exports = {
loadConfig,
getElectronProgram,
@@ -220,5 +249,7 @@ module.exports = {
getPackage,
readJsonSync,
writeJsonSync,
getArgumentByName
getArgumentByName,
getExtraResourcesDir,
getModuleNameFromPath
}

View File

@@ -25,6 +25,8 @@ class IncrUpdater {
'win-ia32-unpacked',
'linux-unpacked'
];
this.nodeModulesString = 'node_modules';
this.asarUnpackedString = 'app.asar.unpacked';
}
/**
@@ -101,9 +103,26 @@ class IncrUpdater {
const extraResDir = path.dirname(extraResPath);
const index = extraResDir.indexOf('extraResources');
const zipFileDir = extraResDir.substring(index);
// 资源路径 extraResPath: D:\www\gofile\src\ee\ee-demo\build\extraResources\hello\c.txt
// 文件在zip中的路径 zipFileDir: extraResources/hello
zip.addLocalFile(extraResPath, zipFileDir);
}
}
// 添加 asarUnpacked
if (cfg.asarUnpacked && cfg.asarUnpacked.length > 0) {
const modules = cfg.asarUnpacked;
for (const moduleItem of modules) {
const modulePath = path.normalize(path.join(homeDir, moduleItem));
if (!fs.existsSync(modulePath)) {
throw new Error(`${modulePath} is not exists!`);
}
const zipDir = path.join(this.asarUnpackedString, moduleItem);
// console.log('modulePath', modulePath);
// console.log('zipDir', zipDir);
zip.addLocalFolder(modulePath, zipDir);
}
}
zip.writeZip(asarZipPath, (err) => {
if (err) {