@ruan-cat/vitepress-preset-config 2.9.0 → 2.11.0
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/config.d.mts +51 -20
- package/dist/config.mjs +25 -16
- package/package.json +10 -16
- package/src/config/{copy-claude-agents.ts → copy-claude-files.ts} +93 -47
- package/src/config/index.ts +1 -1
- package/src/config.mts +1 -3
package/dist/config.d.mts
CHANGED
|
@@ -52,31 +52,37 @@ interface ExtraConfig {
|
|
|
52
52
|
declare function copyReadmeMd(/** 目标文件夹 */ target: string): void;
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
|
-
*
|
|
55
|
+
* Claude 文件夹名称类型
|
|
56
56
|
*/
|
|
57
|
-
|
|
57
|
+
type ClaudeFolderName = "agents" | "commands";
|
|
58
|
+
/**
|
|
59
|
+
* 将 .claude 相关文件夹复制到指定位置的配置选项
|
|
60
|
+
*/
|
|
61
|
+
interface CopyClaudeFilesOptions {
|
|
58
62
|
/**
|
|
59
|
-
*
|
|
63
|
+
* 目标父文件夹路径(必须是相对路径,相对于当前工作目录)
|
|
60
64
|
* @description
|
|
61
65
|
* **重要**:此参数仅接受相对路径,不接受绝对路径(禁止以 `/` 或盘符如 `C:\` 开头)。
|
|
62
66
|
* 使用绝对路径会抛出错误,这是为了防止意外覆盖系统目录。
|
|
63
67
|
*
|
|
64
68
|
* 该地址是写相对路径的 不能写绝对路径,容易导致意外。
|
|
65
69
|
* vitepress 命令运行在 apps/admin 目录内,该地址是相对于该运行目录的。
|
|
66
|
-
* 比如期望将 `.claude/agents` 复制到 `apps/admin/src/docs/prompts
|
|
67
|
-
* 则写 `src/docs/prompts
|
|
70
|
+
* 比如期望将 `.claude/agents` 和 `.claude/commands` 复制到 `apps/admin/src/docs/prompts/` 文件夹下。
|
|
71
|
+
* 则写 `src/docs/prompts` 即可,最终会生成:
|
|
72
|
+
* - `apps/admin/src/docs/prompts/agents/`
|
|
73
|
+
* - `apps/admin/src/docs/prompts/commands/`
|
|
68
74
|
*
|
|
69
75
|
* @throws {Error} 当传入绝对路径时抛出错误
|
|
70
76
|
* @example
|
|
71
77
|
* // ✅ 正确:相对路径
|
|
72
|
-
* "src/docs/prompts
|
|
73
|
-
* "dist
|
|
78
|
+
* "src/docs/prompts"
|
|
79
|
+
* "dist"
|
|
74
80
|
* "./public/claude"
|
|
75
81
|
*
|
|
76
82
|
* @example
|
|
77
83
|
* // ❌ 错误:绝对路径(会抛出错误)
|
|
78
|
-
* "/var/www/
|
|
79
|
-
* "C:\\Users\\
|
|
84
|
+
* "/var/www/claude" // Unix 绝对路径
|
|
85
|
+
* "C:\\Users\\claude" // Windows 绝对路径
|
|
80
86
|
*/
|
|
81
87
|
target: string;
|
|
82
88
|
/**
|
|
@@ -93,39 +99,64 @@ interface CopyClaudeAgentsOptions {
|
|
|
93
99
|
* '/absolute/path/to/monorepo'
|
|
94
100
|
*/
|
|
95
101
|
rootDir?: string;
|
|
102
|
+
/**
|
|
103
|
+
* 要复制的 Claude 文件夹列表
|
|
104
|
+
* @description
|
|
105
|
+
* 指定要复制的文件夹名称数组。如果不传入,默认复制所有文件夹('agents' 和 'commands')。
|
|
106
|
+
* 对于不存在的文件夹,会打印警告并跳过,不会影响其他文件夹的复制。
|
|
107
|
+
*
|
|
108
|
+
* @default ['agents', 'commands']
|
|
109
|
+
* @example
|
|
110
|
+
* // 只复制 agents 文件夹
|
|
111
|
+
* items: ['agents']
|
|
112
|
+
*
|
|
113
|
+
* // 只复制 commands 文件夹
|
|
114
|
+
* items: ['commands']
|
|
115
|
+
*
|
|
116
|
+
* // 复制所有文件夹(默认行为)
|
|
117
|
+
* items: ['agents', 'commands']
|
|
118
|
+
*/
|
|
119
|
+
items?: ClaudeFolderName[];
|
|
96
120
|
}
|
|
97
121
|
/**
|
|
98
|
-
* 将 .claude
|
|
122
|
+
* 将 .claude 相关文件夹(agents 和 commands)复制到指定位置
|
|
99
123
|
* @param options - 配置选项
|
|
100
124
|
* @throws {Error} 当 `options.target` 为绝对路径时抛出错误
|
|
101
125
|
* @description
|
|
102
|
-
*
|
|
103
|
-
* 从根目录的 .claude
|
|
126
|
+
* 该函数会将指定的 `.claude` 文件夹(默认为 `agents` 和 `commands`)复制到目标位置的子目录中。
|
|
127
|
+
* 从根目录的 .claude 文件夹复制到目标位置,自动创建对应的子文件夹。
|
|
104
128
|
*
|
|
105
129
|
* **安全限制**:`target` 参数必须是相对路径,禁止使用绝对路径,以防止意外覆盖系统目录。
|
|
106
130
|
*
|
|
107
131
|
* @example
|
|
108
|
-
* // ✅ 自动检测 monorepo
|
|
109
|
-
*
|
|
132
|
+
* // ✅ 自动检测 monorepo 根目录,复制所有文件夹到当前目录的 dist 文件夹
|
|
133
|
+
* // 会生成:dist/agents/ 和 dist/commands/
|
|
134
|
+
* copyClaudeFiles({ target: 'dist' })
|
|
135
|
+
*
|
|
136
|
+
* // ✅ 只复制 agents 文件夹
|
|
137
|
+
* copyClaudeFiles({
|
|
138
|
+
* target: 'dist',
|
|
139
|
+
* items: ['agents']
|
|
140
|
+
* })
|
|
110
141
|
*
|
|
111
142
|
* // ✅ 手动指定根目录为向上三级,复制到 build 文件夹
|
|
112
|
-
*
|
|
143
|
+
* copyClaudeFiles({
|
|
113
144
|
* target: 'build',
|
|
114
145
|
* rootDir: '../../../'
|
|
115
146
|
* })
|
|
116
147
|
*
|
|
117
148
|
* // ✅ 使用绝对路径指定根目录(rootDir 允许绝对路径)
|
|
118
|
-
*
|
|
149
|
+
* copyClaudeFiles({
|
|
119
150
|
* target: 'dist', // target 必须是相对路径
|
|
120
151
|
* rootDir: '/absolute/path/to/monorepo' // rootDir 可以是绝对路径
|
|
121
152
|
* })
|
|
122
153
|
*
|
|
123
154
|
* @example
|
|
124
155
|
* // ❌ 错误用法:target 使用绝对路径会抛出错误
|
|
125
|
-
*
|
|
126
|
-
*
|
|
156
|
+
* copyClaudeFiles({ target: '/var/www/claude' }) // 抛出 Error
|
|
157
|
+
* copyClaudeFiles({ target: 'C:\\Windows\\claude' }) // 抛出 Error
|
|
127
158
|
*/
|
|
128
|
-
declare function
|
|
159
|
+
declare function copyClaudeFiles(options: CopyClaudeFilesOptions): void;
|
|
129
160
|
|
|
130
161
|
interface AddChangelog2docOptions<T extends Record<string, any> = Record<string, any>> {
|
|
131
162
|
/** 目标文件夹 */
|
|
@@ -145,4 +176,4 @@ declare function setGenerateSidebar(options?: VitePressSidebarOptions): vitepres
|
|
|
145
176
|
/** 设置vitepress主配置 */
|
|
146
177
|
declare function setUserConfig(config?: UserConfig<DefaultTheme.Config>, extraConfig?: ExtraConfig): UserConfig<DefaultTheme.Config>;
|
|
147
178
|
|
|
148
|
-
export { addChangelog2doc,
|
|
179
|
+
export { addChangelog2doc, copyClaudeFiles, copyReadmeMd, setGenerateSidebar, setUserConfig };
|
package/dist/config.mjs
CHANGED
|
@@ -56,7 +56,7 @@ function copyReadmeMd(target) {
|
|
|
56
56
|
fs.copyFileSync(source, destination);
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
// src/config/copy-claude-
|
|
59
|
+
// src/config/copy-claude-files.ts
|
|
60
60
|
import fs2 from "fs";
|
|
61
61
|
import path2 from "path";
|
|
62
62
|
import consola2 from "consola";
|
|
@@ -86,35 +86,44 @@ function resolveRootDir(rootDir) {
|
|
|
86
86
|
}
|
|
87
87
|
return process.cwd();
|
|
88
88
|
}
|
|
89
|
-
function
|
|
89
|
+
function hasClaudeFolder(folderPath, options) {
|
|
90
90
|
const root = resolveRootDir(options == null ? void 0 : options.rootDir);
|
|
91
|
-
const
|
|
92
|
-
const exists = fs2.existsSync(
|
|
91
|
+
const claudeFolderPath = path2.join(root, folderPath);
|
|
92
|
+
const exists = fs2.existsSync(claudeFolderPath);
|
|
93
93
|
if (!exists) {
|
|
94
94
|
consola2.log("\u68C0\u6D4B\u7684\u6839\u76EE\u5F55\u4E3A\uFF1A", root);
|
|
95
|
-
consola2.warn(
|
|
95
|
+
consola2.warn(`\u8BE5\u6839\u76EE\u5F55\u4E0D\u5B58\u5728 ${folderPath} \u6587\u4EF6\u5939`);
|
|
96
96
|
}
|
|
97
97
|
return exists;
|
|
98
98
|
}
|
|
99
|
-
function
|
|
99
|
+
function copyClaudeFiles(options) {
|
|
100
100
|
if (path2.isAbsolute(options.target)) {
|
|
101
101
|
const errorMessage = [
|
|
102
102
|
`target \u53C2\u6570\u4E0D\u5141\u8BB8\u4F7F\u7528\u7EDD\u5BF9\u8DEF\u5F84\uFF0C\u8FD9\u53EF\u80FD\u5BFC\u81F4\u610F\u5916\u7684\u6587\u4EF6\u8986\u76D6\u3002`,
|
|
103
103
|
`\u5F53\u524D\u4F20\u5165\u7684\u8DEF\u5F84: "${options.target}"`,
|
|
104
|
-
`\u8BF7\u4F7F\u7528\u76F8\u5BF9\u8DEF\u5F84\uFF0C\u4F8B\u5982: "src/docs/prompts
|
|
104
|
+
`\u8BF7\u4F7F\u7528\u76F8\u5BF9\u8DEF\u5F84\uFF0C\u4F8B\u5982: "src/docs/prompts"`
|
|
105
105
|
].join("\n");
|
|
106
106
|
consola2.error(errorMessage);
|
|
107
107
|
throw new Error(errorMessage);
|
|
108
108
|
}
|
|
109
|
-
if (!hasClaudeAgents({ rootDir: options.rootDir })) {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
109
|
const root = resolveRootDir(options.rootDir);
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
110
|
+
const itemsToProcess = options.items ?? ["agents", "commands"];
|
|
111
|
+
let successCount = 0;
|
|
112
|
+
for (const folderName of itemsToProcess) {
|
|
113
|
+
const claudeFolderPath = `.claude/${folderName}`;
|
|
114
|
+
if (!hasClaudeFolder(claudeFolderPath, { rootDir: options.rootDir })) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const source = path2.join(root, claudeFolderPath);
|
|
118
|
+
const destination = path2.resolve(process.cwd(), options.target, folderName);
|
|
119
|
+
fs2.mkdirSync(path2.dirname(destination), { recursive: true });
|
|
120
|
+
fs2.cpSync(source, destination, { recursive: true });
|
|
121
|
+
consola2.success(`\u5DF2\u6210\u529F\u590D\u5236 ${claudeFolderPath} \u5230 ${destination}`);
|
|
122
|
+
successCount++;
|
|
123
|
+
}
|
|
124
|
+
if (successCount === 0) {
|
|
125
|
+
consola2.warn("\u6CA1\u6709\u6210\u529F\u590D\u5236\u4EFB\u4F55 .claude \u6587\u4EF6\u5939");
|
|
126
|
+
}
|
|
118
127
|
}
|
|
119
128
|
|
|
120
129
|
// src/config/add-changelog-to-doc.ts
|
|
@@ -532,7 +541,7 @@ function setUserConfig(config, extraConfig) {
|
|
|
532
541
|
}
|
|
533
542
|
export {
|
|
534
543
|
addChangelog2doc,
|
|
535
|
-
|
|
544
|
+
copyClaudeFiles,
|
|
536
545
|
copyReadmeMd,
|
|
537
546
|
defineConfig,
|
|
538
547
|
setGenerateSidebar,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ruan-cat/vitepress-preset-config",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.11.0",
|
|
4
4
|
"description": "用于给大多数的vitepress项目提供一个预设的配置文件。",
|
|
5
5
|
"homepage": "https://vitepress-preset.ruancat6312.top",
|
|
6
6
|
"types": "./src/config.mts",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"vitepress-sidebar": "^1.33.0",
|
|
20
20
|
"vitepress-theme-teek": "^1.4.6",
|
|
21
21
|
"vue": "^3.5.21",
|
|
22
|
-
"@ruan-cat/utils": "^4.
|
|
22
|
+
"@ruan-cat/utils": "^4.16.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/lodash-es": "^4.17.12",
|
|
@@ -77,23 +77,17 @@
|
|
|
77
77
|
"registry": "https://registry.npmjs.org/",
|
|
78
78
|
"tag": "beta"
|
|
79
79
|
},
|
|
80
|
-
"typesVersions": {
|
|
81
|
-
"*": {
|
|
82
|
-
"*": [
|
|
83
|
-
"./dist/*",
|
|
84
|
-
"./*"
|
|
85
|
-
]
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
80
|
"files": [
|
|
89
81
|
"!**/.vercel/**",
|
|
90
|
-
"
|
|
82
|
+
"!**/.vitepress/**",
|
|
91
83
|
"src",
|
|
92
|
-
"
|
|
93
|
-
"
|
|
94
|
-
"
|
|
95
|
-
"!src
|
|
96
|
-
"!src
|
|
84
|
+
"dist/**",
|
|
85
|
+
"tsconfig.json",
|
|
86
|
+
"README.md",
|
|
87
|
+
"!src/**/docs/**",
|
|
88
|
+
"!src/**/tests/**",
|
|
89
|
+
"!*.test.*",
|
|
90
|
+
"!src/**/*.md"
|
|
97
91
|
],
|
|
98
92
|
"scripts": {
|
|
99
93
|
"docs:dev": "vitepress dev src/docs --port 8080",
|
|
@@ -2,6 +2,11 @@ import fs from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import consola from "consola";
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Claude 文件夹名称类型
|
|
7
|
+
*/
|
|
8
|
+
export type ClaudeFolderName = "agents" | "commands";
|
|
9
|
+
|
|
5
10
|
/**
|
|
6
11
|
* 从当前工作目录向上查找 monorepo 根目录
|
|
7
12
|
* @returns monorepo 根目录的绝对路径,如果找不到则返回 null
|
|
@@ -57,61 +62,56 @@ function resolveRootDir(rootDir?: string): string {
|
|
|
57
62
|
}
|
|
58
63
|
|
|
59
64
|
/**
|
|
60
|
-
*
|
|
65
|
+
* 检查指定根目录是否存在指定的 Claude 文件夹
|
|
66
|
+
* @param folderPath - Claude 文件夹的相对路径(如 '.claude/agents' 或 '.claude/commands')
|
|
61
67
|
* @param options - 配置选项
|
|
62
68
|
* @param options.rootDir - 可选的根目录路径,支持相对路径(如 `../../../` 表示向上三级目录)。
|
|
63
69
|
* 如果不传入,将自动向上查找包含 pnpm-workspace.yaml 的 monorepo 根目录。
|
|
64
70
|
* 相对路径会基于当前工作目录 (process.cwd()) 解析为绝对路径。
|
|
65
|
-
* @returns
|
|
66
|
-
* @
|
|
67
|
-
* // 自动检测 monorepo 根目录
|
|
68
|
-
* hasClaudeAgents()
|
|
69
|
-
*
|
|
70
|
-
* // 手动指定相对路径(从当前工作目录向上三级)
|
|
71
|
-
* hasClaudeAgents({ rootDir: '../../../' })
|
|
72
|
-
*
|
|
73
|
-
* // 手动指定绝对路径
|
|
74
|
-
* hasClaudeAgents({ rootDir: '/path/to/monorepo' })
|
|
71
|
+
* @returns 是否存在指定的 Claude 文件夹
|
|
72
|
+
* @internal 该函数为内部使用,不对外暴露
|
|
75
73
|
*/
|
|
76
|
-
function
|
|
74
|
+
function hasClaudeFolder(folderPath: string, options?: { rootDir?: string }): boolean {
|
|
77
75
|
const root = resolveRootDir(options?.rootDir);
|
|
78
|
-
const
|
|
79
|
-
const exists = fs.existsSync(
|
|
76
|
+
const claudeFolderPath = path.join(root, folderPath);
|
|
77
|
+
const exists = fs.existsSync(claudeFolderPath);
|
|
80
78
|
|
|
81
79
|
if (!exists) {
|
|
82
80
|
consola.log("检测的根目录为:", root);
|
|
83
|
-
consola.warn(
|
|
81
|
+
consola.warn(`该根目录不存在 ${folderPath} 文件夹`);
|
|
84
82
|
}
|
|
85
83
|
|
|
86
84
|
return exists;
|
|
87
85
|
}
|
|
88
86
|
|
|
89
87
|
/**
|
|
90
|
-
* 将 .claude
|
|
88
|
+
* 将 .claude 相关文件夹复制到指定位置的配置选项
|
|
91
89
|
*/
|
|
92
|
-
export interface
|
|
90
|
+
export interface CopyClaudeFilesOptions {
|
|
93
91
|
/**
|
|
94
|
-
*
|
|
92
|
+
* 目标父文件夹路径(必须是相对路径,相对于当前工作目录)
|
|
95
93
|
* @description
|
|
96
94
|
* **重要**:此参数仅接受相对路径,不接受绝对路径(禁止以 `/` 或盘符如 `C:\` 开头)。
|
|
97
95
|
* 使用绝对路径会抛出错误,这是为了防止意外覆盖系统目录。
|
|
98
96
|
*
|
|
99
97
|
* 该地址是写相对路径的 不能写绝对路径,容易导致意外。
|
|
100
98
|
* vitepress 命令运行在 apps/admin 目录内,该地址是相对于该运行目录的。
|
|
101
|
-
* 比如期望将 `.claude/agents` 复制到 `apps/admin/src/docs/prompts
|
|
102
|
-
* 则写 `src/docs/prompts
|
|
99
|
+
* 比如期望将 `.claude/agents` 和 `.claude/commands` 复制到 `apps/admin/src/docs/prompts/` 文件夹下。
|
|
100
|
+
* 则写 `src/docs/prompts` 即可,最终会生成:
|
|
101
|
+
* - `apps/admin/src/docs/prompts/agents/`
|
|
102
|
+
* - `apps/admin/src/docs/prompts/commands/`
|
|
103
103
|
*
|
|
104
104
|
* @throws {Error} 当传入绝对路径时抛出错误
|
|
105
105
|
* @example
|
|
106
106
|
* // ✅ 正确:相对路径
|
|
107
|
-
* "src/docs/prompts
|
|
108
|
-
* "dist
|
|
107
|
+
* "src/docs/prompts"
|
|
108
|
+
* "dist"
|
|
109
109
|
* "./public/claude"
|
|
110
110
|
*
|
|
111
111
|
* @example
|
|
112
112
|
* // ❌ 错误:绝对路径(会抛出错误)
|
|
113
|
-
* "/var/www/
|
|
114
|
-
* "C:\\Users\\
|
|
113
|
+
* "/var/www/claude" // Unix 绝对路径
|
|
114
|
+
* "C:\\Users\\claude" // Windows 绝对路径
|
|
115
115
|
*/
|
|
116
116
|
target: string;
|
|
117
117
|
|
|
@@ -129,66 +129,112 @@ export interface CopyClaudeAgentsOptions {
|
|
|
129
129
|
* '/absolute/path/to/monorepo'
|
|
130
130
|
*/
|
|
131
131
|
rootDir?: string;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* 要复制的 Claude 文件夹列表
|
|
135
|
+
* @description
|
|
136
|
+
* 指定要复制的文件夹名称数组。如果不传入,默认复制所有文件夹('agents' 和 'commands')。
|
|
137
|
+
* 对于不存在的文件夹,会打印警告并跳过,不会影响其他文件夹的复制。
|
|
138
|
+
*
|
|
139
|
+
* @default ['agents', 'commands']
|
|
140
|
+
* @example
|
|
141
|
+
* // 只复制 agents 文件夹
|
|
142
|
+
* items: ['agents']
|
|
143
|
+
*
|
|
144
|
+
* // 只复制 commands 文件夹
|
|
145
|
+
* items: ['commands']
|
|
146
|
+
*
|
|
147
|
+
* // 复制所有文件夹(默认行为)
|
|
148
|
+
* items: ['agents', 'commands']
|
|
149
|
+
*/
|
|
150
|
+
items?: ClaudeFolderName[];
|
|
132
151
|
}
|
|
133
152
|
|
|
134
153
|
/**
|
|
135
|
-
* 将 .claude
|
|
154
|
+
* 将 .claude 相关文件夹(agents 和 commands)复制到指定位置
|
|
136
155
|
* @param options - 配置选项
|
|
137
156
|
* @throws {Error} 当 `options.target` 为绝对路径时抛出错误
|
|
138
157
|
* @description
|
|
139
|
-
*
|
|
140
|
-
* 从根目录的 .claude
|
|
158
|
+
* 该函数会将指定的 `.claude` 文件夹(默认为 `agents` 和 `commands`)复制到目标位置的子目录中。
|
|
159
|
+
* 从根目录的 .claude 文件夹复制到目标位置,自动创建对应的子文件夹。
|
|
141
160
|
*
|
|
142
161
|
* **安全限制**:`target` 参数必须是相对路径,禁止使用绝对路径,以防止意外覆盖系统目录。
|
|
143
162
|
*
|
|
144
163
|
* @example
|
|
145
|
-
* // ✅ 自动检测 monorepo
|
|
146
|
-
*
|
|
164
|
+
* // ✅ 自动检测 monorepo 根目录,复制所有文件夹到当前目录的 dist 文件夹
|
|
165
|
+
* // 会生成:dist/agents/ 和 dist/commands/
|
|
166
|
+
* copyClaudeFiles({ target: 'dist' })
|
|
167
|
+
*
|
|
168
|
+
* // ✅ 只复制 agents 文件夹
|
|
169
|
+
* copyClaudeFiles({
|
|
170
|
+
* target: 'dist',
|
|
171
|
+
* items: ['agents']
|
|
172
|
+
* })
|
|
147
173
|
*
|
|
148
174
|
* // ✅ 手动指定根目录为向上三级,复制到 build 文件夹
|
|
149
|
-
*
|
|
175
|
+
* copyClaudeFiles({
|
|
150
176
|
* target: 'build',
|
|
151
177
|
* rootDir: '../../../'
|
|
152
178
|
* })
|
|
153
179
|
*
|
|
154
180
|
* // ✅ 使用绝对路径指定根目录(rootDir 允许绝对路径)
|
|
155
|
-
*
|
|
181
|
+
* copyClaudeFiles({
|
|
156
182
|
* target: 'dist', // target 必须是相对路径
|
|
157
183
|
* rootDir: '/absolute/path/to/monorepo' // rootDir 可以是绝对路径
|
|
158
184
|
* })
|
|
159
185
|
*
|
|
160
186
|
* @example
|
|
161
187
|
* // ❌ 错误用法:target 使用绝对路径会抛出错误
|
|
162
|
-
*
|
|
163
|
-
*
|
|
188
|
+
* copyClaudeFiles({ target: '/var/www/claude' }) // 抛出 Error
|
|
189
|
+
* copyClaudeFiles({ target: 'C:\\Windows\\claude' }) // 抛出 Error
|
|
164
190
|
*/
|
|
165
|
-
export function
|
|
191
|
+
export function copyClaudeFiles(options: CopyClaudeFilesOptions): void {
|
|
166
192
|
// 验证 target 不能是绝对路径
|
|
167
193
|
if (path.isAbsolute(options.target)) {
|
|
168
194
|
const errorMessage = [
|
|
169
195
|
`target 参数不允许使用绝对路径,这可能导致意外的文件覆盖。`,
|
|
170
196
|
`当前传入的路径: "${options.target}"`,
|
|
171
|
-
`请使用相对路径,例如: "src/docs/prompts
|
|
197
|
+
`请使用相对路径,例如: "src/docs/prompts"`,
|
|
172
198
|
].join("\n");
|
|
173
199
|
|
|
174
200
|
consola.error(errorMessage);
|
|
175
201
|
throw new Error(errorMessage);
|
|
176
202
|
}
|
|
177
203
|
|
|
178
|
-
// 检查源目录是否存在
|
|
179
|
-
if (!hasClaudeAgents({ rootDir: options.rootDir })) {
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
204
|
const root = resolveRootDir(options.rootDir);
|
|
184
|
-
const source = path.join(root, ".claude/agents");
|
|
185
|
-
const destination = path.resolve(process.cwd(), options.target);
|
|
186
205
|
|
|
187
|
-
//
|
|
188
|
-
|
|
206
|
+
// 确定要处理的文件夹列表,默认为所有文件夹
|
|
207
|
+
const itemsToProcess = options.items ?? ["agents", "commands"];
|
|
189
208
|
|
|
190
|
-
//
|
|
191
|
-
|
|
209
|
+
// 记录成功复制的文件夹数量
|
|
210
|
+
let successCount = 0;
|
|
211
|
+
|
|
212
|
+
// 遍历每个要处理的文件夹
|
|
213
|
+
for (const folderName of itemsToProcess) {
|
|
214
|
+
const claudeFolderPath = `.claude/${folderName}`;
|
|
215
|
+
|
|
216
|
+
// 使用 hasClaudeFolder 检查文件夹是否存在
|
|
217
|
+
// 如果不存在,hasClaudeFolder 会自动打印警告
|
|
218
|
+
if (!hasClaudeFolder(claudeFolderPath, { rootDir: options.rootDir })) {
|
|
219
|
+
continue; // 跳过不存在的文件夹
|
|
220
|
+
}
|
|
192
221
|
|
|
193
|
-
|
|
222
|
+
// 构建源路径和目标路径
|
|
223
|
+
const source = path.join(root, claudeFolderPath);
|
|
224
|
+
const destination = path.resolve(process.cwd(), options.target, folderName);
|
|
225
|
+
|
|
226
|
+
// 确保目标文件夹的父目录存在
|
|
227
|
+
fs.mkdirSync(path.dirname(destination), { recursive: true });
|
|
228
|
+
|
|
229
|
+
// 递归复制文件夹
|
|
230
|
+
fs.cpSync(source, destination, { recursive: true });
|
|
231
|
+
|
|
232
|
+
consola.success(`已成功复制 ${claudeFolderPath} 到 ${destination}`);
|
|
233
|
+
successCount++;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// 如果没有成功复制任何文件夹,给出提示
|
|
237
|
+
if (successCount === 0) {
|
|
238
|
+
consola.warn("没有成功复制任何 .claude 文件夹");
|
|
239
|
+
}
|
|
194
240
|
}
|
package/src/config/index.ts
CHANGED
package/src/config.mts
CHANGED
|
@@ -9,9 +9,7 @@ import { merge, isUndefined, cloneDeep } from "lodash-es";
|
|
|
9
9
|
import consola from "consola";
|
|
10
10
|
import type { ExtraConfig } from "./types.ts";
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
import { addChangelog2doc, copyReadmeMd, copyClaudeAgents } from "./config/index.ts";
|
|
14
|
-
export { addChangelog2doc, copyReadmeMd, copyClaudeAgents };
|
|
12
|
+
export { addChangelog2doc, copyReadmeMd, copyClaudeFiles } from "./config/index.ts";
|
|
15
13
|
|
|
16
14
|
import { transformerTwoslash } from "@shikijs/vitepress-twoslash";
|
|
17
15
|
|