done-coding-extract 0.1.19 → 0.1.22

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/README.md CHANGED
@@ -1,11 +1,239 @@
1
1
  # @done-coding/cli-extract
2
2
 
3
+ 信息提取命令行工具 - 从项目中提取和生成各种信息文件
4
+
5
+ [![npm version](https://badge.fury.io/js/@done-coding%2Fcli-extract.svg)](https://www.npmjs.com/package/@done-coding/cli-extract)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ ## 安装
9
+
10
+ ### 独立安装
11
+ ```bash
12
+ npm install @done-coding/cli-extract
13
+ # 或
14
+ pnpm add @done-coding/cli-extract
3
15
  ```
4
- 信息提取命令行工具
16
+
17
+ ### 作为 done-coding CLI 的一部分
18
+ ```bash
19
+ npm install -g @done-coding/cli
20
+ # 然后使用
21
+ DC extract [command]
5
22
  ```
6
23
 
7
- ## 使用
24
+ ## 快速开始
8
25
 
9
- ``` bash
10
- npm install @done-coding/cli-extract
11
- ```
26
+ ```bash
27
+ # 独立使用
28
+ dc-extract [command]
29
+
30
+ # 作为主 CLI 的子命令
31
+ DC extract [command]
32
+
33
+ # 查看帮助
34
+ dc-extract --help
35
+ ```
36
+
37
+ ## 功能特性
38
+
39
+ - ✅ **信息提取**: 从项目源码中提取各种信息
40
+ - 📄 **文件生成**: 基于提取的信息生成文档或配置文件
41
+ - 🔧 **模板支持**: 支持自定义模板进行信息格式化
42
+ - ⚙️ **配置灵活**: 支持多种配置方式和生成模式
43
+ - 🚀 **批量处理**: 支持批量提取和生成操作
44
+
45
+ ## API 文档
46
+
47
+ ### 基础命令
48
+
49
+ #### `dc-extract init`
50
+ 初始化配置文件
51
+
52
+ ```bash
53
+ # 创建默认配置文件
54
+ dc-extract init
55
+ ```
56
+
57
+ **功能说明**:
58
+ - 在项目根目录创建 `.done-coding/extract.json5` 配置文件
59
+ - 提供默认的提取规则和模板配置
60
+ - 支持自定义提取目标和输出格式
61
+
62
+ #### `dc-extract` (默认命令)
63
+ 生成文件
64
+
65
+ ```bash
66
+ # 使用默认配置生成文件
67
+ dc-extract
68
+
69
+ # 指定配置文件路径
70
+ dc-extract -C ./custom-config.json5
71
+
72
+ # 指定生成模式
73
+ dc-extract -m template
74
+
75
+ # 指定运行目录
76
+ dc-extract -R ./src
77
+ ```
78
+
79
+ **选项说明**:
80
+ - `-R, --rootDir`: 运行目录,默认为当前目录
81
+ - `-C, --configPath`: 配置文件相对路径,默认为 `./.done-coding/extract.json5`
82
+ - `-m, --mode`: 生成模式,可选值:`result`(默认)、`template`
83
+
84
+ ### 生成模式
85
+
86
+ #### result 模式
87
+ 直接生成最终结果文件
88
+
89
+ ```bash
90
+ # 生成结果文件
91
+ dc-extract -m result
92
+ ```
93
+
94
+ #### template 模式
95
+ 生成模板文件供进一步处理
96
+
97
+ ```bash
98
+ # 生成模板文件
99
+ dc-extract -m template
100
+ ```
101
+
102
+ ## 使用示例
103
+
104
+ ### 基础使用场景
105
+
106
+ ```bash
107
+ # 1. 初始化配置
108
+ dc-extract init
109
+
110
+ # 2. 编辑配置文件(可选)
111
+ # 编辑 .done-coding/extract.json5
112
+
113
+ # 3. 执行信息提取和文件生成
114
+ dc-extract
115
+
116
+ # 4. 检查生成的文件
117
+ ls -la output/
118
+ ```
119
+
120
+ ### 自定义配置使用
121
+
122
+ ```bash
123
+ # 使用自定义配置文件
124
+ dc-extract -C ./configs/my-extract.json5
125
+
126
+ # 指定不同的运行目录
127
+ dc-extract -R ./packages/core
128
+
129
+ # 生成模板文件而非最终结果
130
+ dc-extract -m template
131
+ ```
132
+
133
+ ### 作为主 CLI 的一部分
134
+
135
+ ```bash
136
+ # Windows 系统
137
+ dc extract init
138
+ dc extract -m result
139
+ dc extract -C ./config.json5
140
+
141
+ # macOS/Linux 系统
142
+ DC extract init
143
+ DC extract -m result
144
+ DC extract -C ./config.json5
145
+ ```
146
+
147
+ ## 配置
148
+
149
+ ### 配置文件
150
+
151
+ 通过 `dc-extract init` 命令可以初始化配置文件 `.done-coding/extract.json5`。
152
+
153
+ 具体的配置选项需要查看初始化后生成的配置文件内容。
154
+
155
+ ## 编程接口
156
+
157
+ 本包提供了编程接口,具体的导出内容请查看包的类型定义文件。
158
+
159
+ ## 故障排除
160
+
161
+ ### 常见问题
162
+
163
+ **Q: 配置文件找不到**
164
+ ```bash
165
+ # 检查配置文件是否存在
166
+ ls -la .done-coding/extract.json5
167
+
168
+ # 重新初始化配置
169
+ dc-extract init
170
+ ```
171
+
172
+ **Q: 生成失败**
173
+ ```bash
174
+ # 检查运行目录
175
+ dc-extract -R ./src
176
+
177
+ # 检查配置文件路径
178
+ dc-extract -C ./custom-config.json5
179
+ ```
180
+
181
+ ### 调试模式
182
+
183
+ ```bash
184
+ # 查看版本信息
185
+ dc-extract --version
186
+
187
+ # 查看帮助信息
188
+ dc-extract --help
189
+ ```
190
+
191
+ ## 性能建议
192
+
193
+ - 使用合适的文件匹配规则避免处理不必要的文件
194
+ - 启用缓存可以提高重复提取的速度
195
+ - 大项目建议使用并行处理模式
196
+
197
+ ## 贡献指南
198
+
199
+ 我们欢迎贡献!请遵循以下步骤:
200
+
201
+ 1. Fork 本仓库
202
+ 2. 创建功能分支:`git checkout -b feature/amazing-feature`
203
+ 3. 提交更改:`git commit -m "feat: add amazing feature"`
204
+ 4. 推送分支:`git push origin feature/amazing-feature`
205
+ 5. 创建 Pull Request
206
+
207
+ ### 开发环境设置
208
+
209
+ ```bash
210
+ # 克隆仓库
211
+ git clone https://gitee.com/done-coding/done-coding-cli.git
212
+ cd done-coding-cli/packages/extract
213
+
214
+ # 安装依赖
215
+ pnpm install
216
+
217
+ # 开发模式
218
+ pnpm dev
219
+
220
+ # 构建
221
+ pnpm build
222
+
223
+ # 本地开发测试
224
+ node es/cli.mjs --help
225
+
226
+ # 注意:本地使用 node + 入口文件,发布后使用 bin 命令名
227
+ # 功能完全一致,只是调用方式不同
228
+ ```
229
+
230
+ ## 许可证
231
+
232
+ MIT © [JustSoSu](https://gitee.com/done-coding)
233
+
234
+ ## 相关链接
235
+
236
+ - [主 CLI 工具](https://www.npmjs.com/package/@done-coding/cli)
237
+ - [模板处理工具](https://www.npmjs.com/package/@done-coding/cli-template) - 本包依赖的模板引擎
238
+ - [Gitee 仓库](https://gitee.com/done-coding/done-coding-cli)
239
+ - [更新日志](./CHANGELOG.md)
package/es/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { c as m } from "./index-898cd26e.js";
2
+ import { c as m } from "./index-694d5432.js";
3
3
  import "./index-a1ee6691-8c73eb4d.js";
4
4
  import "@done-coding/cli-utils";
5
5
  import "node:path";
@@ -1,12 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
  import { a as r, e as V, E as u, S as h, G as S } from "./index-a1ee6691-8c73eb4d.js";
3
- import { log as s, _get as J, createSubcommand as N, getRootScriptName as v, getConfigFileCommonOptions as j, initHandlerCommon as F, readConfigFile as x, _set as U, createMainCommand as W } from "@done-coding/cli-utils";
3
+ import { outputConsole as s, _get as J, createSubcommand as N, getRootScriptName as v, getConfigFileCommonOptions as j, initHandlerCommon as F, readConfigFile as x, _set as U, createMainCommand as W } from "@done-coding/cli-utils";
4
4
  import $ from "node:path";
5
- import y from "node:fs";
5
+ import g from "node:fs";
6
6
  import { OutputModeEnum as H, batchCompileHandler as X } from "@done-coding/cli-template";
7
7
  const D = {
8
8
  name: "@done-coding/cli-extract",
9
- version: "0.1.19",
9
+ version: "0.1.22",
10
10
  description: "信息提取命令行工具",
11
11
  bin: {
12
12
  "dc-extract": "es/cli.mjs"
@@ -50,7 +50,7 @@ const D = {
50
50
  }
51
51
  }, R = {
52
52
  name: "@done-coding/cli-inject",
53
- version: "0.5.19",
53
+ version: "0.5.22",
54
54
  description: "信息(JSON)注入命令行工具",
55
55
  bin: {
56
56
  "dc-inject": "es/cli.mjs"
@@ -110,21 +110,21 @@ const D = {
110
110
  return s.error("源文件必须是json"), process.exit(1);
111
111
  if (!c.endsWith(".json"))
112
112
  return s.error("注入文件必须是json"), process.exit(1);
113
- const l = $.resolve(e, t), f = y.readFileSync(l, "utf-8"), d = JSON.parse(f), i = Object.entries(m).reduce(
113
+ const l = $.resolve(e, t), f = g.readFileSync(l, "utf-8"), d = JSON.parse(f), i = Object.entries(m).reduce(
114
114
  (E, [b, M]) => {
115
115
  const L = C({ sourceJson: d, targetKey: b, keyConfig: M });
116
116
  return U(E, b, L), E;
117
117
  },
118
118
  {}
119
- ), p = $.resolve(e, c), g = JSON.stringify(i, null, 2);
120
- if (y.existsSync(p)) {
121
- const E = y.readFileSync(p, "utf-8");
122
- if (g === E)
119
+ ), p = $.resolve(e, c), y = JSON.stringify(i, null, 2);
120
+ if (g.existsSync(p)) {
121
+ const E = g.readFileSync(p, "utf-8");
122
+ if (y === E)
123
123
  return s.skip("注入文件已存在且内容相同,无需重复注入"), i;
124
124
  s.stage("文件内容变化,开始覆盖注入文件");
125
125
  } else
126
126
  s.stage("开始注入文件");
127
- y.writeFileSync(p, g), s.success(`文件注入成功: ${p}`), s.info(g);
127
+ g.writeFileSync(p, y), s.success(`文件注入成功: ${p}`), s.info(y);
128
128
  }, se = async (e) => {
129
129
  const n = await x(e, () => (s.info("配置文件为空,使用默认配置"), O));
130
130
  if (!n)
@@ -144,7 +144,7 @@ const ae = ({
144
144
  input: e,
145
145
  rootDir: n
146
146
  }) => {
147
- const o = $.resolve(n, e), t = y.readFileSync(o, "utf-8");
147
+ const o = $.resolve(n, e), t = g.readFileSync(o, "utf-8");
148
148
  return e.endsWith(".json") || e.endsWith(".json5") ? JSON.parse(t) : t;
149
149
  }, ue = (e) => typeof e == "object" && !!e, de = ({
150
150
  content: e,
@@ -259,7 +259,7 @@ const ae = ({
259
259
  default: S.RESULT,
260
260
  describe: "生成模式"
261
261
  }
262
- }), ge = async ({
262
+ }), ye = async ({
263
263
  rootDir: e = process.cwd(),
264
264
  config: n
265
265
  }) => {
@@ -271,12 +271,12 @@ const ae = ({
271
271
  });
272
272
  return Object.entries(l).reduce(
273
273
  (d, [i, p]) => {
274
- const g = de({
274
+ const y = de({
275
275
  content: f,
276
276
  targetKey: i,
277
277
  keyConfig: p
278
278
  });
279
- return d[i] = g, d;
279
+ return d[i] = y, d;
280
280
  },
281
281
  c
282
282
  );
@@ -295,8 +295,8 @@ const ae = ({
295
295
  if (!n)
296
296
  return s.error("配置文件为空"), process.exit(1);
297
297
  const { rootDir: o } = e;
298
- await ge({ rootDir: o, config: n });
299
- }, ye = {
298
+ await ye({ rootDir: o, config: n });
299
+ }, ge = {
300
300
  command: "$0",
301
301
  describe: "生成文件",
302
302
  options: fe(),
@@ -313,7 +313,7 @@ const ae = ({
313
313
  }, { version: Ee, description: Ce } = D, _ = {
314
314
  describe: Ce,
315
315
  version: Ee,
316
- subcommands: [le, ye].map(
316
+ subcommands: [le, ge].map(
317
317
  N
318
318
  ),
319
319
  demandCommandCount: 1,
@@ -335,9 +335,9 @@ export {
335
335
  le as b,
336
336
  Re as c,
337
337
  I as d,
338
- ye as e,
338
+ ge as e,
339
339
  Ne as f,
340
- ge as g,
340
+ ye as g,
341
341
  G as h,
342
342
  _ as i
343
343
  };
package/es/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { i as t, a as i, e as s, g as d, d as l, f as p, b as f, h as u } from "./index-898cd26e.js";
2
+ import { i as t, a as i, e as s, g as d, d as l, f as p, b as f, h as u } from "./index-694d5432.js";
3
3
  import { E as C, G as E, S as b } from "./index-a1ee6691-8c73eb4d.js";
4
4
  import "@done-coding/cli-utils";
5
5
  import "node:path";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "done-coding-extract",
3
- "version": "0.1.19",
3
+ "version": "0.1.22",
4
4
  "description": "信息提取命令行工具",
5
5
  "private": false,
6
6
  "module": "es/index.mjs",
@@ -42,21 +42,20 @@
42
42
  "license": "MIT",
43
43
  "sideEffects": false,
44
44
  "devDependencies": {
45
- "@done-coding/cli-inject": "0.5.19",
45
+ "@done-coding/cli-inject": "0.5.22",
46
46
  "@types/node": "^18.0.0",
47
47
  "@types/yargs": "^17.0.28",
48
- "rimraf": "^6.0.1",
49
- "typescript": "^5.2.2",
48
+ "typescript": "^5.8.3",
50
49
  "vite": "^4.4.11",
51
50
  "vite-plugin-dts": "^3.6.0"
52
51
  },
52
+ "dependencies": {
53
+ "@done-coding/cli-template": "0.8.9",
54
+ "@done-coding/cli-utils": "0.8.3"
55
+ },
53
56
  "engines": {
54
57
  "node": ">=18.0.0"
55
58
  },
56
- "dependencies": {
57
- "@done-coding/cli-template": "0.8.6",
58
- "@done-coding/cli-utils": "0.8.0"
59
- },
60
- "gitHead": "e68f726aa899f75c4d294b11620f343c953a74c3",
59
+ "gitHead": "4893b466954ef5925151d8dfc8fc8aa558ce654c",
61
60
  "scripts": {}
62
61
  }
package/types/index.d.ts CHANGED
@@ -76,7 +76,7 @@ export declare const generateCommandCliInfo: SubCliInfo;
76
76
 
77
77
  /** 将提取的信息生成文件 */
78
78
  export declare const generateFile: ({ rootDir, config, }: {
79
- rootDir?: string | undefined;
79
+ rootDir?: string;
80
80
  config: ExtractConfig;
81
81
  }) => Promise<void>;
82
82