mini-figma-code-connect 0.1.3 → 0.1.5

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/README.md CHANGED
@@ -57,7 +57,7 @@ pnpm add -D mini-figma-code-connect
57
57
  # 或:npm install -D mini-figma-code-connect
58
58
  ```
59
59
 
60
- 本地开发引擎时仍可用 `link:` / `file:` 指向仓库路径。包尚未安装时,后续 CLI 命令均不存在。
60
+ 包尚未安装时,后续 CLI 命令均不存在。
61
61
 
62
62
  #### 2. 执行一次性脚手架
63
63
 
@@ -128,3 +128,6 @@ pnpm exec mini-code-connect-scaffold-manifest --id <manifest-id>
128
128
  2. 完全退出并重启 Figma。
129
129
  3. 在 Development 里删掉旧插件后,重新 **Import plugin from manifest…**。
130
130
  也可把消费方仓库挪出受保护目录(例如 `~/Projects/`)再导入。
131
+
132
+ 6. **Q:** `pnpm exec mini-code-connect-scaffold-plugin --id …` 报 `generate-registry: glob 里没有 *: "--id"`?
133
+ **A:** `0.1.3` 打包把多个 CLI 打进同一文件,导致 `generate-registry` 误跑并把 `--id` 当成 glob。请升级到 **`>=0.1.4`** 后重试。
package/dist/build.mjs CHANGED
@@ -10,10 +10,16 @@ import path4 from "node:path";
10
10
  import { existsSync, readFileSync, realpathSync } from "node:fs";
11
11
  import path from "node:path";
12
12
  import { fileURLToPath } from "node:url";
13
- function isCliEntrypoint(importMetaUrl) {
13
+ function isCliEntrypoint(importMetaUrl, entryName) {
14
14
  if (!process.argv[1]) return false;
15
15
  try {
16
- return realpathSync(process.argv[1]) === realpathSync(fileURLToPath(importMetaUrl));
16
+ const argvPath = realpathSync(process.argv[1]);
17
+ const metaPath = realpathSync(fileURLToPath(importMetaUrl));
18
+ if (argvPath !== metaPath) return false;
19
+ if (entryName) {
20
+ return path.basename(argvPath).includes(entryName);
21
+ }
22
+ return true;
17
23
  } catch {
18
24
  return false;
19
25
  }
@@ -90,7 +96,7 @@ function generateRegistry({ cwd, mappingsGlob, outFile, typesImport = "./types"
90
96
  fs.writeFileSync(outFile, body);
91
97
  return { count: files.length, files };
92
98
  }
93
- if (isCliEntrypoint(import.meta.url)) {
99
+ if (isCliEntrypoint(import.meta.url, "generate-registry")) {
94
100
  const [, , mappingsGlob, outFile] = process.argv;
95
101
  if (!mappingsGlob || !outFile) {
96
102
  console.error("\u7528\u6CD5: node scripts/generate-registry.mjs <mappingsGlob> <outFile>");
@@ -205,7 +211,7 @@ async function buildPlugin({
205
211
  await esbuild.build(uiOpts);
206
212
  return { watching: false };
207
213
  }
208
- if (isCliEntrypoint(import.meta.url)) {
214
+ if (isCliEntrypoint(import.meta.url, "build")) {
209
215
  const args = process.argv.slice(2);
210
216
  const watch = args.includes("--watch");
211
217
  const outIdx = args.indexOf("--out");
@@ -2,7 +2,7 @@
2
2
 
3
3
  // scripts/figma-mapping/index.mjs
4
4
  import fs4 from "node:fs";
5
- import path4 from "node:path";
5
+ import path5 from "node:path";
6
6
  import readline from "node:readline/promises";
7
7
  import { stdin, stdout } from "node:process";
8
8
 
@@ -215,19 +215,26 @@ function toImportSpecifier(relPath, importPaths) {
215
215
 
216
216
  // scripts/figma-mapping/registry.mjs
217
217
  import fs3 from "node:fs";
218
- import path3 from "node:path";
218
+ import path4 from "node:path";
219
219
 
220
220
  // scripts/generate-registry.mjs
221
221
  import fs2 from "node:fs";
222
- import path2 from "node:path";
222
+ import path3 from "node:path";
223
223
 
224
224
  // scripts/is-cli-entrypoint.mjs
225
225
  import { existsSync, readFileSync, realpathSync } from "node:fs";
226
+ import path2 from "node:path";
226
227
  import { fileURLToPath } from "node:url";
227
- function isCliEntrypoint(importMetaUrl) {
228
+ function isCliEntrypoint(importMetaUrl, entryName) {
228
229
  if (!process.argv[1]) return false;
229
230
  try {
230
- return realpathSync(process.argv[1]) === realpathSync(fileURLToPath(importMetaUrl));
231
+ const argvPath = realpathSync(process.argv[1]);
232
+ const metaPath = realpathSync(fileURLToPath(importMetaUrl));
233
+ if (argvPath !== metaPath) return false;
234
+ if (entryName) {
235
+ return path2.basename(argvPath).includes(entryName);
236
+ }
237
+ return true;
231
238
  } catch {
232
239
  return false;
233
240
  }
@@ -247,7 +254,7 @@ function findFigmaFiles(dir, recursive) {
247
254
  if (!fs2.existsSync(d)) return;
248
255
  for (const entry of fs2.readdirSync(d, { withFileTypes: true })) {
249
256
  if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
250
- const full = path2.join(d, entry.name);
257
+ const full = path3.join(d, entry.name);
251
258
  if (entry.isDirectory()) {
252
259
  if (recursive) walk(full);
253
260
  } else if (entry.name.endsWith(".figma.ts")) {
@@ -259,19 +266,19 @@ function findFigmaFiles(dir, recursive) {
259
266
  return results.sort();
260
267
  }
261
268
  function identifierFor(filePath, index) {
262
- const base = path2.basename(filePath).replace(/\.figma\.ts$/, "").replace(/[^a-zA-Z0-9]/g, "");
269
+ const base = path3.basename(filePath).replace(/\.figma\.ts$/, "").replace(/[^a-zA-Z0-9]/g, "");
263
270
  const safe = base && /^[a-zA-Z_]/.test(base) ? base : `M${base}`;
264
271
  return `${safe || "Mapping"}_${index}`;
265
272
  }
266
273
  function generateRegistry({ cwd, mappingsGlob, outFile, typesImport = "./types" }) {
267
274
  const { dir, recursive } = parseGlob(mappingsGlob);
268
- const files = findFigmaFiles(path2.resolve(cwd, dir), recursive);
269
- const outDir = path2.dirname(outFile);
275
+ const files = findFigmaFiles(path3.resolve(cwd, dir), recursive);
276
+ const outDir = path3.dirname(outFile);
270
277
  const imports = files.map((f, i) => {
271
278
  const id = identifierFor(f, i);
272
- let rel = path2.relative(outDir, f).replace(/\.ts$/, "");
279
+ let rel = path3.relative(outDir, f).replace(/\.ts$/, "");
273
280
  if (!rel.startsWith(".")) rel = `./${rel}`;
274
- rel = rel.split(path2.sep).join("/");
281
+ rel = rel.split(path3.sep).join("/");
275
282
  return { id, importPath: rel };
276
283
  });
277
284
  const typeLine = typesImport == null ? "" : `import type { Template } from '${typesImport}'
