Skip to content

Commit a95b51d

Browse files
committed
开发 编译脚本使用类型检查,修复arch判断错误
1 parent 075244b commit a95b51d

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

Diff for: electron-builder.config.js

+20-21
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-check
12
const fs = require("node:fs");
23
const path = require("node:path");
34
const archiver = require("archiver");
@@ -7,8 +8,8 @@ const download = require("download");
78
const arch =
89
(process.env.npm_config_arch || process.env.M_ARCH || process.arch) ===
910
"arm64"
10-
? ["arm64"]
11-
: ["x64"];
11+
? "arm64"
12+
: "x64";
1213

1314
const platform = process.platform;
1415
const platformMap = { linux: "linux", win32: "win", darwin: "mac" };
@@ -88,12 +89,12 @@ const beforePack = async () => {
8889
}
8990
}
9091
if (process.platform === "win32" && arch === "arm64") {
91-
execSync("npm i node-screenshots-win32-arm64-msvc");
92-
execSync("npm uninstall node-screenshots-win32-x64-msvc");
92+
execSync("pnpm i node-screenshots-win32-arm64-msvc");
93+
execSync("pnpm uninstall node-screenshots-win32-x64-msvc");
9394
}
9495
if (process.platform === "darwin" && arch === "arm64") {
95-
execSync("npm i node-screenshots-darwin-arm64");
96-
execSync("npm uninstall node-screenshots-darwin-x64");
96+
execSync("pnpm i node-screenshots-darwin-arm64");
97+
execSync("pnpm uninstall node-screenshots-darwin-x64");
9798
}
9899
};
99100

@@ -129,7 +130,7 @@ const build = {
129130
},
130131
],
131132
asar: false,
132-
artifactName: `\${productName}-\${version}-\${platform}-${arch[0]}.\${ext}`,
133+
artifactName: `\${productName}-\${version}-\${platform}-${arch}.\${ext}`,
133134
beforePack: beforePack,
134135
linux: {
135136
category: "Utility",
@@ -246,7 +247,7 @@ const build = {
246247

247248
const outputFilePath = path.join(
248249
c.outDir,
249-
`app-${process.platform}-${arch[0]}`,
250+
`app-${process.platform}-${arch}`,
250251
);
251252

252253
const output = fs.createWriteStream(outputFilePath);
@@ -261,32 +262,30 @@ const build = {
261262
return new Promise((rj) => {
262263
output.on("close", () => {
263264
console.log("生成核心包");
264-
rj();
265+
rj(true);
265266
});
266267
});
267268
},
268269
};
269270

270-
const archFilter = arch[0] === "arm64" ? "x64" : "arm64";
271+
const archFilter = arch === "arm64" ? "x64" : "arm64";
271272
const otherPlatform = Object.keys(platformMap).filter((i) => i !== platform);
272273

274+
/** @type {string[]|undefined} */
275+
// @ts-ignore
276+
const files = build[platform2]?.files;
277+
273278
// 移除 onnxruntime-node/bin/napi-v3/
274-
build[platform2].files.push(
279+
files?.push(
275280
`!node_modules/onnxruntime-node/bin/napi-v3/${platform}/${archFilter}`,
276281
);
277282

278283
// 移除 uiohook-napi/prebuilds
279284
for (const i of otherPlatform) {
280-
build[platform2].files.push(
281-
`!node_modules/uiohook-napi/prebuilds/${i}-arm64`,
282-
);
283-
build[platform2].files.push(
284-
`!node_modules/uiohook-napi/prebuilds/${i}-x64`,
285-
);
285+
files?.push(`!node_modules/uiohook-napi/prebuilds/${i}-arm64`);
286+
files?.push(`!node_modules/uiohook-napi/prebuilds/${i}-x64`);
286287
}
287-
build[platform2].files.push(
288-
`!node_modules/uiohook-napi/prebuilds/${platform}-${archFilter}`,
289-
);
288+
files?.push(`!node_modules/uiohook-napi/prebuilds/${platform}-${archFilter}`);
290289

291290
const ignoreDir = [
292291
".*",
@@ -326,7 +325,7 @@ for (const i of ignoreModule) {
326325
}
327326
for (let i of ignoreDir) {
328327
i = `!${i}`;
329-
build[platform2].files.push(i);
328+
files?.push(i);
330329
}
331330

332331
module.exports = build;

0 commit comments

Comments
 (0)