check-ai-artifacts.mjs
3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env node
/**
* AI 产物专项 fitness 检查
*
* 验证 AI 相关的 schema 和 manifest 文件可解析、结构完整。
*/
import fs from "node:fs";
import path from "node:path";
import process from "node:process";
import { requireWorkspaceRoot } from "./workspace-root.mjs";
const repoRoot = requireWorkspaceRoot();
const failures = [];
let totalChecks = 0;
function relativePath(file) {
return path.relative(repoRoot, file).replaceAll("\\", "/");
}
function check(condition, file, message) {
totalChecks++;
if (!condition) {
failures.push(`${relativePath(file)}: ${message}`);
}
}
// ── Schema 文件可解析性检查 ──
const schemaFiles = [
path.join(repoRoot, "contracts", "ai", "project-context.schema.json"),
path.join(repoRoot, "contracts", "ai", "ai-direct-context-bundle.schema.json"),
path.join(repoRoot, "contracts", "ai", "component-manifest.schema.json"),
path.join(repoRoot, "contracts", "ai", "component-manifest-index.schema.json"),
path.join(repoRoot, "contracts", "ai", "component-manifest-item.schema.json"),
];
console.log("[ai-artifacts] Checking schema files...");
for (const schemaFile of schemaFiles) {
if (fs.existsSync(schemaFile)) {
totalChecks++;
try {
JSON.parse(fs.readFileSync(schemaFile, "utf8"));
} catch (error) {
failures.push(`${relativePath(schemaFile)}: schema JSON parse error: ${error.message}`);
}
}
}
// ── Manifest 文件可解析性 + 结构检查 ──
const manifestFiles = [
path.join(repoRoot, "contracts", "ai", "element-plus.manifest.json"),
path.join(repoRoot, "packages", "vui", "vue", "meta", "index.json"),
];
console.log("[ai-artifacts] Checking manifest files...");
for (const manifestFile of manifestFiles) {
if (fs.existsSync(manifestFile)) {
totalChecks++;
try {
const manifest = JSON.parse(fs.readFileSync(manifestFile, "utf8"));
check("packageName" in manifest, relativePath(manifestFile), "manifest missing 'packageName'");
check("components" in manifest, relativePath(manifestFile), "manifest missing 'components'");
if (Array.isArray(manifest.components)) {
for (const comp of manifest.components) {
const componentName = comp.exportName || comp.name || "?";
check("exportName" in comp, relativePath(manifestFile), `component "${componentName}" missing 'exportName'`);
if ("manifest" in comp) {
check(
typeof comp.manifest === "string" && comp.manifest.length > 0,
relativePath(manifestFile),
`component "${componentName}" missing 'manifest' path`,
);
} else {
check(
"figmaMapping" in comp,
relativePath(manifestFile),
`component "${componentName}" missing 'figmaMapping'`,
);
}
}
}
} catch (error) {
failures.push(`${relativePath(manifestFile)}: manifest JSON parse error: ${error.message}`);
}
}
}
// ── 输出 ──
console.log("\n[ai-artifacts] Results");
console.log(` Total checks: ${totalChecks}`);
if (failures.length > 0) {
console.error(`\n[ai-artifacts] FAILED (${failures.length} issue(s)):`);
for (const f of failures) {
console.error(` ✗ ${f}`);
}
process.exit(1);
}
console.log("\n[ai-artifacts] All checks passed.");
process.exit(0);