@ruan-cat/utils 4.13.0 → 4.15.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.
@@ -37,7 +37,7 @@ declare const defPrintCurrentCommand: SpawnSyncSimpleParams["printCurrentCommand
37
37
  * 之前封装的是 execa 函数
38
38
  * @version 2
39
39
  */
40
- declare function generateSpawnSync(spawnSyncSimpleParams: SpawnSyncSimpleParams): (...args: any) => Promise<child_process.SpawnSyncReturns<Buffer<ArrayBufferLike>>>;
40
+ declare function generateSpawnSync(spawnSyncSimpleParams: SpawnSyncSimpleParams): (...args: any) => Promise<child_process.SpawnSyncReturns<NonSharedBuffer>>;
41
41
 
42
42
  type Condition = (...args: unknown[]) => boolean;
43
43
  /** @deprecated 没必要 */
@@ -30,124 +30,6 @@ declare function clean(
30
30
  */
31
31
  targets?: string[]): Promise<void>;
32
32
 
33
- /** 检查当前运行的根目录 是否存在 CHANGELOG.md 文件 */
34
- declare function hasChangelogMd(): boolean;
35
- /**
36
- * 将 CHANGELOG.md 文件移动到指定要求的位置内
37
- * @description
38
- * 该函数相当于实现 `cpx CHANGELOG.md docs` 命令
39
- */
40
- declare function copyChangelogMd(/** 目标文件夹 */ target: string): void;
41
-
42
- /**
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
- * @description
69
- * **重要**:此参数仅接受相对路径,不接受绝对路径(禁止以 `/` 或盘符如 `C:\` 开头)。
70
- * 使用绝对路径会抛出错误,这是为了防止意外覆盖系统目录。
71
- *
72
- * 该地址是写相对路径的 不能写绝对路径,容易导致意外。
73
- * vitepress 命令运行在 apps/admin 目录内,该地址是相对于该运行目录的。
74
- * 比如期望将 `.claude/agents` 复制到 `apps/admin/src/docs/prompts/agents` 文件夹。
75
- * 则写 `src/docs/prompts/agents` 即可。
76
- *
77
- * @throws {Error} 当传入绝对路径时抛出错误
78
- * @example
79
- * // ✅ 正确:相对路径
80
- * "src/docs/prompts/agents"
81
- * "dist/agents"
82
- * "./public/claude"
83
- *
84
- * @example
85
- * // ❌ 错误:绝对路径(会抛出错误)
86
- * "/var/www/agents" // Unix 绝对路径
87
- * "C:\\Users\\agents" // Windows 绝对路径
88
- */
89
- target: string;
90
- /**
91
- * 可选的根目录路径,支持相对路径(如 `../../../` 表示向上三级目录)
92
- * @description
93
- * - 如果不传入,将自动向上查找包含 pnpm-workspace.yaml 的 monorepo 根目录
94
- * - 相对路径会基于当前工作目录 (process.cwd()) 解析为绝对路径
95
- * - 绝对路径将直接使用
96
- * @example
97
- * // 相对路径:向上三级目录
98
- * '../../../'
99
- *
100
- * // 绝对路径
101
- * '/absolute/path/to/monorepo'
102
- */
103
- rootDir?: string;
104
- }
105
- /**
106
- * 将 .claude/agents 文件夹复制到指定位置
107
- * @param options - 配置选项
108
- * @throws {Error} 当 `options.target` 为绝对路径时抛出错误
109
- * @description
110
- * 该函数相当于实现 `cpx .claude/agents <target>` 命令。
111
- * 从根目录的 .claude/agents 复制到目标位置。
112
- *
113
- * **安全限制**:`target` 参数必须是相对路径,禁止使用绝对路径,以防止意外覆盖系统目录。
114
- *
115
- * @example
116
- * // ✅ 自动检测 monorepo 根目录,复制到当前目录的 dist 文件夹
117
- * copyClaudeAgents({ target: 'dist' })
118
- *
119
- * // ✅ 手动指定根目录为向上三级,复制到 build 文件夹
120
- * copyClaudeAgents({
121
- * target: 'build',
122
- * rootDir: '../../../'
123
- * })
124
- *
125
- * // ✅ 使用绝对路径指定根目录(rootDir 允许绝对路径)
126
- * copyClaudeAgents({
127
- * target: 'dist', // target 必须是相对路径
128
- * rootDir: '/absolute/path/to/monorepo' // rootDir 可以是绝对路径
129
- * })
130
- *
131
- * @example
132
- * // ❌ 错误用法:target 使用绝对路径会抛出错误
133
- * copyClaudeAgents({ target: '/var/www/agents' }) // 抛出 Error
134
- * copyClaudeAgents({ target: 'C:\\Windows\\agents' }) // 抛出 Error
135
- */
136
- declare function copyClaudeAgents(options: CopyClaudeAgentsOptions): void;
137
-
138
- /** 检查当前运行的根目录 是否存在文件名大写的 `README.md` 文件 */
139
- declare function hasCapitalReadmeMd(): boolean;
140
- /** 检查当前运行的根目录 是否存在文件名小写的 `readme.md` 文件 */
141
- declare function hasLowerCaseReadmeMd(): boolean;
142
- /** 检查当前运行的根目录 是否存在任意一个大小写命名的 README.md 文件 */
143
- declare function hasReadmeMd(): boolean;
144
- /**
145
- * 将 README.md 文件移动到指定要求的位置内,并重命名为 index.md
146
- * @description
147
- * 该函数相当于实现 `cpx README.md docs` 命令
148
- */
149
- declare function copyReadmeMd(/** 目标文件夹 */ target: string): void;
150
-
151
33
  interface WriteYaml2mdParams<T = Record<string, any>> {
152
34
  /** 目标md文件地址 */
153
35
  mdPath: string;
@@ -156,16 +38,9 @@ interface WriteYaml2mdParams<T = Record<string, any>> {
156
38
  }
157
39
  /**
158
40
  * 将YAML数据写入到MD文件内
41
+ * @deprecated
42
+ * 请使用 gray-matter 库来实现相关的更改,不使用 `writeYaml2md` 函数了。
159
43
  */
160
44
  declare function writeYaml2md<T>(params: WriteYaml2mdParams<T>): void;
161
45
 
162
- interface AddChangelog2docOptions<T = Record<string, any>> {
163
- /** 目标文件夹 */
164
- target: string;
165
- /** 被插入到md头部的数据 */
166
- data: T;
167
- }
168
- /** 将变更日志添加到指定的文档目录内 并提供参数 */
169
- declare function addChangelog2doc<T>(options: AddChangelog2docOptions<T>): void;
170
-
171
- export { type AddChangelog2docOptions, type CopyClaudeAgentsOptions, type PackageInfo, type WriteYaml2mdParams, addChangelog2doc, clean, copyChangelogMd, copyClaudeAgents, copyReadmeMd, defaultCleanTargets, getRuanCatPkgInfo, hasCapitalReadmeMd, hasChangelogMd, hasClaudeAgents, hasLowerCaseReadmeMd, hasReadmeMd, writeYaml2md };
46
+ export { type PackageInfo, type WriteYaml2mdParams, clean, defaultCleanTargets, getRuanCatPkgInfo, writeYaml2md };
@@ -80,11 +80,6 @@ function generateSpawnSync(spawnSyncSimpleParams) {
80
80
  });
