generate-allocation-confirmation-example.mjs
3.5 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
import fs from "node:fs";
import path from "node:path";
import { generateVueModule, writeGeneratedFiles } from "../packages/ai/codegen/src/index.mjs";
import {
mcpDesignContextToFigmaFrame,
mcpDesignContextToPageSchema,
toJson,
} from "../packages/ai/figma-ingest/src/index.mjs";
import { generateIncrementalPatchBundle, writeIncrementalPatchBundle } from "../packages/ai/patcher/src/index.mjs";
const workspaceRoot = path.resolve(import.meta.dirname, "..");
const figmaUrl =
"https://www.figma.com/design/taBZMgXMmkHYUEDwb4ROMX/202604-%E8%B0%83%E6%8B%A8%E7%AE%A1%E7%90%86?node-id=1-1592&m=dev";
const designContext = `
<div data-node-id="1:1592">
<div data-node-id="1:1593"><p>调拨确认单</p></div>
<div className="bg-[#f4f6fc] border-b border-solid"><p>序号</p></div>
<div className="bg-[#f4f6fc] border-b border-solid"><p>商品名称</p></div>
<div className="bg-[#f4f6fc] border-b border-solid"><p>规格</p></div>
<div className="bg-[#f4f6fc] border-b border-solid"><p>调拨数量</p></div>
<div className="bg-[#f4f6fc] border-b border-solid"><p>调出仓</p></div>
<div className="bg-[#f4f6fc] border-b border-solid"><p>调入仓</p></div>
<div><p>1</p></div>
<div><p>商品名称商品名称 商品名称</p></div>
<div><p>A/B</p></div>
<div><p>20</p></div>
<div><p>杭州仓</p></div>
<div><p>上海仓</p></div>
</div>
`.trim();
const options = {
figmaUrl,
frameId: "allocation-confirmation",
title: "调拨确认单",
primaryBlockName: "调拨明细表",
route: {
path: "/allocation/confirmation",
name: "AllocationConfirmation",
menuTitle: "调拨确认单",
requiresAuth: true,
},
notes: "Generated from the real Figma MCP node 1:1592 for the allocation confirmation pilot.",
};
const figmaFrame = mcpDesignContextToFigmaFrame(designContext, options);
figmaFrame.$schema = "../figma-frame.schema.json";
const pageSchema = mcpDesignContextToPageSchema(designContext, options);
const codegenProjectContext = JSON.parse(
fs.readFileSync(path.join(workspaceRoot, "contracts/ai/examples/vui-admin.project-context.json"), "utf8"),
);
const patchProjectContext = JSON.parse(
fs.readFileSync(path.join(workspaceRoot, "contracts/ai/examples/example.project-context.json"), "utf8"),
);
const generatedFiles = generateVueModule(pageSchema, codegenProjectContext);
const patchBundle = generateIncrementalPatchBundle(pageSchema, patchProjectContext);
const framePath = path.join(workspaceRoot, "contracts/ai/examples/allocation-confirmation.figma-frame.json");
const pageSchemaPath = path.join(
workspaceRoot,
"contracts/ai/examples/allocation-confirmation.from-figma.page-schema.json",
);
const patchPlanPath = path.join(
workspaceRoot,
"contracts/ai/examples/allocation-confirmation.example.incremental-patch-plan.json",
);
const outputRoot = path.join(
workspaceRoot,
"packages/ai/codegen/examples/generated-from-figma-allocation-confirmation",
);
const patchOutputRoot = path.join(
workspaceRoot,
"packages/ai/patcher/examples/generated-from-figma-allocation-confirmation-example",
);
fs.writeFileSync(framePath, toJson(figmaFrame), "utf8");
fs.writeFileSync(pageSchemaPath, toJson(pageSchema), "utf8");
fs.writeFileSync(patchPlanPath, toJson(patchBundle.plan), "utf8");
writeGeneratedFiles(outputRoot, generatedFiles);
writeIncrementalPatchBundle(patchOutputRoot, patchBundle);
console.log(
JSON.stringify(
{
framePath,
pageSchemaPath,
patchPlanPath,
generatedFiles: generatedFiles.map((file) => file.path),
patchFiles: patchBundle.files.map((file) => file.path),
},
null,
2,
),
);