@done-coding/cli-config 0.1.11 → 0.1.12

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,222 @@
1
1
  # @done-coding/cli-config
2
2
 
3
+ 工程化配置命令行工具 - 检测和管理项目工程化配置
4
+
5
+ [![npm version](https://badge.fury.io/js/@done-coding%2Fcli-config.svg)](https://www.npmjs.com/package/@done-coding/cli-config)
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-config
13
+ # 或
14
+ pnpm add @done-coding/cli-config
3
15
  ```
4
- 工程化配置命令行工具
16
+
17
+ ### 作为 done-coding CLI 的一部分
18
+ ```bash
19
+ npm install -g @done-coding/cli
20
+ # 然后使用
21
+ DC config [command]
5
22
  ```
6
23
 
7
- ## 使用
24
+ ## 快速开始
8
25
 
9
- ``` bash
10
- npm install @done-coding/cli-config
11
- ```
26
+ ```bash
27
+ # 独立使用
28
+ dc-config [command]
29
+
30
+ # 作为主 CLI 的子命令
31
+ DC config [command]
32
+
33
+ # 查看帮助
34
+ dc-config --help
35
+ ```
36
+
37
+ ## 功能特性
38
+
39
+ - ✅ **配置检测**: 自动检测项目的工程化配置状态
40
+ - 🔧 **配置添加**: 快速添加常用的工程化配置
41
+ - 🔍 **Git 集成**: 集成 git 包的合并检测功能
42
+ - 📋 **规范检查**: 检查代码规范和项目结构
43
+ - 🚀 **一键配置**: 提供常用工程化工具的快速配置
44
+
45
+ ## API 文档
46
+
47
+ ### 基础命令
48
+
49
+ #### `dc-config check`
50
+ 检测工程化配置
51
+
52
+ ```bash
53
+ # 检测当前项目的工程化配置
54
+ dc-config check
55
+ ```
56
+
57
+ #### `dc-config add`
58
+ 添加工程化配置
59
+
60
+ ```bash
61
+ # 添加工程化配置
62
+ dc-config add
63
+ ```
64
+
65
+ ## 使用示例
66
+
67
+ ### 基础使用场景
68
+
69
+ ```bash
70
+ # 1. 检测当前项目配置状态
71
+ dc-config check
72
+
73
+ # 2. 添加工程化配置
74
+ dc-config add
75
+ ```
76
+
77
+ ### 作为主 CLI 的一部分
78
+
79
+ ```bash
80
+ # Windows 系统
81
+ dc config check
82
+ dc config add
83
+
84
+ # macOS/Linux 系统
85
+ DC config check
86
+ DC config add
87
+ ```
88
+
89
+ ## 配置
90
+
91
+ 本包支持配置文件,具体的配置选项需要查看包的实际实现。
92
+
93
+ ## 编程接口
94
+
95
+ 本包提供了编程接口,具体的导出内容请查看包的类型定义文件。
96
+
97
+ ## Git 合并检测集成
98
+
99
+ 本包集成了 `@done-coding/cli-git` 包的合并检测功能:
100
+
101
+ ### merge-lint 模块
102
+
103
+ 当执行 `dc-config check` 时,会自动调用 `dc-git check reverse-merge` 命令:
104
+
105
+ ```bash
106
+ # 自动执行的检测流程
107
+ dc-config check
108
+ ├── 检测 ESLint 配置
109
+ ├── 检测 Prettier 配置
110
+ ├── 检测 TypeScript 配置
111
+ ├── 检测 Git 钩子配置
112
+ └── 调用 dc-git check reverse-merge # 检测反向合并
113
+ ```
114
+
115
+ ### 反向合并检测
116
+
117
+ 防止将高级分支合并到低级分支:
118
+
119
+ - 防止 `main` 分支被合并到 `feature` 分支
120
+ - 防止 `develop` 分支被合并到个人开发分支
121
+ - 确保分支合并方向符合 Git Flow 规范
122
+
123
+ ## 故障排除
124
+
125
+ ### 常见问题
126
+
127
+ **Q: 配置检测失败**
128
+ ```bash
129
+ # 检查项目根目录
130
+ pwd
131
+
132
+ # 检查是否为 Git 仓库
133
+ git status
134
+
135
+ # 使用详细模式查看错误
136
+ dc-config check --verbose
137
+ ```
138
+
139
+ **Q: Git 合并检测报错**
140
+ ```bash
141
+ # 确保 git 包已安装
142
+ dc-git --version
143
+
144
+ # 手动执行 git 检测
145
+ dc-git check reverse-merge
146
+
147
+ # 检查 Git 仓库状态
148
+ git log --oneline -10
149
+ ```
150
+
151
+ **Q: 配置添加失败**
152
+ ```bash
153
+ # 检查写入权限
154
+ ls -la .
155
+
156
+ # 检查 npm/pnpm 可用性
157
+ npm --version
158
+ pnpm --version
159
+
160
+ # 清理缓存重试
161
+ npm cache clean --force
162
+ ```
163
+
164
+ ### 调试模式
165
+
166
+ ```bash
167
+ # 启用详细输出
168
+ dc-config --verbose check
169
+
170
+ # 启用调试模式
171
+ DEBUG=done-coding:config dc-config check
172
+ ```
173
+
174
+ ## 性能建议
175
+
176
+ - 定期运行配置检测确保项目规范性
177
+ - 使用 Git 钩子自动执行配置检测
178
+ - 团队协作时统一工程化配置标准
179
+
180
+ ## 贡献指南
181
+
182
+ 我们欢迎贡献!请遵循以下步骤:
183
+
184
+ 1. Fork 本仓库
185
+ 2. 创建功能分支:`git checkout -b feature/amazing-feature`
186
+ 3. 提交更改:`git commit -m "feat: add amazing feature"`
187
+ 4. 推送分支:`git push origin feature/amazing-feature`
188
+ 5. 创建 Pull Request
189
+
190
+ ### 开发环境设置
191
+
192
+ ```bash
193
+ # 克隆仓库
194
+ git clone https://gitee.com/done-coding/done-coding-cli.git
195
+ cd done-coding-cli/packages/config
196
+
197
+ # 安装依赖
198
+ pnpm install
199
+
200
+ # 开发模式
201
+ pnpm dev
202
+
203
+ # 构建
204
+ pnpm build
205
+
206
+ # 本地开发测试
207
+ node es/cli.mjs --help
208
+
209
+ # 注意:本地使用 node + 入口文件,发布后使用 bin 命令名
210
+ # 功能完全一致,只是调用方式不同
211
+ ```
212
+
213
+ ## 许可证
214
+
215
+ MIT © [JustSoSu](https://gitee.com/done-coding)
216
+
217
+ ## 相关链接
218
+
219
+ - [主 CLI 工具](https://www.npmjs.com/package/@done-coding/cli)
220
+ - [Git 操作工具](https://www.npmjs.com/package/@done-coding/cli-git) - 本包调用的 Git 检测功能
221
+ - [Gitee 仓库](https://gitee.com/done-coding/done-coding-cli)
222
+ - [更新日志](./CHANGELOG.md)
package/es/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { c as m } from "./index-7d957358.js";
2
+ import { c as m } from "./index-6536e597.js";
3
3
  import "@done-coding/cli-utils";
4
4
  import "node:fs";
5
5
  import "node:path";
@@ -1,12 +1,12 @@
1
1
  #!/usr/bin/env node
2
- import { readConfigFile as B, log as i, getPackageJson as Q, getRelyPkgVersion as X, getConfigFileCommonOptions as Y, readCliModuleAssetsConfig as Z, xPrompts as w, addPackageConfig as ee, addHuskyHooks as te, createSubcommand as J, getRootScriptName as oe, createMainCommand as ne } from "@done-coding/cli-utils";
2
+ import { readConfigFile as B, log as i, getPackageJson as Q, getRelyPkgVersion as X, getConfigFileCommonOptions as Y, readCliModuleAssetsConfig as Z, xPrompts as w, addPackageConfig as ee, addHuskyHooks as te, createSubcommand as J, getRootScriptName as ne, createMainCommand as oe } from "@done-coding/cli-utils";
3
3
  import k, { existsSync as C } from "node:fs";
4
4
  import g from "node:path";
5
5
  import { execSync as N } from "node:child_process";
6
6
  var y = /* @__PURE__ */ ((e) => (e.CHECK = "check", e.ADD = "add", e))(y || {}), m = /* @__PURE__ */ ((e) => (e.ESLINT = "eslint", e.PRETTIER = "prettier", e.COMMITLINT = "commitlint", e.LSLINT = "ls-lint", e.MERGELINT = "merge-lint", e))(m || {});
7
7
  const L = {
8
8
  name: "@done-coding/cli-config",
9
- version: "0.1.11",
9
+ version: "0.1.12",
10
10
  description: "工程化配置命令行工具",
11
11
  bin: {
12
12
  "dc-config": "es/cli.mjs"
@@ -36,59 +36,59 @@ const L = {
36
36
  [m.COMMITLINT]: "@commitlint/cli",
37
37
  [m.LSLINT]: "@ls-lint/ls-lint",
38
38
  [m.MERGELINT]: "@done-coding/cli-git"
39
- }, o = "_$_", le = {
39
+ }, n = "_$_", le = {
40
40
  [m.ESLINT]: [
41
- `${o}.config.js`,
42
- `${o}.config.mjs`,
43
- `${o}.config.cjs`,
44
- `.${o}rc`,
45
- `.${o}rc.js`,
46
- `.${o}rc.json`,
47
- `.${o}rc.mjs`,
48
- `.${o}rc.cjs`,
49
- `.${o}rc.yaml`,
50
- `.${o}rc.yml`
41
+ `${n}.config.js`,
42
+ `${n}.config.mjs`,
43
+ `${n}.config.cjs`,
44
+ `.${n}rc`,
45
+ `.${n}rc.js`,
46
+ `.${n}rc.json`,
47
+ `.${n}rc.mjs`,
48
+ `.${n}rc.cjs`,
49
+ `.${n}rc.yaml`,
50
+ `.${n}rc.yml`
51
51
  ],
52
52
  [m.PRETTIER]: [
53
- `${o}.config.js`,
54
- `${o}.config.mjs`,
55
- `${o}.config.cjs`,
56
- `.${o}rc`,
57
- `.${o}rc.js`,
58
- `.${o}rc.json`,
59
- `.${o}rc.json5`,
60
- `.${o}rc.mjs`,
61
- `.${o}rc.cjs`,
62
- `.${o}rc.yaml`,
63
- `.${o}rc.yml`,
64
- `.${o}rc.toml`
53
+ `${n}.config.js`,
54
+ `${n}.config.mjs`,
55
+ `${n}.config.cjs`,
56
+ `.${n}rc`,
57
+ `.${n}rc.js`,
58
+ `.${n}rc.json`,
59
+ `.${n}rc.json5`,
60
+ `.${n}rc.mjs`,
61
+ `.${n}rc.cjs`,
62
+ `.${n}rc.yaml`,
63
+ `.${n}rc.yml`,
64
+ `.${n}rc.toml`
65
65
  ],
66
66
  [m.COMMITLINT]: [
67
- `${o}.config.js`,
68
- `${o}.config.mjs`,
69
- `${o}.config.cjs`,
70
- `.${o}rc`,
71
- `.${o}rc.js`,
72
- `.${o}rc.json`,
73
- `.${o}rc.mjs`,
74
- `.${o}rc.cjs`,
75
- `.${o}rc.yaml`,
76
- `.${o}rc.yml`
67
+ `${n}.config.js`,
68
+ `${n}.config.mjs`,
69
+ `${n}.config.cjs`,
70
+ `.${n}rc`,
71
+ `.${n}rc.js`,
72
+ `.${n}rc.json`,
73
+ `.${n}rc.mjs`,
74
+ `.${n}rc.cjs`,
75
+ `.${n}rc.yaml`,
76
+ `.${n}rc.yml`
77
77
  ],
78
- [m.LSLINT]: [`.${o}.yaml`, `.${o}.yml`],
78
+ [m.LSLINT]: [`.${n}.yaml`, `.${n}.yml`],
79
79
  [m.MERGELINT]: [".done-coding/git.json"]
80
- }, me = (e, t) => t.filter((n) => C(g.resolve(e, n))), _ = (e) => e.filter((t) => {
81
- const n = I.includes(t);
82
- return n || i.warn(
80
+ }, me = (e, t) => t.filter((o) => C(g.resolve(e, o))), _ = (e) => e.filter((t) => {
81
+ const o = I.includes(t);
82
+ return o || i.warn(
83
83
  `当前不支持${t}的配置检测, 支持的类型有${I.join(
84
84
  ", "
85
85
  )}`
86
- ), n;
86
+ ), o;
87
87
  }), de = ({
88
88
  config: e,
89
89
  rootDir: t
90
90
  }) => {
91
- const { moduleList: n = [] } = e, s = _(n);
91
+ const { moduleList: o = [] } = e, s = _(o);
92
92
  i.stage(`开始获取${s.join(", ")}配置信息...`);
93
93
  const r = Q({ rootDir: t });
94
94
  return s.reduce(
@@ -101,7 +101,7 @@ const L = {
101
101
  });
102
102
  if (!f)
103
103
  return a;
104
- const c = le[l].map((u) => u.replace(o, l));
104
+ const c = le[l].map((u) => u.replace(n, l));
105
105
  return c.length ? (a[l] = {
106
106
  version: f,
107
107
  configFileRelativePathList: me(
@@ -126,11 +126,11 @@ const L = {
126
126
  )
127
127
  }
128
128
  }), E = async (e) => {
129
- const t = await ae(e), n = de({ config: t, rootDir: e.rootDir });
129
+ const t = await ae(e), o = de({ config: t, rootDir: e.rootDir });
130
130
  return i.success(`检测到工程化配置信息:
131
- ${JSON.stringify(n, null, 2)}`), {
131
+ ${JSON.stringify(o, null, 2)}`), {
132
132
  config: t,
133
- info: n
133
+ info: o
134
134
  };
135
135
  }, ue = {
136
136
  command: y.CHECK,
@@ -161,7 +161,7 @@ ${JSON.stringify(n, null, 2)}`), {
161
161
  `${e} 跳过版本选择: 仅有一个预设版本配置, 默认选择第一个(${s.version})`
162
162
  ), s;
163
163
  }
164
- const { version: n } = await w({
164
+ const { version: o } = await w({
165
165
  type: "select",
166
166
  name: "version",
167
167
  message: `请选择需要添加的${e}版本`,
@@ -173,18 +173,18 @@ ${JSON.stringify(n, null, 2)}`), {
173
173
  };