81
81
  }
82
82
 
83
- // src/conditions.ts
84
- function isConditionsSome(conditions) {
85
- return conditions.some((condition) => condition());
86
- }
87
-
88
83
  // src/print.ts
89
84
  import { isPlainObject, isArray } from "lodash-es";
90
85
  import consola2 from "consola";
@@ -116,130 +111,9 @@ async function clean(targets) {
116
111
  await doClean();
117
112
  }
118
113
 
119
- // src/node-esm/scripts/copy-changelog.ts
120
- import fs from "fs";
121
- import path from "path";
122
- import consola3 from "consola";
123
- function hasChangelogMd() {
124
- const res = fs.existsSync(path.resolve(process.cwd(), "CHANGELOG.md"));
125
- if (!res) {
126
- consola3.log("\u5F53\u524D\u9879\u76EE\u6839\u76EE\u5F55\u4E3A\uFF1A", process.cwd());
127
- consola3.warn("\u5F53\u524D\u9879\u76EE\u6839\u76EE\u5F55\u4E0D\u5B58\u5728 CHANGELOG.md \u6587\u4EF6");
128
- }
129
- return res;
130
- }
131
- function copyChangelogMd(target) {
132
- if (!hasChangelogMd()) {
133
- return;
134
- }
135
- const source = path.resolve(process.cwd(), "CHANGELOG.md");
136
- const destination = path.resolve(process.cwd(), target, "CHANGELOG.md");
137
- fs.copyFileSync(source, destination);
138
- }
139
-
140
- // src/node-esm/scripts/copy-claude-agents.ts
141
- import fs2 from "fs";
142
- import path2 from "path";
143
- import consola4 from "consola";
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);
153
- }
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;
179
- }
180
- function copyClaudeAgents(options) {
181
- if (path2.isAbsolute(options.target)) {
182
- const errorMessage = [
183
- `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`,
184
- `\u5F53\u524D\u4F20\u5165\u7684\u8DEF\u5F84: "${options.target}"`,
185
- `\u8BF7\u4F7F\u7528\u76F8\u5BF9\u8DEF\u5F84\uFF0C\u4F8B\u5982: "src/docs/prompts/agents"`
186
- ].join("\n");
187
- consola4.error(errorMessage);
188
- throw new Error(errorMessage);
189
- }
190
- if (!hasClaudeAgents({ rootDir: options.rootDir })) {
191
- return;
192
- }
193
- const root = resolveRootDir(options.rootDir);
194
- const source = path2.join(root, ".claude/agents");
195
- const destination = path2.resolve(process.cwd(), options.target);
196
- fs2.mkdirSync(path2.dirname(destination), { recursive: true });
197
- fs2.cpSync(source, destination, { recursive: true });
198
- consola4.success(`\u5DF2\u6210\u529F\u590D\u5236 .claude/agents \u5230 ${destination}`);
199
- }
200
-
201
- // src/node-esm/scripts/copy-readme.ts
202
- import fs3 from "fs";
203
- import path3 from "path";
204
- import consola5 from "consola";
205
- var capitalReadmeMd = "README.md";
206
- var lowerCaseReadmeMd = "readme.md";
207
- function hasCapitalReadmeMd() {
208
- const res = fs3.existsSync(path3.resolve(process.cwd(), capitalReadmeMd));
209
- if (!res) {
210
- consola5.warn(`\u5F53\u524D\u9879\u76EE\u6839\u76EE\u5F55\u4E0D\u5B58\u5728 ${capitalReadmeMd} \u6587\u4EF6`);
211
- }
212
- return res;
213
- }
214
- function hasLowerCaseReadmeMd() {
215
- const res = fs3.existsSync(path3.resolve(process.cwd(), lowerCaseReadmeMd));
216
- if (!res) {
217
- consola5.log(`\u5F53\u524D\u9879\u76EE\u6839\u76EE\u5F55\u4E0D\u5B58\u5728 ${lowerCaseReadmeMd} \u6587\u4EF6`);
218
- }
219
- return res;
220
- }
221
- function hasReadmeMd() {
222
- const res = isConditionsSome([() => hasCapitalReadmeMd(), () => hasCapitalReadmeMd()]);
223
- return res;
224
- }
225
- function copyReadmeMd(target) {
226
- if (!hasReadmeMd()) {
227
- return;
228
- }
229
- let readmeFileName = capitalReadmeMd;
230
- if (hasCapitalReadmeMd()) {
231
- readmeFileName = capitalReadmeMd;
232
- } else if (hasLowerCaseReadmeMd()) {
233
- readmeFileName = lowerCaseReadmeMd;
234
- }
235
- const source = path3.resolve(process.cwd(), readmeFileName);
236
- const destination = path3.resolve(process.cwd(), target, "index.md");
237
- fs3.copyFileSync(source, destination);
238
- }
239
-
240
- // src/node-esm/scripts/yaml-to-md.ts
114
+ // src/node-esm/yaml-to-md.ts
241
115
  import { readFileSync, writeFileSync } from "fs";
