@ruan-cat/utils 4.12.0 → 4.12.1
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/node-esm/index.d.ts
CHANGED
|
@@ -39,14 +39,73 @@ declare function hasChangelogMd(): boolean;
|
|
|
39
39
|
*/
|
|
40
40
|
declare function copyChangelogMd(/** 目标文件夹 */ target: string): void;
|
|
41
41
|
|
|
42
|
-
/** 检查当前运行的根目录 是否存在 .claude/agents 文件夹 */
|
|
43
|
-
declare function hasClaudeAgents(): boolean;
|
|
44
42
|
/**
|
|
45
|
-
*
|
|
43
|
+
* 检查指定根目录是否存在 .claude/agents 文件夹
|
|
44
|
+
* @param options - 配置选项
|
|
45
|
+
* @param options.rootDir - 可选的根目录路径,支持相对路径(如 `../../../` 表示向上三级目录)。
|
|
46
|
+
* 如果不传入,将自动向上查找包含 pnpm-workspace.yaml 的 monorepo 根目录。
|
|
47
|
+
* 相对路径会基于当前工作目录 (process.cwd()) 解析为绝对路径。
|
|
48
|
+
* @returns 是否存在 .claude/agents 文件夹
|
|
49
|
+
* @example
|
|
50
|
+
* // 自动检测 monorepo 根目录
|
|
51
|
+
* hasClaudeAgents()
|
|
52
|
+
*
|
|
53
|
+
* // 手动指定相对路径(从当前工作目录向上三级)
|
|
54
|
+
* hasClaudeAgents({ rootDir: '../../../' })
|
|
55
|
+
*
|
|
56
|
+
* // 手动指定绝对路径
|
|
57
|
+
* hasClaudeAgents({ rootDir: '/path/to/monorepo' })
|
|
58
|
+
*/
|
|
59
|
+
declare function hasClaudeAgents(options?: {
|
|
60
|
+
rootDir?: string;
|
|
61
|
+
}): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* 将 .claude/agents 文件夹复制到指定位置的配置选项
|
|
64
|
+
*/
|
|
65
|
+
interface CopyClaudeAgentsOptions {
|
|
66
|
+
/**
|
|
67
|
+
* 目标文件夹路径(相对于当前工作目录)
|
|
68
|
+
* @example 'dist', 'build/output', './public'
|
|
69
|
+
*/
|
|
70
|
+
target: string;
|
|
71
|
+
/**
|
|
72
|
+
* 可选的根目录路径,支持相对路径(如 `../../../` 表示向上三级目录)
|
|
73
|
+
* @description
|
|
74
|
+
* - 如果不传入,将自动向上查找包含 pnpm-workspace.yaml 的 monorepo 根目录
|
|
75
|
+
* - 相对路径会基于当前工作目录 (process.cwd()) 解析为绝对路径
|
|
76
|
+
* - 绝对路径将直接使用
|
|
77
|
+
* @example
|
|
78
|
+
* // 相对路径:向上三级目录
|
|
79
|
+
* '../../../'
|
|
80
|
+
*
|
|
81
|
+
* // 绝对路径
|
|
82
|
+
* '/absolute/path/to/monorepo'
|
|
83
|
+
*/
|
|
84
|
+
rootDir?: string;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* 将 .claude/agents 文件夹复制到指定位置
|
|
88
|
+
* @param options - 配置选项
|
|
46
89
|
* @description
|
|
47
|
-
* 该函数相当于实现 `cpx .claude/agents <target>`
|
|
90
|
+
* 该函数相当于实现 `cpx .claude/agents <target>` 命令。
|
|
91
|
+
* 从根目录的 .claude/agents 复制到目标位置。
|
|
92
|
+
* @example
|
|
93
|
+
* // 自动检测 monorepo 根目录,复制到当前目录的 dist 文件夹
|
|
94
|
+
* copyClaudeAgents({ target: 'dist' })
|
|
95
|
+
*
|
|
96
|
+
* // 手动指定根目录为向上三级,复制到 build 文件夹
|
|
97
|
+
* copyClaudeAgents({
|
|
98
|
+
* target: 'build',
|
|
99
|
+
* rootDir: '../../../'
|
|
100
|
+
* })
|
|
101
|
+
*
|
|
102
|
+
* // 使用绝对路径指定根目录
|
|
103
|
+
* copyClaudeAgents({
|
|
104
|
+
* target: 'dist',
|
|
105
|
+
* rootDir: '/absolute/path/to/monorepo'
|
|
106
|
+
* })
|
|
48
107
|
*/
|
|
49
|
-
declare function copyClaudeAgents(
|
|
108
|
+
declare function copyClaudeAgents(options: CopyClaudeAgentsOptions): void;
|
|
50
109
|
|
|
51
110
|
/** 检查当前运行的根目录 是否存在文件名大写的 `README.md` 文件 */
|
|
52
111
|
declare function hasCapitalReadmeMd(): boolean;
|
|
@@ -81,4 +140,4 @@ interface AddChangelog2docOptions<T = Record<string, any>> {
|
|
|
81
140
|
/** 将变更日志添加到指定的文档目录内 并提供参数 */
|
|
82
141
|
declare function addChangelog2doc<T>(options: AddChangelog2docOptions<T>): void;
|
|
83
142
|
|
|
84
|
-
export { type AddChangelog2docOptions, type PackageInfo, type WriteYaml2mdParams, addChangelog2doc, clean, copyChangelogMd, copyClaudeAgents, copyReadmeMd, defaultCleanTargets, getRuanCatPkgInfo, hasCapitalReadmeMd, hasChangelogMd, hasClaudeAgents, hasLowerCaseReadmeMd, hasReadmeMd, writeYaml2md };
|
|
143
|
+
export { type AddChangelog2docOptions, type CopyClaudeAgentsOptions, type PackageInfo, type WriteYaml2mdParams, addChangelog2doc, clean, copyChangelogMd, copyClaudeAgents, copyReadmeMd, defaultCleanTargets, getRuanCatPkgInfo, hasCapitalReadmeMd, hasChangelogMd, hasClaudeAgents, hasLowerCaseReadmeMd, hasReadmeMd, writeYaml2md };
|
package/dist/node-esm/index.js
CHANGED
|
@@ -141,20 +141,49 @@ function copyChangelogMd(target) {
|
|
|
141
141
|
import fs2 from "fs";
|
|
142
142
|
import path2 from "path";
|
|
143
143
|
import consola4 from "consola";
|
|
144
|
-
function
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
144
|
+
function findMonorepoRoot() {
|
|
145
|
+
let currentDir = process.cwd();
|
|
146
|
+
const root = path2.parse(currentDir).root;
|
|
147
|
+
while (currentDir !== root) {
|
|
148
|
+
const workspaceFile2 = path2.join(currentDir, "pnpm-workspace.yaml");
|
|
149
|
+
if (fs2.existsSync(workspaceFile2)) {
|
|
150
|
+
return currentDir;
|
|
151
|
+
}
|
|
152
|
+
currentDir = path2.dirname(currentDir);
|
|
149
153
|
}
|
|
150
|
-
|
|
154
|
+
const workspaceFile = path2.join(root, "pnpm-workspace.yaml");
|
|
155
|
+
if (fs2.existsSync(workspaceFile)) {
|
|
156
|
+
return root;
|
|
157
|
+
}
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
function resolveRootDir(rootDir) {
|
|
161
|
+
if (rootDir) {
|
|
162
|
+
return path2.resolve(process.cwd(), rootDir);
|
|
163
|
+
}
|
|
164
|
+
const monorepoRoot = findMonorepoRoot();
|
|
165
|
+
if (monorepoRoot) {
|
|
166
|
+
return monorepoRoot;
|
|
167
|
+
}
|
|
168
|
+
return process.cwd();
|
|
169
|
+
}
|
|
170
|
+
function hasClaudeAgents(options) {
|
|
171
|
+
const root = resolveRootDir(options?.rootDir);
|
|
172
|
+
const claudeAgentsPath = path2.join(root, ".claude/agents");
|
|
173
|
+
const exists = fs2.existsSync(claudeAgentsPath);
|
|
174
|
+
if (!exists) {
|
|
175
|
+
consola4.log("\u68C0\u6D4B\u7684\u6839\u76EE\u5F55\u4E3A\uFF1A", root);
|
|
176
|
+
consola4.warn("\u8BE5\u6839\u76EE\u5F55\u4E0D\u5B58\u5728 .claude/agents \u6587\u4EF6\u5939");
|
|
177
|
+
}
|
|
178
|
+
return exists;
|
|
151
179
|
}
|
|
152
|
-
function copyClaudeAgents(
|
|
153
|
-
if (!hasClaudeAgents()) {
|
|
180
|
+
function copyClaudeAgents(options) {
|
|
181
|
+
if (!hasClaudeAgents({ rootDir: options.rootDir })) {
|
|
154
182
|
return;
|
|
155
183
|
}
|
|
156
|
-
const
|
|
157
|
-
const
|
|
184
|
+
const root = resolveRootDir(options.rootDir);
|
|
185
|
+
const source = path2.join(root, ".claude/agents");
|
|
186
|
+
const destination = path2.resolve(process.cwd(), options.target);
|
|
158
187
|
fs2.mkdirSync(path2.dirname(destination), { recursive: true });
|
|
159
188
|
fs2.cpSync(source, destination, { recursive: true });
|
|
160
189
|
consola4.success(`\u5DF2\u6210\u529F\u590D\u5236 .claude/agents \u5230 ${destination}`);
|