174
174
  })
175
175
  });
176
- return t.find((s) => s.version === n);
176
+ return t.find((s) => s.version === o);
177
177
  }, pe = async ({
178
178
  moduleName: e,
179
179
  moduleConfig: t
180
180
  }) => {
181
- const { configFileInfoList: n } = t;
182
- if (!Array.isArray(n) || n.length === 0) {
181
+ const { configFileInfoList: o } = t;
182
+ if (!Array.isArray(o) || o.length === 0) {
183
183
  i.error(`未找到 ${e} 配置文件信息列表`);
184
184
  return;
185
185
  }
186
- if (n.length === 1) {
187
- const r = n[0];
186
+ if (o.length === 1) {
187
+ const r = o[0];
188
188
  return i.skip(
189
189
  `${e} 跳过配置文件信息选择: 仅有一个配置文件信息, 默认选择第一个(${r.sourceFile})`
190
190
  ), r;
@@ -193,7 +193,7 @@ ${JSON.stringify(n, null, 2)}`), {
193
193
  type: "select",
194
194
  name: "info",
195
195
  message: "请选择需要添加的配置文件",
196
- choices: n.map((r) => {
196
+ choices: o.map((r) => {
197
197
  const { sourceFile: a, description: l } = r;
198
198
  return {
199
199
  title: a,
@@ -202,10 +202,10 @@ ${JSON.stringify(n, null, 2)}`), {
202
202
  };
203
203
  })
204
204
  });