242
- import { consola as consola6 } from "consola";
116
+ import { consola as consola3 } from "consola";
243
117
  import { isUndefined } from "lodash-es";
244
118
 
245
119
  // ../../node_modules/.pnpm/js-yaml@4.1.0/node_modules/js-yaml/dist/js-yaml.mjs
@@ -2864,18 +2738,18 @@ var jsYaml = {
2864
2738
  };
2865
2739
  var js_yaml_default = jsYaml;
2866
2740
 
2867
- // src/node-esm/scripts/yaml-to-md.ts
2741
+ // src/node-esm/yaml-to-md.ts
2868
2742
  function writeYaml2md(params) {
2869
- consola6.info(` \u5F53\u524D\u8FD0\u884C\u7684\u5730\u5740\u4E3A\uFF1A ${process.cwd()} `);
2743
+ consola3.info(` \u5F53\u524D\u8FD0\u884C\u7684\u5730\u5740\u4E3A\uFF1A ${process.cwd()} `);
2870
2744
  const { mdPath, data } = params;
2871
2745
  if (isUndefined(mdPath)) {
2872
- consola6.error(" \u8BF7\u63D0\u4F9Bmd\u6587\u4EF6\u7684\u5730\u5740 ");
2746
+ consola3.error(" \u8BF7\u63D0\u4F9Bmd\u6587\u4EF6\u7684\u5730\u5740 ");
2873
2747
  process.exit(1);
2874
2748
  }
2875
2749
  try {
2876
2750
  readFileSync(mdPath, "utf-8");
2877
2751
  } catch (error) {
2878
- consola6.error(` \u6587\u4EF6 ${mdPath} \u4E0D\u5B58\u5728 `);
2752
+ consola3.error(` \u6587\u4EF6 ${mdPath} \u4E0D\u5B58\u5728 `);
2879
2753
  process.exit(1);
2880
2754
  }
2881
2755
  const mdContent = readFileSync(mdPath, "utf-8");
@@ -2885,36 +2759,12 @@ ${yamlContent}---
2885
2759
 
2886
2760
  ${mdContent}`;
2887
2761
  writeFileSync(mdPath, newContent, "utf-8");
2888
- consola6.success(` \u5DF2\u5C06YAML\u6570\u636E\u5199\u5165\u5230 ${mdPath} `);
2889
- }
2890
-
2891
- // src/node-esm/scripts/add-changelog-to-doc.ts
2892
- import path4 from "path";
2893
- function addChangelog2doc(options) {
2894
- const { data, target } = options;
2895
- if (!hasChangelogMd()) {
2896
- return;
2897
- }
2898
- copyChangelogMd(target);
2899
- const mdPath = path4.resolve(process.cwd(), target, "CHANGELOG.md");
2900
- writeYaml2md({
2901
- mdPath,
2902
- data
2903
- });
2762
+ consola3.success(` \u5DF2\u5C06YAML\u6570\u636E\u5199\u5165\u5230 ${mdPath} `);
2904
2763
  }
2905
2764
  export {
2906
- addChangelog2doc,
2907
2765
  clean,
2908
- copyChangelogMd,
2909
- copyClaudeAgents,
2910
- copyReadmeMd,
2911
2766
  defaultCleanTargets,
2912
2767
  getRuanCatPkgInfo,
2913
- hasCapitalReadmeMd,
2914
- hasChangelogMd,
2915
- hasClaudeAgents,
2916
- hasLowerCaseReadmeMd,
2917
- hasReadmeMd,
2918
2768
  writeYaml2md
2919
2769
  };
2920
2770
  /*! Bundled license information: