done-coding-template 0.8.4 → 0.8.7

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,273 @@
1
1
  # @done-coding/cli-template
2
2
 
3
- 预编译命令行工具
3
+ 模板编译命令行工具 - 基于 Lodash 模板引擎的文件预编译工具
4
4
 
5
- ## 使用
5
+ [![npm version](https://badge.fury.io/js/@done-coding%2Fcli-template.svg)](https://www.npmjs.com/package/@done-coding/cli-template)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
7
 
8
+ ## 安装
9
+
10
+ ### 独立安装
11
+
12
+ ```bash
7
13
  npm install @done-coding/cli-template
14
+ # 或
15
+ pnpm add @done-coding/cli-template
16
+ ```
17
+
18
+ ### 作为 done-coding CLI 的一部分
19
+
20
+ ```bash
21
+ npm install -g @done-coding/cli
22
+ # 然后使用
23
+ DC template [command]
24
+ ```
25
+
26
+ ## 快速开始
27
+
28
+ ```bash
29
+ # 独立使用
30
+ dc-template [command]
31
+
32
+ # 作为主 CLI 的子命令
33
+ DC template [command]
34
+
35
+ # 查看帮助
36
+ dc-template --help
37
+ ```
38
+
39
+ ## 功能特性
40
+
41
+ - ✅ **模板编译**: 基于 Lodash 模板引擎编译模板文件
42
+ - 📁 **批量处理**: 支持批量编译多个模板文件
43
+ - 🔧 **配置管理**: 支持配置文件管理编译规则
44
+ - 🔄 **回滚功能**: 支持编译结果的回滚操作
45
+ - 📝 **Markdown 支持**: 支持 Markdown 代码块处理
46
+ - 🎯 **多种输出模式**: 支持覆盖、追加、替换等输出模式及对应的逆操作(回滚)
47
+
48
+ ## API 文档
49
+
50
+ ### 基础命令
51
+
52
+ #### `dc-template init`
53
+
54
+ 初始化配置文件
55
+
56
+ ```bash
57
+ # 创建默认配置文件
58
+ dc-template init
59
+ ```
60
+
61
+ #### `dc-template` (默认命令)
62
+
63
+ 编译模板
64
+
65
+ ```bash
66
+ # 使用默认配置编译模板
67
+ dc-template
68
+
69
+ # 指定模板文件和输出文件
70
+ dc-template -i template.hbs -o output.txt
71
+
72
+ # 指定环境数据文件
73
+ dc-template -e data.json
74
+
75
+ # 指定输出模式
76
+ dc-template -m append
77
+ ```
78
+
79
+ #### `dc-template batch`
80
+
81
+ 批量编译模板
82
+
83
+ ```bash
84
+ # 批量编译模板
85
+ dc-template batch
86
+
87
+ # 启用批量处理模式
88
+ dc-template -b true
89
+ ```
90
+
91
+ ### 命令选项
92
+
93
+ - `-e, --env`: 环境数据文件 JSON 文件相对路径(优先级高于 envData)
94
+ - `-E, --envData`: 环境变量数据(JSON 字符串)
95
+ - `-i, --input`: 模板文件相对路径(优先级高于 inputTemplate)
96
+ - `-I, --inputData`: 模板数据
97
+ - `-o, --output`: 输出文件路径
98
+ - `-m, --mode`: 输出模式,可选值:`overwrite`(默认)、`append`、`replace`、`return`
99
+ - `-b, --batch`: 是否批量处理,默认为 `false`
100
+ - `-R, --rootDir`: 运行目录
101
+ - `-C, --configPath`: 配置文件相对路径,默认为 `./.done-coding/template.json`
102
+ - `--rollbackDelAskAsYes`: 回滚删除询问默认 yes(即不再额外询问,直接认为同意),默认为 `false`
103
+ - `--rollbackDelNullFile`: 回滚时是否删除空文件,默认为 `false`
104
+ - `-d, --dealMarkdown`: (检测是 markdown)是否处理(单个)代码块包裹,默认为 `false`
105
+ - `-r, --rollback`: 是否回滚,默认为 `false`
106
+
107
+ ## 使用示例
108
+
109
+ ### 基础使用场景
110
+
111
+ ```bash
112
+ # 1. 初始化配置
113
+ dc-template init
114
+
115
+ # 2. 编译单个模板
116
+ dc-template -i template.hbs -o output.html
117
+
118
+ # 3. 使用环境数据文件
119
+ dc-template -i template.hbs -o output.html -e data.json
120
+
121
+ # 4. 批量编译模板
122
+ dc-template batch
123
+ ```
124
+
125
+ ### 不同输出模式
126
+
127
+ ```bash
128
+ # 覆盖模式(默认)
129
+ dc-template -i template.hbs -o output.txt -m overwrite
130
+
131
+ # 追加模式
132
+ dc-template -i template.hbs -o output.txt -m append
133
+
134
+ # 替换模式
135
+ dc-template -i template.hbs -o output.txt -m replace
136
+
137
+ # 返回模式(不写入文件)
138
+ dc-template -i template.hbs -m return
139
+ ```
140
+
141
+ ### 回滚操作
142
+
143
+ ```bash
144
+ # 执行回滚
145
+ dc-template -r true
146
+
147
+ # 回滚时自动确认删除
148
+ dc-template -r true --rollbackDelAskAsYes true
149
+
150
+ # 回滚时删除空文件
151
+ dc-template -r true --rollbackDelNullFile true
152
+ ```
153
+
154
+ ### Markdown 处理
155
+
156
+ ```bash
157
+ # 处理 Markdown 代码块
158
+ dc-template -i template.md -o output.md -d true
159
+ ```
160
+
161
+ ### 作为主 CLI 的一部分
162
+
163
+ ```bash
164
+ # Windows 系统
165
+ dc template init
166
+ dc template -i template.hbs -o output.txt
167
+ dc template batch
168
+
169
+ # macOS/Linux 系统
170
+ DC template init
171
+ DC template -i template.hbs -o output.txt
172
+ DC template batch
173
+ ```
174
+
175
+ ## 配置
176
+
177
+ 通过 `dc-template init` 命令可以初始化配置文件 `.done-coding/template.json`。
178
+
179
+ 具体的配置选项需要查看初始化后生成的配置文件内容。
180
+
181
+ ## 编程接口
182
+
183
+ 本包提供了编程接口,具体的导出内容请查看包的类型定义文件。
184
+
185
+ ## 故障排除
186
+
187
+ ### 常见问题
188
+
189
+ **Q: 配置文件找不到**
190
+
191
+ ```bash
192
+ # 检查配置文件是否存在
193
+ ls -la .done-coding/template.json
194
+
195
+ # 重新初始化配置
196
+ dc-template init
197
+ ```
198
+
199
+ **Q: 模板编译失败**
200
+
201
+ ```bash
202
+ # 检查模板文件是否存在
203
+ ls -la template.hbs
204
+
205
+ # 检查环境数据文件格式
206
+ cat data.json | jq .
207
+
208
+ # 验证模板语法
209
+ dc-template -i template.hbs -m return
210
+ ```
211
+
212
+ **Q: 回滚失败**
213
+
214
+ ```bash
215
+ # 检查是否有可回滚的操作
216
+ dc-template -r true
217
+
218
+ # 强制回滚并删除空文件
219
+ dc-template -r true --rollbackDelNullFile true
220
+ ```
221
+
222
+ ### 调试模式
223
+
224
+ ```bash
225
+ # 查看版本信息
226
+ dc-template --version
227
+
228
+ # 查看帮助信息
229
+ dc-template --help
230
+ ```
231
+
232
+ ## 贡献指南
233
+
234
+ 我们欢迎贡献!请遵循以下步骤:
235
+
236
+ 1. Fork 本仓库
237
+ 2. 创建功能分支:`git checkout -b feature/amazing-feature`
238
+ 3. 提交更改:`git commit -m "feat: add amazing feature"`
239
+ 4. 推送分支:`git push origin feature/amazing-feature`
240
+ 5. 创建 Pull Request
241
+
242
+ ### 开发环境设置
243
+
244
+ ```bash
245
+ # 克隆仓库
246
+ git clone https://gitee.com/done-coding/done-coding-cli.git
247
+ cd done-coding-cli/packages/template
248
+
249
+ # 安装依赖
250
+ pnpm install
251
+
252
+ # 开发模式
253
+ pnpm dev
254
+
255
+ # 构建
256
+ pnpm build
257
+
258
+ # 本地开发测试
259
+ node es/cli.mjs --help
260
+
261
+ # 注意:本地使用 node + 入口文件,发布后使用 bin 命令名
262
+ # 功能完全一致,只是调用方式不同
263
+ ```
264
+
265
+ ## 许可证
266
+
267
+ MIT © [JustSoSu](https://gitee.com/done-coding)
268
+
269
+ ## 相关链接
270
+
271
+ - [主 CLI 工具](https://www.npmjs.com/package/@done-coding/cli)
272
+ - [Gitee 仓库](https://gitee.com/done-coding/done-coding-cli)
273
+ - [更新日志](./CHANGELOG.md)
package/es/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { e as m } from "./main-166f76ed.js";
2
+ import { e as m } from "./main-a217c17b.js";
3
3
  import "node:path";
4
4
  import "node:fs";
5
5
  import "@done-coding/cli-utils";
package/es/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { M as r } from "./main-166f76ed.js";
3
- import { d as f, O as T, S as _, T as h, b as A, a as O, c as b, h as L } from "./main-166f76ed.js";
2
+ import { M as r } from "./main-a217c17b.js";
3
+ import { d as f, O as T, S as _, T as h, b as A, a as O, c as b, h as L } from "./main-a217c17b.js";
4
4
  import t from "node:path";
5
5
  import { existsSync as m } from "node:fs";
6
6
  import "@done-coding/cli-utils";
@@ -6,7 +6,7 @@ import L from "lodash.template";
6
6
  import q from "lodash.assign";
7
7
  const h = {
8
8
  name: "@done-coding/cli-template",
9
- version: "0.8.4",
9
+ version: "0.8.7",
10
10
  description: "预编译命令行工具",
11
11
  bin: {
12
12
  "dc-template": "es/cli.mjs"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "done-coding-template",
3
- "version": "0.8.4",
3
+ "version": "0.8.7",
4
4
  "description": "预编译命令行工具",
5
5
  "private": false,
6
6
  "module": "es/index.mjs",
@@ -31,7 +31,7 @@
31
31
  "license": "MIT",
32
32
  "sideEffects": false,
33
33
  "devDependencies": {
34
- "@done-coding/cli-inject": "0.5.17",
34
+ "@done-coding/cli-inject": "0.5.20",
35
35
  "@types/lodash.assign": "^4.2.9",
36
36
  "@types/lodash.template": "^4.5.3",
37
37
  "@types/node": "^18.0.0",
@@ -45,10 +45,10 @@
45
45
  "node": ">=18.0.0"
46
46
  },
47
47
  "dependencies": {
48
- "@done-coding/cli-utils": "0.7.7",
48
+ "@done-coding/cli-utils": "0.8.1",
49
49
  "lodash.assign": "^4.2.0",
50
50
  "lodash.template": "^4.5.0"
51
51
  },
52
- "gitHead": "60699aec488072491ef8643fafa9ffc4bdce48c3",
52
+ "gitHead": "0930f800167c04a86b56eae9741872dd51bec0c6",
53
53
  "scripts": {}
54
54
  }