@ruan-cat/utils 4.10.0 → 4.12.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruan-cat/utils",
3
- "version": "4.10.0",
3
+ "version": "4.12.0",
4
4
  "description": "阮喵喵工具集合。默认提供js文件,也直接提供ts文件。",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -61,27 +61,27 @@
61
61
  "tsconfig.json"
62
62
  ],
63
63
  "dependencies": {
64
- "@vueuse/integrations": "^13.7.0",
65
- "axios": "^1.11.0",
64
+ "@vueuse/integrations": "^13.9.0",
65
+ "axios": "^1.12.2",
66
66
  "consola": "^3.4.2",
67
67
  "lodash-es": "^4.17.21"
68
68
  },
69
69
  "devDependencies": {
70
- "@antfu/utils": "^9.2.0",
70
+ "@antfu/utils": "^9.2.1",
71
71
  "@types/lodash-es": "^4.17.12",
72
- "@types/node": "^22.17.2",
72
+ "@types/node": "^22.18.6",
73
73
  "@types/qs": "^6.14.0",
74
- "automd": "^0.4.0",
74
+ "automd": "^0.4.2",
75
75
  "commander": "^13.1.0",
76
76
  "js-yaml": "^4.1.0",
77
77
  "qs": "^6.14.0",
78
78
  "tsup": "^8.5.0",
79
79
  "type-plus": "^7.6.2",
80
- "typedoc": "^0.28.10",
80
+ "typedoc": "^0.28.13",
81
81
  "typedoc-plugin-frontmatter": "^1.3.0",
82
- "typedoc-plugin-markdown": "^4.8.1",
82
+ "typedoc-plugin-markdown": "^4.9.0",
83
83
  "typescript": "^5.9.2",
84
- "unplugin-auto-import": "^20.0.0",
84
+ "unplugin-auto-import": "^20.1.0",
85
85
  "unplugin-vue-router": "^0.15.0",
86
86
  "vite-plugin-autogeneration-import-file": "^3.0.0",
87
87
  "vitepress": "^1.6.4"
@@ -1,5 +1,5 @@
1
1
  // 工具包文档项目 直接导入生成文档配置 避免出现循环依赖
2
- import { setUserConfig, setGenerateSidebar, withMermaid } from "../../../vitepress-preset-config";
2
+ import { setUserConfig, setGenerateSidebar } from "../../../vitepress-preset-config";
3
3
  import { addChangelog2doc, copyReadmeMd } from "@ruan-cat/utils/node-esm";
4
4
 
5
5
  import { description } from "../../package.json";
@@ -33,4 +33,4 @@ const userConfig = setUserConfig({
33
33
  userConfig.themeConfig.sidebar = setGenerateSidebar({
34
34
  documentRootPath: "src",
35
35
  });
36
- export default withMermaid(userConfig);
36
+ export default userConfig;
@@ -2,6 +2,7 @@ export * from "./ruan-cat-pkg-info";
2
2
 
3
3
  export * from "./scripts/clean";
4
4
  export * from "./scripts/copy-changelog";
5
+ export * from "./scripts/copy-claude-agents";
5
6
  export * from "./scripts/copy-readme";
6
7
  export * from "./scripts/yaml-to-md";
7
8
  export * from "./scripts/add-changelog-to-doc";
@@ -0,0 +1,35 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import consola from "consola";
4
+
5
+ /** 检查当前运行的根目录 是否存在 .claude/agents 文件夹 */
6
+ export function hasClaudeAgents() {
7
+ const res = fs.existsSync(path.resolve(process.cwd(), ".claude/agents"));
8
+ if (!res) {
9
+ consola.log("当前项目根目录为:", process.cwd());
10
+ consola.warn("当前项目根目录不存在 .claude/agents 文件夹");
11
+ }
12
+ return res;
13
+ }
14
+
15
+ /**
16
+ * 将 .claude/agents 文件夹复制到指定要求的位置内
17
+ * @description
18
+ * 该函数相当于实现 `cpx .claude/agents <target>` 命令
19
+ */
20
+ export function copyClaudeAgents(/** 目标文件夹 */ target: string) {
21
+ if (!hasClaudeAgents()) {
22
+ return;
23
+ }
24
+
25
+ const source = path.resolve(process.cwd(), ".claude/agents");
26
+ const destination = path.resolve(process.cwd(), target);
27
+
28
+ // 确保目标文件夹的父目录存在
29
+ fs.mkdirSync(path.dirname(destination), { recursive: true });
30
+
31
+ // 递归复制文件夹
32
+ fs.cpSync(source, destination, { recursive: true });
33
+
34
+ consola.success(`已成功复制 .claude/agents 到 ${destination}`);
35
+ }
package/src/print.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { isPlainObject, isArray } from "lodash-es";
2
2
  import { isConditionsSome } from "./conditions";
3
+ import consola from "consola";
3
4
 
4
5
  /**
5
6
  * 一个简单的格式化函数
@@ -21,3 +22,29 @@ export function printFormat(params: any) {
21
22
 
22
23
  return res;
23
24
  }
25
+
26
+ export interface PrintListParams {
27
+ /** 标题,可以是字符串或根据列表生成标题的函数 */
28
+ title: ((stringList: string[]) => string) | string;
29
+ /** 要显示的字符串列表 */
30
+ stringList: string[];
31
+ }
32
+
33
+ /**
34
+ * 输出字符串列表
35
+ * @description
36
+ * 1. 生成编号列表文本
37
+ * 2. 生成标题文本
38
+ * 3. 输出标题和列表
39
+ */
40
+ export function printList({ title, stringList }: PrintListParams): void {
41
+ // 生成编号列表文本
42
+ const listText = stringList.map((item, index) => `${index + 1}. ${item}`).join("\n");
43
+
44
+ // 生成标题文本
45
+ const titleText = typeof title === "function" ? title(stringList) : title;
46
+
47
+ // 输出标题和列表
48
+ consola.info(titleText);
49
+ consola.box(listText);
50
+ }
package/tsconfig.json CHANGED
@@ -26,25 +26,19 @@
26
26
  "skipLibCheck": true,
27
27
  // 需要使用 ThisType 工具
28
28
  "noImplicitThis": true,
29
- "types": [
30
- "typedoc",
31
- "typedoc-plugin-markdown",
32
- "node"
33
- ],
29
+ "types": ["typedoc", "typedoc-plugin-markdown", "node"],
34
30
  "paths": {
35
- "@ruan-cat/utils/*": [
36
- "./src/*"
37
- ]
38
- },
31
+ "@ruan-cat/utils/*": ["./src/*"]
32
+ }
39
33
  },
40
34
  "include": [
41
- "./src/**/*.ts",
35
+ "./src/**/*.ts"
42
36
  // "./src/**/*.js",
43
37
  // "./tests/**/*.ts",
44
38
  // "./tests/**/*.js",
45
39
  ],
46
40
  "exclude": [
47
41
  // 测试用例的全部文件 交由本项目根目录下的 tsconfig.json 处理
48
- "src/tests/**/*.ts",
42
+ "src/tests/**/*.ts"
49
43
  ]
50
- }
44
+ }