@ruan-cat/utils 4.12.1 → 4.14.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,96 +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
- * @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 - 配置选项
89
- * @description
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
- * })
107
- */
108
- declare function copyClaudeAgents(options: CopyClaudeAgentsOptions): void;
109
-
110
- /** 检查当前运行的根目录 是否存在文件名大写的 `README.md` 文件 */
111
- declare function hasCapitalReadmeMd(): boolean;
112
- /** 检查当前运行的根目录 是否存在文件名小写的 `readme.md` 文件 */
113
- declare function hasLowerCaseReadmeMd(): boolean;
114
- /** 检查当前运行的根目录 是否存在任意一个大小写命名的 README.md 文件 */
115
- declare function hasReadmeMd(): boolean;
116
- /**
117
- * 将 README.md 文件移动到指定要求的位置内,并重命名为 index.md
118
- * @description
119
- * 该函数相当于实现 `cpx README.md docs` 命令
120
- */
121
- declare function copyReadmeMd(/** 目标文件夹 */ target: string): void;
122
-
123
33
  interface WriteYaml2mdParams<T = Record<string, any>> {
124
34
  /** 目标md文件地址 */
125
35
  mdPath: string;
@@ -131,13 +41,4 @@ interface WriteYaml2mdParams<T = Record<string, any>> {
131
41
  */
132
42
  declare function writeYaml2md<T>(params: WriteYaml2mdParams<T>): void;
133
43
 
134
- interface AddChangelog2docOptions<T = Record<string, any>> {
135
- /** 目标文件夹 */
136
- target: string;
137
- /** 被插入到md头部的数据 */
138
- data: T;
139
- }
140
- /** 将变更日志添加到指定的文档目录内 并提供参数 */
141
- declare function addChangelog2doc<T>(options: AddChangelog2docOptions<T>): void;
142
-
143
- export { type AddChangelog2docOptions, type CopyClaudeAgentsOptions, type PackageInfo, type WriteYaml2mdParams, addChangelog2doc, clean, copyChangelogMd, copyClaudeAgents, copyReadmeMd, defaultCleanTargets, getRuanCatPkgInfo, hasCapitalReadmeMd, hasChangelogMd, hasClaudeAgents, hasLowerCaseReadmeMd, hasReadmeMd, writeYaml2md };
44
+ 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,121 +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 (!hasClaudeAgents({ rootDir: options.rootDir })) {
182
- return;
183
- }
184
- const root = resolveRootDir(options.rootDir);
185
- const source = path2.join(root, ".claude/agents");
186
- const destination = path2.resolve(process.cwd(), options.target);
187
- fs2.mkdirSync(path2.dirname(destination), { recursive: true });
188
- fs2.cpSync(source, destination, { recursive: true });
189
- consola4.success(`\u5DF2\u6210\u529F\u590D\u5236 .claude/agents \u5230 ${destination}`);
190
- }
191
-
192
- // src/node-esm/scripts/copy-readme.ts
193
- import fs3 from "fs";
194
- import path3 from "path";
195
- import consola5 from "consola";
196
- var capitalReadmeMd = "README.md";
197
- var lowerCaseReadmeMd = "readme.md";
198
- function hasCapitalReadmeMd() {
199
- const res = fs3.existsSync(path3.resolve(process.cwd(), capitalReadmeMd));
200
- if (!res) {
201
- consola5.warn(`\u5F53\u524D\u9879\u76EE\u6839\u76EE\u5F55\u4E0D\u5B58\u5728 ${capitalReadmeMd} \u6587\u4EF6`);
202
- }
203
- return res;
204
- }
205
- function hasLowerCaseReadmeMd() {
206
- const res = fs3.existsSync(path3.resolve(process.cwd(), lowerCaseReadmeMd));
207
- if (!res) {
208
- consola5.log(`\u5F53\u524D\u9879\u76EE\u6839\u76EE\u5F55\u4E0D\u5B58\u5728 ${lowerCaseReadmeMd} \u6587\u4EF6`);
209
- }
210
- return res;
211
- }
212
- function hasReadmeMd() {
213
- const res = isConditionsSome([() => hasCapitalReadmeMd(), () => hasCapitalReadmeMd()]);
214
- return res;
215
- }
216
- function copyReadmeMd(target) {
217
- if (!hasReadmeMd()) {
218
- return;
219
- }
220
- let readmeFileName = capitalReadmeMd;
221
- if (hasCapitalReadmeMd()) {
222
- readmeFileName = capitalReadmeMd;
223
- } else if (hasLowerCaseReadmeMd()) {
224
- readmeFileName = lowerCaseReadmeMd;
225
- }
226
- const source = path3.resolve(process.cwd(), readmeFileName);
227
- const destination = path3.resolve(process.cwd(), target, "index.md");
228
- fs3.copyFileSync(source, destination);
229
- }
230
-
231
- // src/node-esm/scripts/yaml-to-md.ts
114
+ // src/node-esm/yaml-to-md.ts
232
115
  import { readFileSync, writeFileSync } from "fs";
233
- import { consola as consola6 } from "consola";
116
+ import { consola as consola3 } from "consola";
234
117
  import { isUndefined } from "lodash-es";
235
118
 
236
119
  // ../../node_modules/.pnpm/js-yaml@4.1.0/node_modules/js-yaml/dist/js-yaml.mjs
@@ -2855,18 +2738,18 @@ var jsYaml = {
2855
2738
  };
2856
2739
  var js_yaml_default = jsYaml;
2857
2740
 
2858
- // src/node-esm/scripts/yaml-to-md.ts
2741
+ // src/node-esm/yaml-to-md.ts
2859
2742
  function writeYaml2md(params) {
2860
- 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()} `);
2861
2744
  const { mdPath, data } = params;
2862
2745
  if (isUndefined(mdPath)) {
2863
- consola6.error(" \u8BF7\u63D0\u4F9Bmd\u6587\u4EF6\u7684\u5730\u5740 ");
2746
+ consola3.error(" \u8BF7\u63D0\u4F9Bmd\u6587\u4EF6\u7684\u5730\u5740 ");
2864
2747
  process.exit(1);
2865
2748
  }
2866
2749
  try {
2867
2750
  readFileSync(mdPath, "utf-8");
2868
2751
  } catch (error) {
2869
- consola6.error(` \u6587\u4EF6 ${mdPath} \u4E0D\u5B58\u5728 `);
2752
+ consola3.error(` \u6587\u4EF6 ${mdPath} \u4E0D\u5B58\u5728 `);
2870
2753
  process.exit(1);
2871
2754
  }
2872
2755
  const mdContent = readFileSync(mdPath, "utf-8");
@@ -2876,36 +2759,12 @@ ${yamlContent}---
2876
2759
 
2877
2760
  ${mdContent}`;
2878
2761
  writeFileSync(mdPath, newContent, "utf-8");
2879
- consola6.success(` \u5DF2\u5C06YAML\u6570\u636E\u5199\u5165\u5230 ${mdPath} `);
2880
- }
2881
-
2882
- // src/node-esm/scripts/add-changelog-to-doc.ts
2883
- import path4 from "path";
2884
- function addChangelog2doc(options) {
2885
- const { data, target } = options;
2886
- if (!hasChangelogMd()) {
2887
- return;
2888
- }
2889
- copyChangelogMd(target);
2890
- const mdPath = path4.resolve(process.cwd(), target, "CHANGELOG.md");
2891
- writeYaml2md({
2892
- mdPath,
2893
- data
2894
- });
2762
+ consola3.success(` \u5DF2\u5C06YAML\u6570\u636E\u5199\u5165\u5230 ${mdPath} `);
2895
2763
  }
2896
2764
  export {
2897
- addChangelog2doc,
2898
2765
  clean,
2899
- copyChangelogMd,
2900
- copyClaudeAgents,
2901
- copyReadmeMd,
2902
2766
  defaultCleanTargets,
2903
2767
  getRuanCatPkgInfo,
2904
- hasCapitalReadmeMd,
2905
- hasChangelogMd,
2906
- hasClaudeAgents,
2907
- hasLowerCaseReadmeMd,
2908
- hasReadmeMd,
2909
2768
  writeYaml2md
2910
2769
  };
2911
2770
  /*! Bundled license information: