Skip to content

Commit e239f14

Browse files
committed
🦄 refactor: 优化构建脚本
1 parent 9c78553 commit e239f14

2 files changed

Lines changed: 28 additions & 24 deletions

File tree

native/ferrous-opencc-wasm/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"version": "0.1.0",
44
"private": true,
55
"scripts": {
6-
"build": "wasm-pack build --target web"
6+
"build": "wasm-pack build --target web",
7+
"build:debug": "wasm-pack build --target web --dev"
78
},
89
"devDependencies": {
910
"wasm-pack": "^0.13.1"

scripts/build-native.ts

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import os from "node:os";
44
import path from "node:path";
55
import process from "node:process";
66

7+
interface NativeModule {
8+
name: string;
9+
enabled?: boolean;
10+
}
11+
712
const isRustAvailable = () => {
813
try {
914
execSync("cargo --version", { stdio: "ignore" });
@@ -32,39 +37,37 @@ if (!isRustAvailable()) {
3237
process.exit(1);
3338
}
3439

35-
console.log(`[BuildNative] 当前构建目标: ${process.platform}`);
40+
const modules: NativeModule[] = [
41+
{
42+
name: "external-media-integration",
43+
},
44+
{
45+
name: "tools",
46+
},
47+
{
48+
name: "taskbar-lyric",
49+
enabled: isWindows,
50+
},
51+
// 有人抱怨编译 wasm 总是有问题,暂时注释掉
52+
// {
53+
// name: "ferrous-opencc-wasm",
54+
// },
55+
];
3656

3757
try {
38-
console.log("[BuildNative] 开始构建原生模块...");
39-
4058
const args = process.argv.slice(2);
4159
const isDev = args.includes("--dev");
4260
const buildCommand = isDev ? "build:debug" : "build";
4361

44-
execSync(`pnpm --filter external-media-integration ${buildCommand}`, {
45-
stdio: "inherit",
46-
});
47-
48-
console.log(`[BuildNative] 构建 tools 原生模块 (${buildCommand})...`);
49-
execSync(`pnpm --filter tools ${buildCommand}`, {
50-
stdio: "inherit",
51-
});
52-
53-
if (isWindows) {
54-
console.log(`[BuildNative] 构建任务栏歌词原生模块 (${buildCommand})...`);
55-
execSync(`pnpm --filter taskbar-lyric ${buildCommand}`, {
62+
for (const mod of modules) {
63+
if (mod.enabled === false) {
64+
continue;
65+
}
66+
execSync(`pnpm --filter ${mod.name} ${buildCommand}`, {
5667
stdio: "inherit",
5768
});
5869
}
59-
60-
// 有人抱怨编译 wasm 总是有问题,暂时注释掉
61-
// console.log("[BuildNative] 构建 ferrous-opencc-wasm...");
62-
// execSync("pnpm --filter ferrous-opencc-wasm build", {
63-
// stdio: "inherit",
64-
// });
6570
} catch (error) {
6671
console.error("[BuildNative] 模块构建失败", error);
6772
process.exit(1);
6873
}
69-
70-
console.log("[BuildNative] 原生模块构建完成");

0 commit comments

Comments
 (0)