mini-figma-code-connect 0.1.3 → 0.1.4
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 +4 -1
- package/dist/build.mjs +10 -4
- package/dist/figma-mapping.mjs +29 -22
- package/dist/generate-registry.mjs +18 -11
- package/dist/install-skill.mjs +9 -3
- package/dist/scaffold-manifest.mjs +12 -5
- package/dist/scaffold-plugin.mjs +13 -7
- package/package.json +1 -1
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
|
-
|
|
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
|
-
|
|
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");
|
package/dist/figma-mapping.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// scripts/figma-mapping/index.mjs
|
|
4
4
|
import fs4 from "node:fs";
|
|
5
|
-
import
|
|
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
|
|
218
|
+
import path4 from "node:path";
|
|
219
219
|
|
|
220
220
|
// scripts/generate-registry.mjs
|
|
221
221
|
import fs2 from "node:fs";
|
|
222
|
-
import
|
|
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
|
-
|
|
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 =
|
|
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 =
|
|
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(
|
|
269
|
-
const outDir =
|
|
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 =
|
|
279
|
+
let rel = path3.relative(outDir, f).replace(/\.ts$/, "");
|
|
273
280
|
if (!rel.startsWith(".")) rel = `./${rel}`;
|
|
274
|
-
rel = rel.split(
|
|
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:
|
|
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 =
|
|
308
|
+
outFile = path4.join(cwd, "figma-plugin-dist/.generated/registry.generated.ts")
|
|
302
309
|
}) {
|
|
303
|
-
fs3.mkdirSync(
|
|
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(
|
|
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,
|
|
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() ===
|
|
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 =
|
|
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 =
|
|
580
|
-
if (!outAbs.startsWith(ROOT +
|
|
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(
|
|
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
|
|
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
|
-
|
|
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 =
|
|
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 =
|
|
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(
|
|
50
|
-
const outDir =
|
|
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 =
|
|
60
|
+
let rel = path2.relative(outDir, f).replace(/\.ts$/, "");
|
|
54
61
|
if (!rel.startsWith(".")) rel = `./${rel}`;
|
|
55
|
-
rel = rel.split(
|
|
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:
|
|
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 {
|
package/dist/install-skill.mjs
CHANGED
|
@@ -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
|
-
|
|
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,15 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
// scripts/scaffold-manifest.mjs
|
|
4
4
|
import fs from "node:fs";
|
|
5
|
-
import
|
|
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
|
-
|
|
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
|
}
|
|
@@ -47,7 +54,7 @@ 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 =
|
|
57
|
+
const target = path2.join(cwd, file);
|
|
51
58
|
if (fs.existsSync(target)) {
|
|
52
59
|
results.push({ target, skipped: true });
|
|
53
60
|
continue;
|
|
@@ -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);
|
package/dist/scaffold-plugin.mjs
CHANGED
|
@@ -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
|
-
|
|
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");
|
|
@@ -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);
|
|
@@ -206,7 +212,7 @@ function generateRegistry({ cwd, mappingsGlob, outFile, typesImport = "./types"
|
|
|
206
212
|
fs3.writeFileSync(outFile, body);
|
|
207
213
|
return { count: files.length, files };
|
|
208
214
|
}
|
|
209
|
-
if (isCliEntrypoint(import.meta.url)) {
|
|
215
|
+
if (isCliEntrypoint(import.meta.url, "generate-registry")) {
|
|
210
216
|
const [, , mappingsGlob, outFile] = process.argv;
|
|
211
217
|
if (!mappingsGlob || !outFile) {
|
|
212
218
|
console.error("\u7528\u6CD5: node scripts/generate-registry.mjs <mappingsGlob> <outFile>");
|
|
@@ -321,7 +327,7 @@ async function buildPlugin({
|
|
|
321
327
|
await esbuild.build(uiOpts);
|
|
322
328
|
return { watching: false };
|
|
323
329
|
}
|
|
324
|
-
if (isCliEntrypoint(import.meta.url)) {
|
|
330
|
+
if (isCliEntrypoint(import.meta.url, "build")) {
|
|
325
331
|
const args = process.argv.slice(2);
|
|
326
332
|
const watch = args.includes("--watch");
|
|
327
333
|
const outIdx = args.indexOf("--out");
|
|
@@ -420,7 +426,7 @@ ${ignoreEntry}
|
|
|
420
426
|
steps.push({ step: "build", target: path7.join(cwd, outDir), skipped: false });
|
|
421
427
|
return { steps };
|
|
422
428
|
}
|
|
423
|
-
if (isCliEntrypoint(import.meta.url)) {
|
|
429
|
+
if (isCliEntrypoint(import.meta.url, "scaffold-plugin")) {
|
|
424
430
|
const args = process.argv.slice(2);
|
|
425
431
|
const get = (flag, fallback) => {
|
|
426
432
|
const i = args.indexOf(flag);
|