@tu-design/cli 0.5.9 → 0.5.11
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/dist/index.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { Command } from "commander";
|
|
|
6
6
|
import picocolors from "picocolors";
|
|
7
7
|
import { dirname, join } from "node:path";
|
|
8
8
|
import { createHash } from "node:crypto";
|
|
9
|
-
|
|
9
|
+
// src/io/node.ts
|
|
10
10
|
const nodeIo = {
|
|
11
11
|
exists: (path) => existsSync(path),
|
|
12
12
|
readFile: (path) => readFileSync(path, "utf8"),
|
|
@@ -35,8 +35,7 @@ function npmItemPath(name) {
|
|
|
35
35
|
const pkgJson = createRequire(import.meta.url).resolve("@tu-design/vue/package.json");
|
|
36
36
|
return join(dirname(pkgJson), "dist/registry/vue", `${name}.json`);
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
//#region src/lib/json.ts
|
|
38
|
+
// src/lib/json.ts
|
|
40
39
|
/**
|
|
41
40
|
* 统一 JSON 解析报错:裸 SyntaxError 不含文件名,用户无从下手;这里补上来源。
|
|
42
41
|
* label 用面向用户的文件名(如 `components.json`),而不是绝对路径。
|
|
@@ -52,8 +51,7 @@ function parseJson(text, label) {
|
|
|
52
51
|
throw new Error(`${label} 不是合法 JSON:${reason}`);
|
|
53
52
|
}
|
|
54
53
|
}
|
|
55
|
-
|
|
56
|
-
//#region src/lib/config.ts
|
|
54
|
+
// src/lib/config.ts
|
|
57
55
|
/** init 未显式传 --registry 时写入 components.json 的默认 URL 通道(不可达时 add 走 npm 兜底)。 */
|
|
58
56
|
const DEFAULT_REGISTRY = "https://gopowerteam.github.io/tu-design/r/vue";
|
|
59
57
|
const CONFIG_FILE = "components.json";
|
|
@@ -131,8 +129,7 @@ function loadConfig(io, cwd) {
|
|
|
131
129
|
function saveConfig(io, cwd, config) {
|
|
132
130
|
io.writeFile(configPath(cwd), `${JSON.stringify(config, null, 2)}\n`);
|
|
133
131
|
}
|
|
134
|
-
|
|
135
|
-
//#region src/lib/ai-rules.ts
|
|
132
|
+
// src/lib/ai-rules.ts
|
|
136
133
|
/**
|
|
137
134
|
* init 注入到用户项目根目录 AGENTS.md 的 AI 协作规则。
|
|
138
135
|
* 目的:让 AI 编码代理遵循 tu-design 的组件安装 / 导入 / 主题约定,
|
|
@@ -162,12 +159,10 @@ const AGENTS_MD_SOURCE = `# tu-design AI 协作规则
|
|
|
162
159
|
- 完整组件清单:https://gopowerteam.github.io/tu-design/llms.txt(可整页抓取给 AI)
|
|
163
160
|
- 全量文档:https://gopowerteam.github.io/tu-design/llms-full.txt(可整页抓取给 AI)
|
|
164
161
|
`;
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
const TOKENS_CSS_SOURCE = "/* tu-design 官方 tokens —— Tailwind CSS v4 主题(shadcn v4 集合扩展)。\n *\n * 主题桥接:语义色优先消费应用级 --app-* CSS 变量(应用主题系统写入),\n * 未定义时回落官方 oklch 值 —— 无主题系统的项目观感与上游一致,零破坏。\n * 契约(--app-* 全集见各项目主题包,如 @repo/themes):\n * - --app-bg-page/surface/raised/hover → --background/--card/--popover/--muted/--accent\n * - --app-text-1/2/3 → --foreground 及各 *-foreground/--muted-foreground\n * (text-3 上游零消费,供应用侧直接使用)\n * - --app-accent/-contrast → --primary(+foreground)/--ring\n * - --app-border → --border/--input(dark 模式建议低不透明度值,如 #FFFFFF1A,对齐上游风格)\n * - --secondary/-foreground 有意不桥接(上游定位即中性灰)\n * - --app-destructive/success/warning/info → 状态色三件套:实色、-soft 浅底(未定义回落\n * color-mix 派生)、-foreground 前景(深色实色场景如 dark destructive 白字对比 borderline,\n * 建议应用侧显式定义覆盖)\n * - .dark 块同样桥接,兜底为官方暗色 oklch;--*-soft 在 .dark 内重复声明:\n * 自定义属性按声明处求值后继承,不在 .dark 重声明将无法响应暗色的实色变化。\n */\n@import \"tw-animate-css\";\n\n@custom-variant dark (&:where(.dark, .dark *));\n\n:root {\n --background: var(--app-bg-page, oklch(1 0 0));\n --foreground: var(--app-text-1, oklch(0.145 0 0));\n --card: var(--app-bg-raised, oklch(1 0 0));\n --card-foreground: var(--app-text-1, oklch(0.145 0 0));\n --popover: var(--app-bg-raised, oklch(1 0 0));\n --popover-foreground: var(--app-text-1, oklch(0.145 0 0));\n --primary: var(--app-accent, oklch(0.205 0 0));\n --primary-foreground: var(--app-accent-contrast, oklch(0.985 0 0));\n --secondary: oklch(0.97 0 0);\n --secondary-foreground: oklch(0.205 0 0);\n --muted: var(--app-bg-surface, oklch(0.97 0 0));\n --muted-foreground: var(--app-text-2, oklch(0.556 0 0));\n --accent: var(--app-bg-hover, oklch(0.97 0 0));\n --accent-foreground: var(--app-text-1, oklch(0.205 0 0));\n --destructive: var(--app-destructive, oklch(0.577 0.245 27.325));\n --destructive-soft: var(\n --app-destructive-soft,\n color-mix(in oklab, var(--destructive) 10%, transparent)\n );\n --destructive-foreground: var(--app-destructive-foreground, oklch(0.985 0 0));\n --success: var(--app-success, oklch(0.596 0.145 163.225));\n --success-soft: var(--app-success-soft, color-mix(in oklab, var(--success) 10%, transparent));\n --success-foreground: var(--app-success-foreground, oklch(0.985 0 0));\n --warning: var(--app-warning, oklch(0.666 0.179 58.318));\n --warning-soft: var(--app-warning-soft, color-mix(in oklab, var(--warning) 12%, transparent));\n --warning-foreground: var(--app-warning-foreground, oklch(0.985 0 0));\n --info: var(--app-info, oklch(0.546 0.245 262.881));\n --info-soft: var(--app-info-soft, color-mix(in oklab, var(--info) 12%, transparent));\n --info-foreground: var(--app-info-foreground, oklch(0.985 0 0));\n --border: var(--app-border, oklch(0.922 0 0));\n --input: var(--app-border, oklch(0.922 0 0));\n --ring: var(--app-accent, oklch(0.708 0 0));\n --radius: 0.625rem;\n /* 层叠序:表体 sticky < 表头普通列 sticky(fill/virtual 表头钉住,z-20 由 TableRender theadThClass 提供)\n < 表头 sticky < 浮层/弹窗(同级浮层按 DOM 挂载次序叠放;表头 fixed 列经 stickyStyle inline style 消费 --z-sticky-head) */\n --z-sticky: 10;\n --z-sticky-head: 30;\n --z-overlay: 50;\n}\n\n.dark {\n --background: var(--app-bg-page, oklch(0.145 0 0));\n --foreground: var(--app-text-1, oklch(0.985 0 0));\n --card: var(--app-bg-raised, oklch(0.205 0 0));\n --card-foreground: var(--app-text-1, oklch(0.985 0 0));\n --popover: var(--app-bg-raised, oklch(0.269 0 0));\n --popover-foreground: var(--app-text-1, oklch(0.985 0 0));\n --primary: var(--app-accent, oklch(0.922 0 0));\n --primary-foreground: var(--app-accent-contrast, oklch(0.205 0 0));\n --secondary: oklch(0.269 0 0);\n --secondary-foreground: oklch(0.985 0 0);\n --muted: var(--app-bg-surface, oklch(0.269 0 0));\n --muted-foreground: var(--app-text-2, oklch(0.708 0 0));\n --accent: var(--app-bg-hover, oklch(0.371 0 0));\n --accent-foreground: var(--app-text-1, oklch(0.985 0 0));\n --destructive: var(--app-destructive, oklch(0.704 0.191 22.216));\n --destructive-soft: var(\n --app-destructive-soft,\n color-mix(in oklab, var(--destructive) 10%, transparent)\n );\n --destructive-foreground: var(--app-destructive-foreground, oklch(0.985 0 0));\n --success: var(--app-success, oklch(0.696 0.17 162.48));\n --success-soft: var(--app-success-soft, color-mix(in oklab, var(--success) 10%, transparent));\n --success-foreground: var(--app-success-foreground, oklch(0.985 0 0));\n --warning: var(--app-warning, oklch(0.769 0.188 70.08));\n --warning-soft: var(--app-warning-soft, color-mix(in oklab, var(--warning) 12%, transparent));\n --warning-foreground: var(--app-warning-foreground, oklch(0.205 0 0));\n --info: var(--app-info, oklch(0.623 0.214 259.815));\n --info-soft: var(--app-info-soft, color-mix(in oklab, var(--info) 12%, transparent));\n --info-foreground: var(--app-info-foreground, oklch(0.985 0 0));\n --border: var(--app-border, oklch(1 0 0 / 10%));\n --input: var(--app-border, oklch(1 0 0 / 15%));\n --ring: var(--app-accent, oklch(0.556 0 0));\n}\n\n@theme inline {\n --radius-sm: calc(var(--radius) - 4px);\n --radius-md: calc(var(--radius) - 2px);\n --radius-lg: var(--radius);\n --radius-xl: calc(var(--radius) + 4px);\n --radius-2xl: calc(var(--radius) + 6px);\n --color-background: var(--background);\n --color-foreground: var(--foreground);\n --color-card: var(--card);\n --color-card-foreground: var(--card-foreground);\n --color-popover: var(--popover);\n --color-popover-foreground: var(--popover-foreground);\n --color-primary: var(--primary);\n --color-primary-foreground: var(--primary-foreground);\n --color-secondary: var(--secondary);\n --color-secondary-foreground: var(--secondary-foreground);\n --color-muted: var(--muted);\n --color-muted-foreground: var(--muted-foreground);\n --color-accent: var(--accent);\n --color-accent-foreground: var(--accent-foreground);\n --color-destructive: var(--destructive);\n --color-destructive-soft: var(--destructive-soft);\n --color-destructive-foreground: var(--destructive-foreground);\n --color-success: var(--success);\n --color-success-foreground: var(--success-foreground);\n --color-success-soft: var(--success-soft);\n --color-warning: var(--warning);\n --color-warning-foreground: var(--warning-foreground);\n --color-warning-soft: var(--warning-soft);\n --color-info: var(--info);\n --color-info-foreground: var(--info-foreground);\n --color-info-soft: var(--info-soft);\n --color-border: var(--border);\n --color-input: var(--input);\n --color-ring: var(--ring);\n}\n\n/* 全局边框色兜底,对齐 shadcn v4 官方 tokens(上游另含 outline-ring/50,此处仅移植 border):\n 裸 border 类不再回退 currentColor,而是使用 --border token。 */\n@layer base {\n * {\n border-color: var(--color-border);\n }\n}\n";
|
|
162
|
+
// src/lib/generated-sources.ts
|
|
163
|
+
const TOKENS_CSS_SOURCE = "/* tu-design 官方 tokens —— Tailwind CSS v4 主题(shadcn v4 集合扩展)。\n *\n * 主题桥接:语义色优先消费应用级 --app-* CSS 变量(应用主题系统写入),\n * 未定义时回落官方 oklch 值 —— 无主题系统的项目观感与上游一致,零破坏。\n * 契约(--app-* 全集见各项目主题包,如 @repo/themes):\n * - --app-bg-page → --background(页面画布底;模态面板不消费此位)\n * - --app-bg-surface → --muted(弱化背景)与 --dialog(模态面板表面)双消费\n * - --app-bg-raised → --card、--popover(浮起表面)\n * - --app-bg-hover → --accent(hover 强调背景)\n * - --app-text-1/2/3 → --foreground 及各 *-foreground/--muted-foreground\n * (text-3 上游零消费,供应用侧直接使用)\n * - --app-accent/-contrast → --primary(+foreground)/--ring\n * - --app-border → --border/--input(dark 模式建议低不透明度值,如 #FFFFFF1A,对齐上游风格)\n * - --secondary/-foreground 有意不桥接(上游定位即中性灰)\n * - --app-destructive/success/warning/info → 状态色三件套:实色、-soft 浅底(未定义回落\n * color-mix 派生)、-foreground 前景(深色实色场景如 dark destructive 白字对比 borderline,\n * 建议应用侧显式定义覆盖)\n * - .dark 块同样桥接,兜底为官方暗色 oklch;--*-soft 在 .dark 内重复声明:\n * 自定义属性按声明处求值后继承,不在 .dark 重声明将无法响应暗色的实色变化。\n */\n@import \"tw-animate-css\";\n\n@custom-variant dark (&:where(.dark, .dark *));\n\n:root {\n --background: var(--app-bg-page, oklch(1 0 0));\n --foreground: var(--app-text-1, oklch(0.145 0 0));\n --card: var(--app-bg-raised, oklch(1 0 0));\n --card-foreground: var(--app-text-1, oklch(0.145 0 0));\n --popover: var(--app-bg-raised, oklch(1 0 0));\n --popover-foreground: var(--app-text-1, oklch(0.145 0 0));\n /* 模态面板表面(Dialog/AlertDialog/Drawer,issue #2):独立于页面画布 --background */\n --dialog: var(--app-bg-surface, oklch(1 0 0));\n --dialog-foreground: var(--app-text-1, oklch(0.145 0 0));\n --primary: var(--app-accent, oklch(0.205 0 0));\n --primary-foreground: var(--app-accent-contrast, oklch(0.985 0 0));\n --secondary: oklch(0.97 0 0);\n --secondary-foreground: oklch(0.205 0 0);\n --muted: var(--app-bg-surface, oklch(0.97 0 0));\n --muted-foreground: var(--app-text-2, oklch(0.556 0 0));\n --accent: var(--app-bg-hover, oklch(0.97 0 0));\n --accent-foreground: var(--app-text-1, oklch(0.205 0 0));\n --destructive: var(--app-destructive, oklch(0.577 0.245 27.325));\n --destructive-soft: var(\n --app-destructive-soft,\n color-mix(in oklab, var(--destructive) 10%, transparent)\n );\n --destructive-foreground: var(--app-destructive-foreground, oklch(0.985 0 0));\n --success: var(--app-success, oklch(0.596 0.145 163.225));\n --success-soft: var(--app-success-soft, color-mix(in oklab, var(--success) 10%, transparent));\n --success-foreground: var(--app-success-foreground, oklch(0.985 0 0));\n --warning: var(--app-warning, oklch(0.666 0.179 58.318));\n --warning-soft: var(--app-warning-soft, color-mix(in oklab, var(--warning) 12%, transparent));\n --warning-foreground: var(--app-warning-foreground, oklch(0.985 0 0));\n --info: var(--app-info, oklch(0.546 0.245 262.881));\n --info-soft: var(--app-info-soft, color-mix(in oklab, var(--info) 12%, transparent));\n --info-foreground: var(--app-info-foreground, oklch(0.985 0 0));\n --border: var(--app-border, oklch(0.922 0 0));\n --input: var(--app-border, oklch(0.922 0 0));\n --ring: var(--app-accent, oklch(0.708 0 0));\n --radius: 0.625rem;\n /* 层叠序:表体 sticky < 表头普通列 sticky(fill/virtual 表头钉住,z-20 由 TableRender theadThClass 提供)\n < 表头 sticky < 非模态浮层 < 宿主应用 chrome < 模态层(chrome 由消费方置于 overlay~modal 之间,\n 不得 ≥ modal,否则击穿模态遮罩;表头 fixed 列经 stickyStyle inline style 消费 --z-sticky-head)\n --z-overlay:原地锚定的 Select/Tooltip/DropdownMenu/ContextMenu(弹窗内处于 Content 栈上下文内,天然高于面板)\n --z-modal:Dialog/AlertDialog/Drawer 的 Backdrop/Positioner/Content + teleport 至 body 的\n Popover/Cascader/TreeSelect/日期弹层 Positioner(同层按 DOM 挂载次序叠放,teleport 节点恒后于应用\n 根容器,故弹窗内下拉恒浮于面板之上;模态打开时弹窗外浮层被遮罩与焦点陷阱阻断,不可达同开) */\n --z-sticky: 10;\n --z-sticky-head: 30;\n --z-overlay: 50;\n --z-modal: 60;\n}\n\n.dark {\n --background: var(--app-bg-page, oklch(0.145 0 0));\n --foreground: var(--app-text-1, oklch(0.985 0 0));\n --card: var(--app-bg-raised, oklch(0.205 0 0));\n --card-foreground: var(--app-text-1, oklch(0.985 0 0));\n --popover: var(--app-bg-raised, oklch(0.269 0 0));\n --popover-foreground: var(--app-text-1, oklch(0.985 0 0));\n /* 暗色兜底取画布同值(0.145):与迁移前面板观感一致,零破坏(issue #2) */\n --dialog: var(--app-bg-surface, oklch(0.145 0 0));\n --dialog-foreground: var(--app-text-1, oklch(0.985 0 0));\n --primary: var(--app-accent, oklch(0.922 0 0));\n --primary-foreground: var(--app-accent-contrast, oklch(0.205 0 0));\n --secondary: oklch(0.269 0 0);\n --secondary-foreground: oklch(0.985 0 0);\n --muted: var(--app-bg-surface, oklch(0.269 0 0));\n --muted-foreground: var(--app-text-2, oklch(0.708 0 0));\n --accent: var(--app-bg-hover, oklch(0.371 0 0));\n --accent-foreground: var(--app-text-1, oklch(0.985 0 0));\n --destructive: var(--app-destructive, oklch(0.704 0.191 22.216));\n --destructive-soft: var(\n --app-destructive-soft,\n color-mix(in oklab, var(--destructive) 10%, transparent)\n );\n --destructive-foreground: var(--app-destructive-foreground, oklch(0.985 0 0));\n --success: var(--app-success, oklch(0.696 0.17 162.48));\n --success-soft: var(--app-success-soft, color-mix(in oklab, var(--success) 10%, transparent));\n --success-foreground: var(--app-success-foreground, oklch(0.985 0 0));\n --warning: var(--app-warning, oklch(0.769 0.188 70.08));\n --warning-soft: var(--app-warning-soft, color-mix(in oklab, var(--warning) 12%, transparent));\n --warning-foreground: var(--app-warning-foreground, oklch(0.205 0 0));\n --info: var(--app-info, oklch(0.623 0.214 259.815));\n --info-soft: var(--app-info-soft, color-mix(in oklab, var(--info) 12%, transparent));\n --info-foreground: var(--app-info-foreground, oklch(0.985 0 0));\n --border: var(--app-border, oklch(1 0 0 / 10%));\n --input: var(--app-border, oklch(1 0 0 / 15%));\n --ring: var(--app-accent, oklch(0.556 0 0));\n}\n\n@theme inline {\n --radius-sm: calc(var(--radius) - 4px);\n --radius-md: calc(var(--radius) - 2px);\n --radius-lg: var(--radius);\n --radius-xl: calc(var(--radius) + 4px);\n --radius-2xl: calc(var(--radius) + 6px);\n --color-background: var(--background);\n --color-foreground: var(--foreground);\n --color-card: var(--card);\n --color-card-foreground: var(--card-foreground);\n --color-popover: var(--popover);\n --color-popover-foreground: var(--popover-foreground);\n --color-dialog: var(--dialog);\n --color-dialog-foreground: var(--dialog-foreground);\n --color-primary: var(--primary);\n --color-primary-foreground: var(--primary-foreground);\n --color-secondary: var(--secondary);\n --color-secondary-foreground: var(--secondary-foreground);\n --color-muted: var(--muted);\n --color-muted-foreground: var(--muted-foreground);\n --color-accent: var(--accent);\n --color-accent-foreground: var(--accent-foreground);\n --color-destructive: var(--destructive);\n --color-destructive-soft: var(--destructive-soft);\n --color-destructive-foreground: var(--destructive-foreground);\n --color-success: var(--success);\n --color-success-foreground: var(--success-foreground);\n --color-success-soft: var(--success-soft);\n --color-warning: var(--warning);\n --color-warning-foreground: var(--warning-foreground);\n --color-warning-soft: var(--warning-soft);\n --color-info: var(--info);\n --color-info-foreground: var(--info-foreground);\n --color-info-soft: var(--info-soft);\n --color-border: var(--border);\n --color-input: var(--input);\n --color-ring: var(--ring);\n}\n\n/* 全局边框色兜底,对齐 shadcn v4 官方 tokens(上游另含 outline-ring/50,此处仅移植 border):\n 裸 border 类不再回退 currentColor,而是使用 --border token。 */\n@layer base {\n * {\n border-color: var(--color-border);\n }\n}\n";
|
|
168
164
|
const CN_UTIL_SOURCE = "import { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\n/**\n * 合并 Tailwind CSS 类名:clsx 组合条件类名,tailwind-merge 消解冲突规则。\n * @param inputs - 任意数量的类名值(字符串、数组或对象)\n * @returns 消解冲突后的类名字符串\n */\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n";
|
|
169
|
-
|
|
170
|
-
//#region src/lib/alias.ts
|
|
165
|
+
// src/lib/alias.ts
|
|
171
166
|
/**
|
|
172
167
|
* 将 paths 合并进 tsconfig 文本。优先 JSON round-trip;
|
|
173
168
|
* JSONC(带注释等无法解析)时回退纯文本插入,保留原注释。
|
|
@@ -259,8 +254,7 @@ function applyAliases(io, cwd, aliasRoot) {
|
|
|
259
254
|
io.writeFile(viteConfigPath, merged);
|
|
260
255
|
}
|
|
261
256
|
}
|
|
262
|
-
|
|
263
|
-
//#region src/lib/init-core.ts
|
|
257
|
+
// src/lib/init-core.ts
|
|
264
258
|
/**
|
|
265
259
|
* init 注入的源码(TOKENS_CSS_SOURCE / CN_UTIL_SOURCE)里出现的裸包说明符,
|
|
266
260
|
* 必须全部在此声明,否则 init 出来的项目首屏构建即失败(init-core.test.ts 强制校验)。
|
|
@@ -374,8 +368,7 @@ function runInit(io, cwd, opts) {
|
|
|
374
368
|
skippedAgents
|
|
375
369
|
};
|
|
376
370
|
}
|
|
377
|
-
|
|
378
|
-
//#region src/lib/registry.ts
|
|
371
|
+
// src/lib/registry.ts
|
|
379
372
|
const ITEM_TYPES = [
|
|
380
373
|
"registry:ui",
|
|
381
374
|
"registry:lib",
|
|
@@ -439,8 +432,7 @@ async function fetchItem(fetcher, registryUrl, npm, name) {
|
|
|
439
432
|
if (npm.hasItem(name)) return validateRegistryItem(npm.readItem(name));
|
|
440
433
|
throw new Error(`无法获取组件 ${name}:URL 通道 ${url} 失败(${urlFailure}),npm 通道(@tu-design/vue)亦不可用`);
|
|
441
434
|
}
|
|
442
|
-
|
|
443
|
-
//#region src/lib/pm.ts
|
|
435
|
+
// src/lib/pm.ts
|
|
444
436
|
const PM_NAMES = [
|
|
445
437
|
"pnpm",
|
|
446
438
|
"npm",
|
|
@@ -522,8 +514,7 @@ function installDependencies(io, cwd, deps, dev, pm = detectPackageManagerFromLo
|
|
|
522
514
|
if (deps.length === 0) return;
|
|
523
515
|
io.exec(buildInstallCommand(pm, deps, dev));
|
|
524
516
|
}
|
|
525
|
-
|
|
526
|
-
//#region src/lib/lockfile.ts
|
|
517
|
+
// src/lib/lockfile.ts
|
|
527
518
|
/** 组件版本记录文件,位于项目根(components.json 旁)。 */
|
|
528
519
|
const LOCKFILE_NAME = "components.lock.json";
|
|
529
520
|
/**
|
|
@@ -591,8 +582,7 @@ function readLockfile(io, root) {
|
|
|
591
582
|
function writeLockfile(io, root, lockfile) {
|
|
592
583
|
io.writeFile(`${root}/${LOCKFILE_NAME}`, `${JSON.stringify(lockfile, null, 2)}\n`);
|
|
593
584
|
}
|
|
594
|
-
|
|
595
|
-
//#region src/lib/rewrite.ts
|
|
585
|
+
// src/lib/rewrite.ts
|
|
596
586
|
/**
|
|
597
587
|
* 空白归一化:移除全部空白字符。
|
|
598
588
|
*
|
|
@@ -655,8 +645,7 @@ function rewriteContent(content, filePath, aliasRoot) {
|
|
|
655
645
|
return rewritten === null ? whole : `${lead}${quote}${rewritten}${quote}`;
|
|
656
646
|
});
|
|
657
647
|
}
|
|
658
|
-
|
|
659
|
-
//#region src/lib/write.ts
|
|
648
|
+
// src/lib/write.ts
|
|
660
649
|
/**
|
|
661
650
|
* 返回目录的父目录(POSIX 路径);根目录 "/" 没有父级。
|
|
662
651
|
* @param dir - 目录路径
|
|
@@ -782,8 +771,7 @@ async function writeFiles(plans, io, opts) {
|
|
|
782
771
|
}
|
|
783
772
|
return result;
|
|
784
773
|
}
|
|
785
|
-
|
|
786
|
-
//#region src/lib/add-core.ts
|
|
774
|
+
// src/lib/add-core.ts
|
|
787
775
|
/**
|
|
788
776
|
* 按依赖拓扑序展开 registry item:registryDependencies 先于自身解析,已解析项去重,
|
|
789
777
|
* 循环引用抛错并给出完整环路。
|
|
@@ -954,8 +942,7 @@ async function runAdd(io, cwd, names, opts) {
|
|
|
954
942
|
devDependencies
|
|
955
943
|
};
|
|
956
944
|
}
|
|
957
|
-
|
|
958
|
-
//#region src/lib/diff-core.ts
|
|
945
|
+
// src/lib/diff-core.ts
|
|
959
946
|
/**
|
|
960
947
|
* 本地文件 vs 线上 registry vs lockfile 安装时快照的三方比对。
|
|
961
948
|
* 全部 hash 走空白归一化(hashNormalizedContent);远端基准在
|
|
@@ -1021,8 +1008,7 @@ async function diffComponents(io, fetcher, registryUrl, npm, root, config, names
|
|
|
1021
1008
|
}
|
|
1022
1009
|
return out;
|
|
1023
1010
|
}
|
|
1024
|
-
|
|
1025
|
-
//#region src/lib/version.ts
|
|
1011
|
+
// src/lib/version.ts
|
|
1026
1012
|
/**
|
|
1027
1013
|
* 从 package.json 原始文本解析版本号(纯函数,便于测试)。
|
|
1028
1014
|
* @param raw - package.json 文件的原始文本
|
|
@@ -1033,8 +1019,7 @@ function parsePkgVersion(raw) {
|
|
|
1033
1019
|
if (typeof parsed.version !== "string" || parsed.version.length === 0) throw new Error("package.json 缺少 version 字段");
|
|
1034
1020
|
return parsed.version;
|
|
1035
1021
|
}
|
|
1036
|
-
|
|
1037
|
-
//#region src/index.ts
|
|
1022
|
+
// src/index.ts
|
|
1038
1023
|
/**
|
|
1039
1024
|
* 唯一的子进程执行实现:init / add 都走它,失败原因由 stdio 直接透传给用户。
|
|
1040
1025
|
* @param cwd - 子进程工作目录(项目根)
|
|
@@ -1242,7 +1227,7 @@ program.command("mcp").description("启动 MCP Server(stdio,仅查询组件
|
|
|
1242
1227
|
import("@modelcontextprotocol/sdk/server/mcp.js"),
|
|
1243
1228
|
import("@modelcontextprotocol/sdk/server/stdio.js"),
|
|
1244
1229
|
import("zod"),
|
|
1245
|
-
import("./mcp-core-
|
|
1230
|
+
import("./mcp-core-C9j95RL7.mjs")
|
|
1246
1231
|
]);
|
|
1247
1232
|
const fetcher = registryHttpFetcher();
|
|
1248
1233
|
const server = new McpServer({
|
|
@@ -1296,5 +1281,4 @@ program.command("mcp").description("启动 MCP Server(stdio,仅查询组件
|
|
|
1296
1281
|
}
|
|
1297
1282
|
});
|
|
1298
1283
|
program.parse();
|
|
1299
|
-
//#endregion
|
|
1300
1284
|
export { validateRegistryItem as t };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as validateRegistryItem } from "./index.mjs";
|
|
2
|
-
|
|
2
|
+
// src/lib/mcp-core.ts
|
|
3
3
|
/** 组件名只允许小写字母、数字与连字符:防路径穿越与 URL 注入。 */
|
|
4
4
|
const NAME_RE = /^[a-z0-9-]+$/;
|
|
5
5
|
/**
|
|
@@ -88,5 +88,4 @@ async function getComponent(fetcher, registryUrl, name) {
|
|
|
88
88
|
installHint: `npx @tu-design/cli add ${item.name}`
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
|
-
//#endregion
|
|
92
91
|
export { fetchRegistryIndex, getComponent, searchComponents };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tu-design/cli",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.11",
|
|
4
4
|
"description": "tu-design CLI:初始化并按 registry 分发组件源码到用户项目(shadcn 模式)。",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -35,18 +35,18 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
38
|
-
"@tu-design/vue": "0.5.
|
|
39
|
-
"commander": "^15",
|
|
40
|
-
"picocolors": "^1",
|
|
41
|
-
"prompts": "^2",
|
|
42
|
-
"zod": "^4"
|
|
38
|
+
"@tu-design/vue": "0.5.11",
|
|
39
|
+
"commander": "^15.1.0",
|
|
40
|
+
"picocolors": "^1.1.1",
|
|
41
|
+
"prompts": "^2.4.2",
|
|
42
|
+
"zod": "^4.6.7"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@types/prompts": "^2.4.
|
|
46
|
-
"tsx": "^4.
|
|
47
|
-
"typescript": "^
|
|
48
|
-
"vite-plus": "1.
|
|
49
|
-
"vitest": "^5.
|
|
45
|
+
"@types/prompts": "^2.4.9",
|
|
46
|
+
"tsx": "^4.23.15",
|
|
47
|
+
"typescript": "^6.0.3",
|
|
48
|
+
"vite-plus": "1.7.0",
|
|
49
|
+
"vitest": "^5.1.1"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|
|
52
52
|
"generate:sources": "tsx scripts/generate-sources.ts && vp fmt src/lib/generated-sources.ts",
|