@done-coding/cli-inject 0.5.19 → 0.5.20

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,7 +1,184 @@
1
1
  # @done-coding/cli-inject
2
2
 
3
- done-coding信息(JSON)注入命令行工具
3
+ 信息(JSON)注入命令行工具 - 将 JSON 数据注入到文件中
4
4
 
5
- ## 使用
5
+ [![npm version](https://badge.fury.io/js/@done-coding%2Fcli-inject.svg)](https://www.npmjs.com/package/@done-coding/cli-inject)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
7
 
8
+ ## 安装
9
+
10
+ ### 独立安装
11
+ ```bash
7
12
  npm install @done-coding/cli-inject
13
+ # 或
14
+ pnpm add @done-coding/cli-inject
15
+ ```
16
+
17
+ ### 作为 done-coding CLI 的一部分
18
+ ```bash
19
+ npm install -g @done-coding/cli
20
+ # 然后使用
21
+ DC inject [command]
22
+ ```
23
+
24
+ ## 快速开始
25
+
26
+ ```bash
27
+ # 独立使用
28
+ dc-inject [command]
29
+
30
+ # 作为主 CLI 的子命令
31
+ DC inject [command]
32
+
33
+ # 查看帮助
34
+ dc-inject --help
35
+ ```
36
+
37
+ ## 功能特性
38
+
39
+ - ✅ **JSON 注入**: 将 JSON 数据注入到指定文件中
40
+ - 🔧 **配置管理**: 支持配置文件管理注入规则
41
+ - 📁 **目录支持**: 支持指定运行目录和配置文件路径
42
+ - 🔄 **批量处理**: 支持批量注入操作
43
+
44
+ ## API 文档
45
+
46
+ ### 基础命令
47
+
48
+ #### `dc-inject init`
49
+ 初始化配置文件
50
+
51
+ ```bash
52
+ # 创建默认配置文件
53
+ dc-inject init
54
+ ```
55
+
56
+ #### `dc-inject` (默认命令)
57
+ 生成文件
58
+
59
+ ```bash
60
+ # 使用默认配置生成文件
61
+ dc-inject
62
+
63
+ # 指定运行目录
64
+ dc-inject -R ./src
65
+
66
+ # 指定配置文件路径
67
+ dc-inject -C ./custom-config.json
68
+ ```
69
+
70
+ **选项说明**:
71
+ - `-R, --rootDir`: 运行目录
72
+ - `-C, --configPath`: 配置文件相对路径,默认为 `./.done-coding/inject.json`
73
+
74
+ ## 使用示例
75
+
76
+ ### 基础使用场景
77
+
78
+ ```bash
79
+ # 1. 初始化配置
80
+ dc-inject init
81
+
82
+ # 2. 执行注入操作
83
+ dc-inject
84
+
85
+ # 3. 指定不同的运行目录
86
+ dc-inject -R ./packages/core
87
+ ```
88
+
89
+ ### 作为主 CLI 的一部分
90
+
91
+ ```bash
92
+ # Windows 系统
93
+ dc inject init
94
+ dc inject -R ./src
95
+
96
+ # macOS/Linux 系统
97
+ DC inject init
98
+ DC inject -R ./src
99
+ ```
100
+
101
+ ## 配置
102
+
103
+ 通过 `dc-inject init` 命令可以初始化配置文件 `.done-coding/inject.json`。
104
+
105
+ 具体的配置选项需要查看初始化后生成的配置文件内容。
106
+
107
+ ## 编程接口
108
+
109
+ 本包提供了编程接口,具体的导出内容请查看包的类型定义文件。
110
+
111
+ ## 故障排除
112
+
113
+ ### 常见问题
114
+
115
+ **Q: 配置文件找不到**
116
+ ```bash
117
+ # 检查配置文件是否存在
118
+ ls -la .done-coding/inject.json
119
+
120
+ # 重新初始化配置
121
+ dc-inject init
122
+ ```
123
+
124
+ **Q: 注入失败**
125
+ ```bash
126
+ # 检查运行目录
127
+ dc-inject -R ./src
128
+
129
+ # 检查配置文件路径
130
+ dc-inject -C ./custom-config.json
131
+ ```
132
+
133
+ ### 调试模式
134
+
135
+ ```bash
136
+ # 查看版本信息
137
+ dc-inject --version
138
+
139
+ # 查看帮助信息
140
+ dc-inject --help
141
+ ```
142
+
143
+ ## 贡献指南
144
+
145
+ 我们欢迎贡献!请遵循以下步骤:
146
+
147
+ 1. Fork 本仓库
148
+ 2. 创建功能分支:`git checkout -b feature/amazing-feature`
149
+ 3. 提交更改:`git commit -m "feat: add amazing feature"`
150
+ 4. 推送分支:`git push origin feature/amazing-feature`
151
+ 5. 创建 Pull Request
152
+
153
+ ### 开发环境设置
154
+
155
+ ```bash
156
+ # 克隆仓库
157
+ git clone https://gitee.com/done-coding/done-coding-cli.git
158
+ cd done-coding-cli/packages/inject
159
+
160
+ # 安装依赖
161
+ pnpm install
162
+
163
+ # 开发模式
164
+ pnpm dev
165
+
166
+ # 构建
167
+ pnpm build
168
+
169
+ # 本地开发测试
170
+ node es/cli.mjs --help
171
+
172
+ # 注意:本地使用 node + 入口文件,发布后使用 bin 命令名
173
+ # 功能完全一致,只是调用方式不同
174
+ ```
175
+
176
+ ## 许可证
177
+
178
+ MIT © [JustSoSu](https://gitee.com/done-coding)
179
+
180
+ ## 相关链接
181
+
182
+ - [主 CLI 工具](https://www.npmjs.com/package/@done-coding/cli)
183
+ - [Gitee 仓库](https://gitee.com/done-coding/done-coding-cli)
184
+ - [更新日志](./CHANGELOG.md)
package/es/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { c as m } from "./index-3b0208e2.js";
2
+ import { c as m } from "./index-b3f74005.js";
3
3
  import "./index-a1ee6691.js";
4
4
  import "@done-coding/cli-utils";
5
5
  import "node:path";
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { I as c, S as E } from "./index-a1ee6691.js";
3
3
  import { log as o, _get as I, initHandlerCommon as k, getConfigFileCommonOptions as A, _set as w, readConfigFile as T, createSubcommand as N, getRootScriptName as _, createMainCommand as M } from "@done-coding/cli-utils";
4
- import $ from "node:path";
4
+ import D from "node:path";
5
5
  import u from "node:fs";
6
6
  const x = ({
7
7
  sourceJson: e,
@@ -36,7 +36,7 @@ const x = ({
36
36
  }
37
37
  }, d = {
38
38
  name: "@done-coding/cli-inject",
39
- version: "0.5.19",
39
+ version: "0.5.20",
40
40
  description: "信息(JSON)注入命令行工具",
41
41
  bin: {
42
42
  "dc-inject": "es/cli.mjs"
@@ -47,7 +47,7 @@ const x = ({
47
47
  }
48
48
  }, {
49
49
  cliConfig: { namespaceDir: G, moduleName: J }
50
- } = d, L = `./${G}/${J}`, R = `${L}.json`, h = {
50
+ } = d, L = `./${G}/${J}`, R = `${L}.json`, U = {
51
51
  sourceFilePath: "./package.json",
52
52
  keyConfigMap: {
53
53
  name: {
@@ -64,22 +64,22 @@ const x = ({
64
64
  }
65
65
  },
66
66
  injectFilePath: "./src/injectInfo.json"
67
- }, U = () => A({
67
+ }, h = U, V = () => A({
68
68
  configPathDefault: R
69
69
  }), S = async (e) => k(h, e, {
70
70
  onFileGenerated: () => {
71
71
  o.info("文件生成成功");
72
72
  }
73
- }), V = {
73
+ }), H = {
74
74
  command: E.INIT,
75
75
  describe: "初始化配置文件",
76
- options: U(),
76
+ options: V(),
77
77
  handler: S
78
- }, H = () => ({
78
+ }, K = () => ({
79
79
  ...A({
80
80
  configPathDefault: R
81
81
  })
82
- }), K = async ({
82
+ }), W = async ({
83
83
  rootDir: e = process.cwd(),
84
84
  config: n = h,
85
85
  keyConfigMap: t = {}
@@ -96,13 +96,13 @@ const x = ({
96
96
  return o.error("源文件必须是json"), process.exit(1);
97
97
  if (!r.endsWith(".json"))
98
98
  return o.error("注入文件必须是json"), process.exit(1);
99
- const p = $.resolve(e, s), g = u.readFileSync(p, "utf-8"), y = JSON.parse(g), i = Object.entries(f).reduce(
99
+ const p = D.resolve(e, s), g = u.readFileSync(p, "utf-8"), y = JSON.parse(g), i = Object.entries(f).reduce(
100
100
  (m, [F, v]) => {
101
101
  const P = x({ sourceJson: y, targetKey: F, keyConfig: v });
102
102
  return w(m, F, P), m;
103
103
  },
104
104
  {}
105
- ), l = $.resolve(e, r), C = JSON.stringify(i, null, 2);
105
+ ), l = D.resolve(e, r), C = JSON.stringify(i, null, 2);
106
106
  if (u.existsSync(l)) {
107
107
  const m = u.readFileSync(l, "utf-8");
108
108
  if (C === m)
@@ -116,13 +116,13 @@ const x = ({
116
116
  if (!n)
117
117
  return o.error("配置文件为空"), process.exit(1);
118
118
  const { rootDir: t } = e;
119
- await K({ rootDir: t, config: n });
120
- }, W = {
119
+ await W({ rootDir: t, config: n });
120
+ }, X = {
121
121
  command: "$0",
122
122
  describe: "生成文件",
123
- options: H(),
123
+ options: K(),
124
124
  handler: j
125
- }, Z = async (e, n) => {
125
+ }, ee = async (e, n) => {
126
126
  switch (e) {
127
127
  case E.INIT:
128
128
  return S(n);
@@ -131,34 +131,34 @@ const x = ({
131
131
  default:
132
132
  return j(n);
133
133
  }
134
- }, { version: X, description: q } = d, b = {
135
- describe: q,
136
- version: X,
137
- subcommands: [V, W].map(
134
+ }, { version: q, description: z } = d, b = {
135
+ describe: z,
136
+ version: q,
137
+ subcommands: [H, X].map(
138
138
  N
139
139
  ),
140
140
  demandCommandCount: 1,
141
141
  rootScriptName: _({ packageJson: d })
142
142
  }, {
143
- cliConfig: { moduleName: D }
143
+ cliConfig: { moduleName: $ }
144
144
  } = d, O = (e = !1) => {
145
- const n = e ? D : void 0, t = `$0${e ? ` ${D}` : ""} <command> [options]`;
145
+ const n = e ? $ : void 0, t = `$0${e ? ` ${$}` : ""} <command> [options]`;
146
146
  return { command: n, usage: t };
147
- }, ee = async () => M({
147
+ }, ne = async () => M({
148
148
  ...b,
149
149
  ...O()
150
- }), ne = () => N({
150
+ }), oe = () => N({
151
151
  ...b,
152
152
  ...O(!0)
153
153
  });
154
154
  export {
155
- ne as a,
156
- V as b,
157
- ee as c,
155
+ oe as a,
156
+ H as b,
157
+ ne as c,
158
158
  j as d,
159
- W as e,
160
- Z as f,
161
- K as g,
159
+ X as e,
160
+ ee as f,
161
+ W as g,
162
162
  S as h,
163
163
  b as i,
164
164
  x as k
package/es/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { i as r, a as i, e as s, g as t, d, f as l, b as f, h as p, k as C } from "./index-3b0208e2.js";
2
+ import { i as r, a as i, e as s, g as t, d, f as l, b as f, h as p, k as C } from "./index-b3f74005.js";
3
3
  import { I as g, S as u } from "./index-a1ee6691.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/cli-inject",
3
- "version": "0.5.19",
3
+ "version": "0.5.20",
4
4
  "description": "信息(JSON)注入命令行工具",
5
5
  "private": false,
6
6
  "module": "es/index.mjs",
@@ -64,7 +64,7 @@
64
64
  "node": ">=18.0.0"
65
65
  },
66
66
  "dependencies": {
67
- "@done-coding/cli-utils": "0.8.0"
67
+ "@done-coding/cli-utils": "0.8.1"
68
68
  },
69
- "gitHead": "e68f726aa899f75c4d294b11620f343c953a74c3"
69
+ "gitHead": "0930f800167c04a86b56eae9741872dd51bec0c6"
70
70
  }