@@ -284,13 +291,13 @@ function generateRegistry({ cwd, mappingsGlob, outFile, typesImport = "./types"
284
291
  fs2.writeFileSync(outFile, body);
285
292
  return { count: files.length, files };
286
293
  }
287
- if (isCliEntrypoint(import.meta.url)) {
294
+ if (isCliEntrypoint(import.meta.url, "generate-registry")) {
288
295
  const [, , mappingsGlob, outFile] = process.argv;
289
296
  if (!mappingsGlob || !outFile) {
290
297
  console.error("\u7528\u6CD5: node scripts/generate-registry.mjs <mappingsGlob> <outFile>");
291
298
  process.exit(1);
292
299
  }
293
- const result = generateRegistry({ cwd: process.cwd(), mappingsGlob, outFile: path2.resolve(outFile) });
300
+ const result = generateRegistry({ cwd: process.cwd(), mappingsGlob, outFile: path3.resolve(outFile) });
294
301
  console.log(`[generate-registry] \u5199\u5165 ${result.count} \u6761\u6620\u5C04\u5230 ${outFile}`);
295
302
  }
296
303
 
@@ -298,9 +305,9 @@ if (isCliEntrypoint(import.meta.url)) {
298
305
  function refreshRegistry({
299
306
  cwd,
300
307
  mappingsGlob = "figma-mappings/**/*.figma.ts",
301
- outFile = path3.join(cwd, "figma-plugin-dist/.generated/registry.generated.ts")
308
+ outFile = path4.join(cwd, "figma-plugin-dist/.generated/registry.generated.ts")
302
309
  }) {
303
- fs3.mkdirSync(path3.dirname(outFile), { recursive: true });
310
+ fs3.mkdirSync(path4.dirname(outFile), { recursive: true });
304
311
  const result = generateRegistry({ cwd, mappingsGlob, outFile });
305
312
  return { count: result.count };
306
313
  }
@@ -515,11 +522,11 @@ async function pickLoop(schema, ranked, allFiles, rest, useAi) {
515
522
  if (answer === "s") return processQueue(rest, useAi);
516
523
  if (answer === "m") {
517
524
  const rel = (await ask("\u8F93\u5165\u8DEF\u5F84\uFF08\u76F8\u5BF9\u9879\u76EE\u6839\u76EE\u5F55\uFF0C\u6216\u7EDD\u5BF9\u8DEF\u5F84\uFF09: ")).trim();
518
- if (!fs4.existsSync(path4.resolve(ROOT, rel))) {
525
+ if (!fs4.existsSync(path5.resolve(ROOT, rel))) {
519
526
  console.log("\u6587\u4EF6\u4E0D\u5B58\u5728\uFF0C\u91CD\u6765\u3002\n");
520
527
  return pickLoop(schema, ranked, allFiles, rest, useAi);
521
528
  }
522
- return confirmAndGenerate(schema, path4.relative(ROOT, path4.resolve(ROOT, rel)), rest, useAi);
529
+ return confirmAndGenerate(schema, path5.relative(ROOT, path5.resolve(ROOT, rel)), rest, useAi);
523
530
  }
524
531
  const idx = Number(answer);
525
532
  if (Number.isInteger(idx) && idx >= 1 && idx <= top.length) {
@@ -535,7 +542,7 @@ async function pickLoop(schema, ranked, allFiles, rest, useAi) {
535
542
  }
536
543
  async function confirmAndGenerate(schema, relPath, rest, useAi) {
537
544
  const info = extractComponentInfo(relPath);
538
- const componentName = info.names.find((n) => n.toLowerCase() === path4.basename(relPath, ".ts").toLowerCase()) ?? info.names[0] ?? path4.basename(relPath, ".ts");
545
+ const componentName = info.names.find((n) => n.toLowerCase() === path5.basename(relPath, ".ts").toLowerCase()) ?? info.names[0] ?? path5.basename(relPath, ".ts");
539
546
  console.log(`
540
547
  \u9009\u4E2D: ${relPath}`);
541
548
  console.log(`\u8BC6\u522B\u5230\u7684\u5BFC\u51FA: ${info.names.join(", ") || "\uFF08\u6CA1\u627E\u5230 export \u7684\u7EC4\u4EF6\u540D\uFF0C\u4F1A\u7528\u6587\u4EF6\u540D\u515C\u5E95\uFF09"}`);
@@ -573,11 +580,11 @@ async function confirmAndGenerate(schema, relPath, rest, useAi) {
573
580
  }
574
581
  async function writeMappingFile(schema, content, rest, useAi) {
575
582
  const safeName = schema.componentName.replace(/[^a-zA-Z0-9]+/g, "") || "Component";
576
- const defaultOut = path4.relative(ROOT, path4.join(MAPPINGS_DIR, `${safeName}.figma.ts`));
583
+ const defaultOut = path5.relative(ROOT, path5.join(MAPPINGS_DIR, `${safeName}.figma.ts`));
577
584
  const outInput = (await ask(`\u4FDD\u5B58\u5230\u54EA [\u56DE\u8F66\u7528 "${defaultOut}"]: `)).trim();
578
585
  const outRel = outInput || defaultOut;
579
- const outAbs = path4.resolve(ROOT, outRel);
580
- if (!outAbs.startsWith(ROOT + path4.sep)) {
586
+ const outAbs = path5.resolve(ROOT, outRel);
587
+ if (!outAbs.startsWith(ROOT + path5.sep)) {
581
588
  console.log(`\u62D2\u7EDD\u5199\u5165\uFF1A${outAbs} \u5728\u9879\u76EE\u6839\u76EE\u5F55\u4E4B\u5916\uFF0C\u8FD9\u4E2A\u811A\u672C\u53EA\u5141\u8BB8\u5F80 ${ROOT} \u91CC\u5199\u3002\u8DF3\u8FC7\u8FD9\u4E2A\u7EC4\u4EF6\u3002
582
589
  `);
583
590
  return processQueue(rest, useAi);
@@ -589,7 +596,7 @@ async function writeMappingFile(schema, content, rest, useAi) {
589
596
  return processQueue(rest, useAi);
590
597
  }
591
598
  }
592
- fs4.mkdirSync(path4.dirname(outAbs), { recursive: true });
599
+ fs4.mkdirSync(path5.dirname(outAbs), { recursive: true });
593
600
  fs4.writeFileSync(outAbs, content);
594
601
  console.log(`
595
602
  \u5DF2\u5199\u5165 ${outRel}`);
@@ -1,14 +1,21 @@
1
1
  // scripts/generate-registry.mjs
2
2
  import fs from "node:fs";
3
- import path from "node:path";
3
+ import path2 from "node:path";
4
4
 
5
5
  // scripts/is-cli-entrypoint.mjs
6
6
  import { existsSync, readFileSync, realpathSync } from "node:fs";
7
+ import path from "node:path";
7
8
  import { fileURLToPath } from "node:url";
8
- function isCliEntrypoint(importMetaUrl) {
9
+ function isCliEntrypoint(importMetaUrl, entryName) {
9
10
  if (!process.argv[1]) return false;
10
11
  try {
11
- return realpathSync(process.argv[1]) === realpathSync(fileURLToPath(importMetaUrl));
12
+ const argvPath = realpathSync(process.argv[1]);
13
+ const metaPath = realpathSync(fileURLToPath(importMetaUrl));
14
+ if (argvPath !== metaPath) return false;
15
+ if (entryName) {
16
+ return path.basename(argvPath).includes(entryName);
17
+ }
18
+ return true;
12
19
  } catch {
13
20
  return false;
14
21
  }
@@ -28,7 +35,7 @@ function findFigmaFiles(dir, recursive) {
28
35
  if (!fs.existsSync(d)) return;
29
36
  for (const entry of fs.readdirSync(d, { withFileTypes: true })) {
30
37
  if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
31
- const full = path.join(d, entry.name);
38
+ const full = path2.join(d, entry.name);
32
39
  if (entry.isDirectory()) {
33
40
  if (recursive) walk(full);
34
41
  } else if (entry.name.endsWith(".figma.ts")) {
@@ -40,19 +47,19 @@ function findFigmaFiles(dir, recursive) {
40
47
  return results.sort();
41
48
  }
42
49
  function identifierFor(filePath, index) {
43
- const base = path.basename(filePath).replace(/\.figma\.ts$/, "").replace(/[^a-zA-Z0-9]/g, "");
50
+ const base = path2.basename(filePath).replace(/\.figma\.ts$/, "").replace(/[^a-zA-Z0-9]/g, "");
44
51
  const safe = base && /^[a-zA-Z_]/.test(base) ? base : `M${base}`;
45
52
  return `${safe || "Mapping"}_${index}`;
46
53
  }
47
54
  function generateRegistry({ cwd, mappingsGlob, outFile, typesImport = "./types" }) {
48
55
  const { dir, recursive } = parseGlob(mappingsGlob);
49
- const files = findFigmaFiles(path.resolve(cwd, dir), recursive);
50
- const outDir = path.dirname(outFile);
56
+ const files = findFigmaFiles(path2.resolve(cwd, dir), recursive);
57
+ const outDir = path2.dirname(outFile);
51
58
  const imports = files.map((f, i) => {
52
59
  const id = identifierFor(f, i);
53
- let rel = path.relative(outDir, f).replace(/\.ts$/, "");
60
+ let rel = path2.relative(outDir, f).replace(/\.ts$/, "");
54
61
  if (!rel.startsWith(".")) rel = `./${rel}`;
55
- rel = rel.split(path.sep).join("/");
62
+ rel = rel.split(path2.sep).join("/");
56
63
  return { id, importPath: rel };
57
64
  });
58
65
  const typeLine = typesImport == null ? "" : `import type { Template } from '${typesImport}'
@@ -65,13 +72,13 @@ function generateRegistry({ cwd, mappingsGlob, outFile, typesImport = "./types"
65
72
  fs.writeFileSync(outFile, body);
66
73
  return { count: files.length, files };
67
74
  }
68
- if (isCliEntrypoint(import.meta.url)) {
75
+ if (isCliEntrypoint(import.meta.url, "generate-registry")) {
69
76
  const [, , mappingsGlob, outFile] = process.argv;
70
77
  if (!mappingsGlob || !outFile) {
71
78
  console.error("\u7528\u6CD5: node scripts/generate-registry.mjs <mappingsGlob> <outFile>");
72
79
  process.exit(1);
73
80
  }
74
- const result = generateRegistry({ cwd: process.cwd(), mappingsGlob, outFile: path.resolve(outFile) });
81
+ const result = generateRegistry({ cwd: process.cwd(), mappingsGlob, outFile: path2.resolve(outFile) });
75
82
  console.log(`[generate-registry] \u5199\u5165 ${result.count} \u6761\u6620\u5C04\u5230 ${outFile}`);
76
83
  }
77
84
  export {
@@ -8,10 +8,16 @@ import path2 from "node:path";
8
8
  import { existsSync, readFileSync, realpathSync } from "node:fs";
9
9
  import path from "node:path";
10
10
  import { fileURLToPath } from "node:url";
11
- function isCliEntrypoint(importMetaUrl) {
11
+ function isCliEntrypoint(importMetaUrl, entryName) {
12
12
  if (!process.argv[1]) return false;
13
13
  try {
14
- return realpathSync(process.argv[1]) === realpathSync(fileURLToPath(importMetaUrl));
14
+ const argvPath = realpathSync(process.argv[1]);
15
+ const metaPath = realpathSync(fileURLToPath(importMetaUrl));
16
+ if (argvPath !== metaPath) return false;
17
+ if (entryName) {
18
+ return path.basename(argvPath).includes(entryName);
19
+ }
20
+ return true;
15
21
  } catch {
16
22
  return false;
17
23
  }
@@ -67,7 +73,7 @@ function installSkill({ cwd, root, force = false, claudeMirror = true }) {
67
73
  }
68
74
  return { results, root: base };
69
75
  }
70
- if (isCliEntrypoint(import.meta.url)) {
76
+ if (isCliEntrypoint(import.meta.url, "install-skill")) {
71
77
  const args = process.argv.slice(2);
72
78
  const force = args.includes("--force");
73
79
  const noClaudeMirror = args.includes("--no-claude-mirror");
@@ -2,22 +2,29 @@
2
2
 
3
3
  // scripts/scaffold-manifest.mjs
4
4
  import fs from "node:fs";
5
- import path from "node:path";
5
+ import path2 from "node:path";
6
6
 
7
7
  // scripts/is-cli-entrypoint.mjs
8
8
  import { existsSync, readFileSync, realpathSync } from "node:fs";
9
+ import path from "node:path";
9
10
  import { fileURLToPath } from "node:url";
10
- function isCliEntrypoint(importMetaUrl) {
11
+ function isCliEntrypoint(importMetaUrl, entryName) {
11
12
  if (!process.argv[1]) return false;
12
13
  try {
13
- return realpathSync(process.argv[1]) === realpathSync(fileURLToPath(importMetaUrl));
14
+ const argvPath = realpathSync(process.argv[1]);
15
+ const metaPath = realpathSync(fileURLToPath(importMetaUrl));
16
+ if (argvPath !== metaPath) return false;
17
+ if (entryName) {
18
+ return path.basename(argvPath).includes(entryName);
19
+ }
20
+ return true;
14
21
  } catch {
15
22
  return false;
16
23
  }
17
24
  }
18
25
 
19
26
  // scripts/scaffold-manifest.mjs
20
- function scaffoldManifest({ cwd, name = "Mini Code Connect", id, outDir = "dist" }) {
27
+ function scaffoldManifest({ cwd, name = "Mini Code Connect", id, outDir = "dist", force = false }) {
21
28
  if (!id) throw new Error("scaffoldManifest: id \u5FC5\u586B");
22
29
  const panel = {
23
30
  name,
@@ -47,8 +54,8 @@ function scaffoldManifest({ cwd, name = "Mini Code Connect", id, outDir = "dist"
47
54
  ["manifest.json", panel],
48
55
  ["manifest.codegen.json", codegen]
49
56
  ]) {
50
- const target = path.join(cwd, file);
51
- if (fs.existsSync(target)) {
57
+ const target = path2.join(cwd, file);
58
+ if (fs.existsSync(target) && !force) {
52
59
  results.push({ target, skipped: true });
53
60
  continue;
54
61
  }
@@ -57,7 +64,7 @@ function scaffoldManifest({ cwd, name = "Mini Code Connect", id, outDir = "dist"
57
64
  }
58
65
  return { results };
59
66
  }
60
- if (isCliEntrypoint(import.meta.url)) {
67
+ if (isCliEntrypoint(import.meta.url, "scaffold-manifest")) {
61
68
  const args = process.argv.slice(2);
62
69
  const get = (flag) => {
63
70
  const i = args.indexOf(flag);
@@ -67,10 +74,18 @@ if (isCliEntrypoint(import.meta.url)) {
67
74
  const id = get("--id");
68
75
  const outDir = get("--out") ?? "dist";
69
76
  if (!id) {
70
- console.error('\u7528\u6CD5: node scripts/scaffold-manifest.mjs --id <manifest-id> [--name "<\u9762\u677F\u663E\u793A\u540D>"] [--out dist]');
77
+ console.error(
78
+ '\u7528\u6CD5: node scripts/scaffold-manifest.mjs --id <manifest-id> [--name "<\u9762\u677F\u663E\u793A\u540D>"] [--out dist] [--force]'
79
+ );
71
80
  process.exit(1);
72
81
  }
73
- const { results } = scaffoldManifest({ cwd: process.cwd(), name, id, outDir });
82
+ const { results } = scaffoldManifest({
83
+ cwd: process.cwd(),
84
+ name,
85
+ id,
86
+ outDir,
87
+ force: args.includes("--force")
88
+ });
74
89
  for (const r of results) {
75
90
  console.log(r.skipped ? `[scaffold-manifest] \u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7\uFF1A${r.target}` : `[scaffold-manifest] \u5DF2\u5199\u5165\uFF1A${r.target}`);
76
91
  }
@@ -12,10 +12,16 @@ import path2 from "node:path";
12
12
  import { existsSync, readFileSync, realpathSync } from "node:fs";
13
13
  import path from "node:path";
14
14
  import { fileURLToPath } from "node:url";
15
- function isCliEntrypoint(importMetaUrl) {
15
+ function isCliEntrypoint(importMetaUrl, entryName) {
16
16
  if (!process.argv[1]) return false;
17
17
  try {
18
- return realpathSync(process.argv[1]) === realpathSync(fileURLToPath(importMetaUrl));
18
+ const argvPath = realpathSync(process.argv[1]);
19
+ const metaPath = realpathSync(fileURLToPath(importMetaUrl));
20
+ if (argvPath !== metaPath) return false;
21
+ if (entryName) {
22
+ return path.basename(argvPath).includes(entryName);
23
+ }
24
+ return true;
19
25
  } catch {
20
26
  return false;
21
27
  }
@@ -71,7 +77,7 @@ function installSkill({ cwd, root, force = false, claudeMirror = true }) {
71
77
  }
72
78
  return { results, root: base };
73
79
  }
74
- if (isCliEntrypoint(import.meta.url)) {
80
+ if (isCliEntrypoint(import.meta.url, "install-skill")) {
75
81
  const args = process.argv.slice(2);
76
82
  const force = args.includes("--force");
77
83
  const noClaudeMirror = args.includes("--no-claude-mirror");
@@ -88,7 +94,7 @@ if (isCliEntrypoint(import.meta.url)) {
88
94
  // scripts/scaffold-manifest.mjs
89
95
  import fs2 from "node:fs";
90
96
  import path3 from "node:path";
91
- function scaffoldManifest({ cwd, name = "Mini Code Connect", id, outDir = "dist" }) {
97
+ function scaffoldManifest({ cwd, name = "Mini Code Connect", id, outDir = "dist", force = false }) {
92
98
  if (!id) throw new Error("scaffoldManifest: id \u5FC5\u586B");
93
99
  const panel = {
94
100
  name,
@@ -119,7 +125,7 @@ function scaffoldManifest({ cwd, name = "Mini Code Connect", id, outDir = "dist"
119
125
  ["manifest.codegen.json", codegen]
120
126
  ]) {
121
127
  const target = path3.join(cwd, file);
122
- if (fs2.existsSync(target)) {
128
+ if (fs2.existsSync(target) && !force) {
123
129
  results.push({ target, skipped: true });
124
130
  continue;
125
131
  }
@@ -128,7 +134,7 @@ function scaffoldManifest({ cwd, name = "Mini Code Connect", id, outDir = "dist"
128
134
  }
129
135
  return { results };
130
136
  }
131
- if (isCliEntrypoint(import.meta.url)) {
137
+ if (isCliEntrypoint(import.meta.url, "scaffold-manifest")) {
132
138
  const args = process.argv.slice(2);
133
139
  const get = (flag) => {
134
140
  const i = args.indexOf(flag);
@@ -138,10 +144,18 @@ if (isCliEntrypoint(import.meta.url)) {
138
144
  const id = get("--id");
139
145
  const outDir = get("--out") ?? "dist";
140
146
  if (!id) {
141
- console.error('\u7528\u6CD5: node scripts/scaffold-manifest.mjs --id <manifest-id> [--name "<\u9762\u677F\u663E\u793A\u540D>"] [--out dist]');
147
+ console.error(
148
+ '\u7528\u6CD5: node scripts/scaffold-manifest.mjs --id <manifest-id> [--name "<\u9762\u677F\u663E\u793A\u540D>"] [--out dist] [--force]'
149
+ );
142
150
  process.exit(1);
143
151
  }
144
- const { results } = scaffoldManifest({ cwd: process.cwd(), name, id, outDir });
152
+ const { results } = scaffoldManifest({
153
+ cwd: process.cwd(),
154
+ name,
155
+ id,
156
+ outDir,
157
+ force: args.includes("--force")
158
+ });
145
159
  for (const r of results) {
146
160
  console.log(r.skipped ? `[scaffold-manifest] \u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7\uFF1A${r.target}` : `[scaffold-manifest] \u5DF2\u5199\u5165\uFF1A${r.target}`);
147
161
  }
@@ -206,7 +220,7 @@ function generateRegistry({ cwd, mappingsGlob, outFile, typesImport = "./types"
206
220
  fs3.writeFileSync(outFile, body);
207
221
  return { count: files.length, files };
208
222
  }
209
- if (isCliEntrypoint(import.meta.url)) {
223
+ if (isCliEntrypoint(import.meta.url, "generate-registry")) {
210
224
  const [, , mappingsGlob, outFile] = process.argv;
211
225
  if (!mappingsGlob || !outFile) {
212
226
  console.error("\u7528\u6CD5: node scripts/generate-registry.mjs <mappingsGlob> <outFile>");
@@ -321,7 +335,7 @@ async function buildPlugin({
321
335
  await esbuild.build(uiOpts);
322
336
  return { watching: false };
323
337
  }
324
- if (isCliEntrypoint(import.meta.url)) {
338
+ if (isCliEntrypoint(import.meta.url, "build")) {
325
339
  const args = process.argv.slice(2);
326
340
  const watch = args.includes("--watch");
327
341
  const outIdx = args.indexOf("--out");
@@ -363,7 +377,7 @@ async function scaffoldPlugin({
363
377
  fs5.writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n");
364
378
  steps.push({ step: "config", target: configPath, skipped: false });
365
379
  }
366
- const manifest = scaffoldManifest({ cwd, name, id, outDir });
380
+ const manifest = scaffoldManifest({ cwd, name, id, outDir, force });
367
381
  steps.push({ step: "manifest", ...manifest });
368
382
  const buildScriptPath = path7.join(cwd, "scripts/build-figma-plugin.mjs");
369
383
  if (fs5.existsSync(buildScriptPath) && !force) {
@@ -420,7 +434,7 @@ ${ignoreEntry}
420
434
  steps.push({ step: "build", target: path7.join(cwd, outDir), skipped: false });
421
435
  return { steps };
422
436
  }
423
- if (isCliEntrypoint(import.meta.url)) {
437
+ if (isCliEntrypoint(import.meta.url, "scaffold-plugin")) {
424
438
  const args = process.argv.slice(2);
425
439
  const get = (flag, fallback) => {
426
440
  const i = args.indexOf(flag);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mini-figma-code-connect",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "type": "module",
5
5
  "description": "Local Code Connect for Figma Professional — 无 Org 也能做确定性的 f(instance) → snippet。",
6
6
  "license": "UNLICENSED",