@actiondock/builder 2.0.8 → 2.0.10
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/package.json +10 -4
- package/src/build.ts +106 -0
- package/src/exporter.ts +17 -30
- package/src/index.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@actiondock/builder",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.10",
|
|
4
4
|
"description": "ActionDock Build Planner, Bun standalone compiler, and Skill exporter",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -27,15 +27,21 @@
|
|
|
27
27
|
"test": "bun test"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@actiondock/core": "^2.0.
|
|
31
|
-
"@actiondock/sdk": "^2.0.
|
|
30
|
+
"@actiondock/core": "^2.0.10",
|
|
31
|
+
"@actiondock/sdk": "^2.0.10",
|
|
32
32
|
"yaml": "^2.7.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@types/bun": "latest",
|
|
36
36
|
"typescript": "^5.7.0"
|
|
37
37
|
},
|
|
38
|
-
"keywords": [
|
|
38
|
+
"keywords": [
|
|
39
|
+
"actiondock",
|
|
40
|
+
"builder",
|
|
41
|
+
"compiler",
|
|
42
|
+
"skill",
|
|
43
|
+
"export"
|
|
44
|
+
],
|
|
39
45
|
"author": "team4u",
|
|
40
46
|
"license": "Apache-2.0",
|
|
41
47
|
"repository": {
|
package/src/build.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join, resolve } from "node:path";
|
|
3
|
+
import { generateStandaloneEntrypoint, getPackageSlug } from "@actiondock/core";
|
|
4
|
+
import { BunCompiler } from "./compiler";
|
|
5
|
+
import { BuilderError } from "./errors";
|
|
6
|
+
import { BuildPlanner } from "./planner";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 独立二进制可执行文件构建选项。
|
|
10
|
+
*/
|
|
11
|
+
export interface BuildOptions {
|
|
12
|
+
/** 目标项目根目录 */
|
|
13
|
+
projectRoot: string;
|
|
14
|
+
/** 目标架构(如 "bun-linux-x64", "bun-darwin-arm64", "bun-windows-x64" 等) */
|
|
15
|
+
target?: string;
|
|
16
|
+
/** 输出可执行文件的目标路径(默认输出到 dist/ 目录) */
|
|
17
|
+
outfile?: string;
|
|
18
|
+
/** 是否开启代码压缩混淆(默认 true) */
|
|
19
|
+
minify?: boolean;
|
|
20
|
+
/** 是否编译为 V8/JavaScriptCore 字节码(默认 true) */
|
|
21
|
+
bytecode?: boolean;
|
|
22
|
+
/** 显式挑选打包的 Action ID 清单(用于按需子集打包) */
|
|
23
|
+
actions?: string[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 独立二进制构建完成后的元数据结果对象。
|
|
28
|
+
*/
|
|
29
|
+
export interface BuildResult {
|
|
30
|
+
/** 所属 Package ID */
|
|
31
|
+
packageId: string;
|
|
32
|
+
/** 打包的项目版本号 */
|
|
33
|
+
version: string;
|
|
34
|
+
/** 编译的目标平台架构 */
|
|
35
|
+
target: string;
|
|
36
|
+
/** 生成的独立二进制可执行文件绝对路径 */
|
|
37
|
+
executablePath: string;
|
|
38
|
+
/** 生成的 sidecar 元数据 JSON 文件绝对路径 */
|
|
39
|
+
metadataPath: string;
|
|
40
|
+
/** 打包内置的 Action ID 列表 */
|
|
41
|
+
actions: string[];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 调用 Bun 原生编译引擎(Bun.build --compile)将 Action Package 打包为零外部依赖的独立二进制可执行文件。
|
|
46
|
+
*
|
|
47
|
+
* @param options 构建参数
|
|
48
|
+
* @returns 构建产物结果元数据
|
|
49
|
+
*/
|
|
50
|
+
export async function buildProject(options: BuildOptions): Promise<BuildResult> {
|
|
51
|
+
const root = resolve(options.projectRoot);
|
|
52
|
+
const plan = BuildPlanner.plan({
|
|
53
|
+
projectRoot: root,
|
|
54
|
+
actions: options.actions,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
if (plan.actions.length === 0) {
|
|
58
|
+
throw new BuilderError("No actions resolved for standalone compilation");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const buildDir = join(root, ".actiondock", ".build");
|
|
62
|
+
mkdirSync(buildDir, { recursive: true });
|
|
63
|
+
|
|
64
|
+
const entryCode = generateStandaloneEntrypoint(
|
|
65
|
+
plan.packageId,
|
|
66
|
+
plan.version,
|
|
67
|
+
plan.description,
|
|
68
|
+
plan.actions.map((a) => ({ id: a.id, filePath: a.resolvedPath })),
|
|
69
|
+
plan.configDefs
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
const entryFileName = `entry-${Date.now()}-${Math.random().toString(36).slice(2, 8)}.ts`;
|
|
73
|
+
const entryPath = join(buildDir, entryFileName);
|
|
74
|
+
writeFileSync(entryPath, entryCode, "utf-8");
|
|
75
|
+
|
|
76
|
+
const binaryName = getPackageSlug(plan.packageId);
|
|
77
|
+
const defaultOutfile = join(root, "dist", binaryName);
|
|
78
|
+
const outfile = resolve(options.outfile || defaultOutfile);
|
|
79
|
+
|
|
80
|
+
try {
|
|
81
|
+
const result = await BunCompiler.compile({
|
|
82
|
+
entrypoint: entryPath,
|
|
83
|
+
outfile,
|
|
84
|
+
target: options.target,
|
|
85
|
+
minify: options.minify,
|
|
86
|
+
bytecode: options.bytecode,
|
|
87
|
+
cwd: root,
|
|
88
|
+
packageId: plan.packageId,
|
|
89
|
+
version: plan.version,
|
|
90
|
+
actions: plan.actions.map((a) => a.id),
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
packageId: result.packageId || plan.packageId,
|
|
95
|
+
version: result.version || plan.version,
|
|
96
|
+
target: result.target,
|
|
97
|
+
executablePath: result.executablePath,
|
|
98
|
+
metadataPath: result.metadataPath || "",
|
|
99
|
+
actions: plan.actions.map((a) => a.id),
|
|
100
|
+
};
|
|
101
|
+
} finally {
|
|
102
|
+
if (existsSync(entryPath)) {
|
|
103
|
+
rmSync(entryPath, { force: true });
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
package/src/exporter.ts
CHANGED
|
@@ -130,32 +130,17 @@ export class SkillExporter {
|
|
|
130
130
|
writeFileSync(join(skillDir, "SKILL.md"), skillMd, "utf-8");
|
|
131
131
|
|
|
132
132
|
// 2. 生成 actiondock.skill.json 工具清单
|
|
133
|
-
const skillJsonContent =
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
id: a.id,
|
|
142
|
-
entry: a.entry,
|
|
143
|
-
description: a.description,
|
|
144
|
-
inputSchema: a.inputSchema,
|
|
145
|
-
outputSchema: a.outputSchema,
|
|
146
|
-
uses: a.uses,
|
|
147
|
-
tags: a.tags,
|
|
148
|
-
})),
|
|
149
|
-
playbooks: plan.playbooks.map((p) => ({
|
|
150
|
-
id: p.id,
|
|
151
|
-
description: p.description,
|
|
152
|
-
entry: `playbooks/${basename(p.filePath)}`,
|
|
153
|
-
})),
|
|
154
|
-
exportedAt: new Date().toISOString(),
|
|
155
|
-
};
|
|
133
|
+
const skillJsonContent = generateSkillJson(
|
|
134
|
+
configForTemplates,
|
|
135
|
+
plan.actions as any,
|
|
136
|
+
{
|
|
137
|
+
mode: "source",
|
|
138
|
+
playbooks: plan.playbooks as any,
|
|
139
|
+
}
|
|
140
|
+
);
|
|
156
141
|
writeFileSync(
|
|
157
142
|
join(skillDir, "actiondock.skill.json"),
|
|
158
|
-
|
|
143
|
+
skillJsonContent,
|
|
159
144
|
"utf-8"
|
|
160
145
|
);
|
|
161
146
|
|
|
@@ -329,17 +314,19 @@ export class SkillExporter {
|
|
|
329
314
|
writeFileSync(join(skillDir, "SKILL.md"), skillMd, "utf-8");
|
|
330
315
|
|
|
331
316
|
// 2. 生成 actiondock.skill.json
|
|
332
|
-
const
|
|
317
|
+
const skillJsonContent = generateSkillJson(
|
|
333
318
|
configForTemplates,
|
|
334
319
|
plan.actions as any,
|
|
335
|
-
|
|
336
|
-
|
|
320
|
+
{
|
|
321
|
+
mode: "standalone",
|
|
322
|
+
executable: `./bin/${actualBinaryName}`,
|
|
323
|
+
target,
|
|
324
|
+
playbooks: plan.playbooks as any,
|
|
325
|
+
}
|
|
337
326
|
);
|
|
338
|
-
const parsedSkillJson = JSON.parse(rawSkillJson);
|
|
339
|
-
parsedSkillJson.mode = "standalone";
|
|
340
327
|
writeFileSync(
|
|
341
328
|
join(skillDir, "actiondock.skill.json"),
|
|
342
|
-
|
|
329
|
+
skillJsonContent,
|
|
343
330
|
"utf-8"
|
|
344
331
|
);
|
|
345
332
|
|