205
- return n.find((r) => r.sourceFile === s.sourceFile);
205
+ return o.find((r) => r.sourceFile === s.sourceFile);
206
206
  }, ye = ({ rootDir: e, list: t }) => {
207
207
  i.stage(`开始安装依赖包: ${JSON.stringify(t, null, 2)}`);
208
- const n = g.resolve(e, "pnpm-workspace.yaml"), s = C(n);
208
+ const o = g.resolve(e, "pnpm-workspace.yaml"), s = C(o);
209
209
  N(`pnpm add -D ${s ? "-w" : ""} ${t.join(" ")}`, {
210
210
  cwd: e,
211
211
  stdio: "inherit"
@@ -213,16 +213,16 @@ ${JSON.stringify(n, null, 2)}`), {
213
213
  }, Le = async ({
214
214
  hooksConfig: e,
215
215
  argv: t
216
- }) => Object.entries(e).forEach(async ([n, s]) => {
216
+ }) => Object.entries(e).forEach(async ([o, s]) => {
217
217
  await te({
218
- hookNames: [n],
218
+ hookNames: [o],
219
219
  rootDir: t.rootDir,
220
220
  getCode: () => s
221
221
  });
222
222
  }), he = async ({
223
223
  moduleName: e,
224
224
  moduleConfigList: t,
225
- argv: n
225
+ argv: o
226
226
  }) => {
227
227
  const s = await $e({
228
228
  moduleName: e,
@@ -252,7 +252,7 @@ ${JSON.stringify(n, null, 2)}`), {
252
252
  return i.stage(`需要安装的依赖包:
253
253
  ${JSON.stringify($, null, 2)}`), await ee({
254
254
  patchConfig: s.packageJson,
255
- rootDir: n.rootDir
255
+ rootDir: o.rootDir
256
256
  }), {
257
257
  sourceFile: u,
258
258
  targetFile: j,
@@ -264,21 +264,20 @@ ${JSON.stringify($, null, 2)}`), await ee({
264
264
  var p;
265
265
  return Le({
266
266
  hooksConfig: ((p = s.husky) == null ? void 0 : p.hooks) || {},
267
- argv: n
267
+ argv: o
268
268
  });
269
269
  }
270
270
  };
271
271
  }, ke = ({
272
272
  listConfig: e,
273
273
  moduleDir: t,
274
- moduleName: n
274
+ moduleName: o
275
275
  }) => {
276
276
  if (typeof e == "string") {
277
- console.log(e);
278
277
  const s = g.resolve(t, e);
279
278
  if (!C(s))
280
279
  throw new Error(
281
- `${n} 预设列表文件 ${s} 不存在`
280
+ `${o} 预设列表文件 ${s} 不存在`
282
281
  );
283
282
  const r = k.readFileSync(s, "utf-8");
284
283
  return JSON.parse(
@@ -287,13 +286,13 @@ ${JSON.stringify($, null, 2)}`), await ee({
287
286
  } else {
288
287
  if (!Array.isArray(e))
289
288
  throw new Error(
290
- `(${n})预置项必须是数组或者是相对于当前工程化配置模块目录的相对路径`
289
+ `(${o})预置项必须是数组或者是相对于当前工程化配置模块目录的相对路径`
291
290
  );
292
291
  return e;
293
292
  }
294
293
  }, b = async (e) => {
295
- const { config: t, info: n } = await E(e), { moduleList: s = [] } = t, a = _(s).filter((c) => {
296
- const u = n[c];
294
+ const { config: t, info: o } = await E(e), { moduleList: s = [] } = t, a = _(s).filter((c) => {
295
+ const u = o[c];
297
296
  return u ? (i.skip(`
298
297
  检测到 ${c} 已配置, ${JSON.stringify(u, null, 2)},
299
298
  跳过添加 ${c}`), !1) : !0;
@@ -389,13 +388,13 @@ ${JSON.stringify($, null, 2)}`), await ee({
389
388
  version: Ie,
390
389
  subcommands: [ue, Ne].map(J),
391
390
  demandCommandCount: 1,
392
- rootScriptName: oe({ packageJson: L })
391
+ rootScriptName: ne({ packageJson: L })
393
392
  }, {
394
393
  cliConfig: { moduleName: O }
395
394
  } = L, x = (e = !1) => {
396
- const t = e ? O : void 0, n = `$0${e ? ` ${O}` : ""} <command> [options]`;
397
- return { command: t, usage: n };
398
- }, Pe = async () => ne({
395
+ const t = e ? O : void 0, o = `$0${e ? ` ${O}` : ""} <command> [options]`;
396
+ return { command: t, usage: o };
397
+ }, Pe = async () => oe({
399
398
  ...G,
400
399
  ...x()
401
400
  }), Te = () => J({
package/es/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { C as i, S as s, a as t, h as u } from "./index-7d957358.js";
2
+ import { C as i, S as s, a as t, h as u } from "./index-6536e597.js";
3
3
  import "@done-coding/cli-utils";
4
4
  import "node:fs";
5
5
  import "node:path";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@done-coding/cli-config",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "description": "工程化配置命令行工具",
5
5
  "private": false,
6
6
  "module": "es/index.mjs",
@@ -41,7 +41,7 @@
41
41
  "license": "MIT",
42
42
  "sideEffects": false,
43
43
  "devDependencies": {
44
- "@done-coding/cli-inject": "0.5.19",
44
+ "@done-coding/cli-inject": "0.5.20",
45
45
  "@types/node": "^18.0.0",
46
46
  "@types/yargs": "^17.0.28",
47
47
  "rimraf": "^6.0.1",
@@ -53,7 +53,7 @@
53
53
  "node": ">=18.0.0"
54
54
  },
55
55
  "dependencies": {
56
- "@done-coding/cli-utils": "0.8.0"
56
+ "@done-coding/cli-utils": "0.8.1"
57
57
  },
58
- "gitHead": "e68f726aa899f75c4d294b11620f343c953a74c3"
58
+ "gitHead": "0930f800167c04a86b56eae9741872dd51bec0c6"
59
59
  }