generate-design-mapper-examples.mjs
2.11 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
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { enhanceFigmaFrame, loadComponentManifest } from "../packages/ai/design-mapper/src/index.mjs";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const root = path.resolve(__dirname, "..");
// Load manifests (vui + element-plus fallback chain)
const vuiManifest = loadComponentManifest(path.join(root, "packages/vui/vue/meta/index.json"));
if (!vuiManifest) {
console.error("Failed to load vui manifest");
process.exit(1);
}
const elManifest = loadComponentManifest(path.join(root, "contracts/ai/element-plus.manifest.json"));
if (!elManifest) {
console.error("Failed to load element-plus manifest");
process.exit(1);
}
const manifests = [vuiManifest, elManifest];
const examplesDir = path.join(root, "contracts/ai/examples");
const targets = ["allocation-confirmation.figma-frame.json", "user-management-list.figma-frame.json"];
for (const target of targets) {
const framePath = path.join(examplesDir, target);
if (!fs.existsSync(framePath)) {
console.warn(`Skip: ${target} not found`);
continue;
}
const figmaFrame = JSON.parse(fs.readFileSync(framePath, "utf8"));
const { enhancedFrame, suggestions } = enhanceFigmaFrame(figmaFrame, manifests);
const outFile = target.replace(".figma-frame.json", ".design-mapper-suggestions.json");
const outPath = path.join(examplesDir, outFile);
const output = {
$meta: {
generator: "scripts/generate-design-mapper-examples.mjs",
source: target,
manifests: [vuiManifest.packageName, elManifest.packageName],
},
suggestions,
enhancedFrame,
};
fs.writeFileSync(outPath, `${JSON.stringify(output, null, 2)}\n`, "utf8");
// Print summary
const s = suggestions.summary;
const td = s.tierDistribution;
console.log(
`[${suggestions.frameTitle}] elements=${suggestions.totalElements}, mapped=${s.mapped}, high=${s.highConfidence}, medium=${s.mediumConfidence}, low=${s.lowConfidence}, unmapped=${s.unmapped}`,
);
console.log(` tier: vui=${td.vui}, element-plus=${td.elementPlus}, html=${td.html}`);
console.log(` → ${outFile}`);
}
console.log("Done.");