juice-email-cli 2.1.7 → 2.1.8
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 +162 -112
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
# juice-email-cli
|
|
2
2
|
|
|
3
|
-
> 一个用于生成符合各大邮件平台标准的 HTML 邮件命令行工具,基于 [juice](https://github.com/Automattic/juice) 实现 CSS 内联,支持 Mustache
|
|
3
|
+
> 一个用于生成符合各大邮件平台标准的 HTML 邮件命令行工具,基于 [juice](https://github.com/Automattic/juice) 实现 CSS 内联,支持 Mustache 模板变量替换,同时输出标准版与压缩版。
|
|
4
4
|
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
## 功能特性
|
|
8
8
|
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
9
|
+
- **CSS 内联** —— 将 `<style>` 中的样式全部内联为 `style=""` 属性,兼容 Gmail / Outlook / Apple Mail 等
|
|
10
|
+
- **Mustache 模板变量** —— 支持 `{{变量名}}` 语法,通过配置文件批量替换
|
|
11
|
+
- **Mustache 列表循环** —— 支持 `{{#items}}...{{/items}}` 遍历数组,支持嵌套循环
|
|
12
|
+
- **片段组装** —— 将片段 HTML 插入模板的 `<tbody id="content">`,自动调整缩进,输出 4 个阶段文件
|
|
13
|
+
- **三层配置合并** —— CLI 默认 < 用户目录 < 优先配置,层层合并
|
|
14
|
+
- **HTML 标签渲染** —— 变量值中的 `<sup>`、`<sub>` 等 HTML 标签直接渲染(可通过 `rawHtml` 关闭)
|
|
15
|
+
- **双文件输出** —— 普通模式生成 `.output.html` + `.minified.html`
|
|
16
|
+
- **四文件输出** —— 片段模式生成 `.raw.html` + `.html` + `.output.html` + `.minified.html`
|
|
17
|
+
- **交互模式** —— 无参数运行,逐步选择品牌、模板、片段、配置
|
|
18
|
+
- **Windows 右键菜单** —— 子菜单层级,一键注册/卸载
|
|
16
19
|
|
|
17
20
|
---
|
|
18
21
|
|
|
@@ -42,32 +45,79 @@ npm link # 链接到全局
|
|
|
42
45
|
|
|
43
46
|
## 使用方法
|
|
44
47
|
|
|
48
|
+
### 普通模式(CSS 内联 + 压缩,输出 2 个文件)
|
|
49
|
+
|
|
45
50
|
```bash
|
|
46
|
-
#
|
|
51
|
+
# 最简用法
|
|
47
52
|
juice -f my-email.html
|
|
48
53
|
|
|
49
54
|
# 指定配置文件
|
|
50
55
|
juice -c project.yaml -f my-email.html
|
|
56
|
+
|
|
57
|
+
# 使用 EDM 模板库中的模板
|
|
58
|
+
juice -f edm/elabscience/elabscience-template.html
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
生成文件(与输入文件同目录):
|
|
62
|
+
|
|
63
|
+
| 文件 | 说明 |
|
|
64
|
+
|------|------|
|
|
65
|
+
| `<name>.output.html` | CSS 内联 + 变量替换后的标准版 |
|
|
66
|
+
| `<name>.minified.html` | 压缩版 |
|
|
67
|
+
|
|
68
|
+
### 片段模式(片段 + 模板拼接,输出 4 个文件)
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
# 完整指定片段和模板
|
|
72
|
+
juice -s edm/elabscience/literature/snippet.html -f edm/elabscience/elabscience-template.html
|
|
73
|
+
|
|
74
|
+
# 只指定片段,交互式选择模板
|
|
75
|
+
juice -s edm/elabscience/literature/snippet.html
|
|
76
|
+
|
|
77
|
+
# 自定义输出文件名
|
|
78
|
+
juice -s snippet.html -f template.html -n my-output
|
|
51
79
|
```
|
|
52
80
|
|
|
53
|
-
|
|
81
|
+
生成文件(当前工作目录):
|
|
54
82
|
|
|
55
83
|
| 文件 | 说明 |
|
|
56
84
|
|------|------|
|
|
57
|
-
|
|
|
58
|
-
|
|
|
85
|
+
| `<name>.raw.html` | 原始组装(Mustache 未渲染,无 CSS 内联) |
|
|
86
|
+
| `<name>.html` | 已渲染(Mustache 变量已替换,无 CSS 内联) |
|
|
87
|
+
| `<name>.output.html` | Juice CSS 内联后 |
|
|
88
|
+
| `<name>.minified.html` | 压缩版 |
|
|
89
|
+
|
|
90
|
+
输出文件名默认为模板文件名(不含扩展名)。如果文件冲突,交互模式下可选择覆盖、自动版本号(`-v1`、`-v2`...)或重新输入。
|
|
91
|
+
|
|
92
|
+
### 交互模式(逐步选择)
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
juice
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
流程:选择品牌 → 模板 → 片段文件夹 → 片段 HTML → 配置文件 → 输出文件名 → 确认执行。
|
|
59
99
|
|
|
60
100
|
### 参数说明
|
|
61
101
|
|
|
62
102
|
| 参数 | 简写 | 说明 |
|
|
63
103
|
|------|------|------|
|
|
64
|
-
| `--file <path>` | `-f` | 输入 HTML
|
|
65
|
-
| `--
|
|
104
|
+
| `--file <path>` | `-f` | 输入 HTML 模板文件路径 |
|
|
105
|
+
| `--snippet <path>` | `-s` | 片段 HTML 文件路径:插入到模板 `<tbody id="content">` |
|
|
106
|
+
| `--config <path>` | `-c` | 配置文件路径,不指定时自动查找 |
|
|
107
|
+
| `--name <name>` | `-n` | 片段模式输出文件名(不含扩展名) |
|
|
66
108
|
| `--install` | | 注册 Windows 右键菜单(需管理员权限) |
|
|
67
109
|
| `--uninstall` | | 取消 Windows 右键菜单注册(需管理员权限) |
|
|
68
110
|
| `--version` | `-v` | 查看版本号 |
|
|
69
111
|
| `--help` | `-h` | 查看帮助 |
|
|
70
112
|
|
|
113
|
+
### CLI 执行模式
|
|
114
|
+
|
|
115
|
+
| `-s` | `-f` | `-c` | 执行模式 |
|
|
116
|
+
|------|------|------|----------|
|
|
117
|
+
| ✓ | * | * | 片段模式(-s 指定片段,-f 可选指定模板) |
|
|
118
|
+
| ✗ | ✓ | * | 普通模式(生成 .output.html + .minified.html) |
|
|
119
|
+
| ✗ | ✗ | * | 交互式片段模式(逐步选择) |
|
|
120
|
+
|
|
71
121
|
---
|
|
72
122
|
|
|
73
123
|
## 配置文件优先级
|
|
@@ -97,11 +147,17 @@ juice -c project.yaml -f my-email.html
|
|
|
97
147
|
juice -c project.yaml -f email.html
|
|
98
148
|
|
|
99
149
|
# 使用输入文件同级目录配置(与用户目录合并)
|
|
100
|
-
# → email.html 同目录下有 juice.yaml
|
|
101
150
|
juice -f email.html
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### 片段模式配置
|
|
154
|
+
|
|
155
|
+
片段模式下,会自动检测片段目录下的 `juice.yaml` / `juice.yml` 作为项目配置参与合并:
|
|
102
156
|
|
|
103
|
-
|
|
104
|
-
|
|
157
|
+
```
|
|
158
|
+
优先级 低 ──────────────────────────────────────────────────────── 高
|
|
159
|
+
|
|
160
|
+
内置默认 < ~/juice.yaml < 片段目录 juice.yaml < -c 指定
|
|
105
161
|
```
|
|
106
162
|
|
|
107
163
|
---
|
|
@@ -111,6 +167,9 @@ juice -f email.html
|
|
|
111
167
|
用户配置文件(`~/juice.yaml` 或项目目录 `juice.yaml`)只需填写需要覆盖的字段,其余自动继承:
|
|
112
168
|
|
|
113
169
|
```yaml
|
|
170
|
+
# 设为 false 时,变量值中的 HTML 标签会被转义
|
|
171
|
+
rawHtml: true
|
|
172
|
+
|
|
114
173
|
variables:
|
|
115
174
|
brandName: "我的品牌"
|
|
116
175
|
brandColor: "#ff6600"
|
|
@@ -127,28 +186,17 @@ variables:
|
|
|
127
186
|
tag: "热销"
|
|
128
187
|
- name: "产品 B"
|
|
129
188
|
price: "¥199.00"
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
items:
|
|
136
|
-
- "优势 A"
|
|
137
|
-
- "优势 B"
|
|
138
|
-
- title: "特性二"
|
|
139
|
-
items:
|
|
140
|
-
- "优势 C"
|
|
141
|
-
- "优势 D"
|
|
189
|
+
|
|
190
|
+
# 变量值支持 HTML 标签(rawHtml: true 时)
|
|
191
|
+
overview:
|
|
192
|
+
title: "CD38-NAD<sup>+</sup> Axis Study"
|
|
193
|
+
keywords: "Immune Thrombocytopenia, NMN, NAD<sup>+</sup>"
|
|
142
194
|
|
|
143
195
|
# juice 选项(全部可选,均有内置默认值)
|
|
144
196
|
# juice:
|
|
145
197
|
# removeStyleTags: true
|
|
146
198
|
# preserveMediaQueries: true
|
|
147
|
-
# preservePseudos: true
|
|
148
|
-
# preservedSelectors: # 保留的选择器(不会被内联)
|
|
149
|
-
# - "a:hover"
|
|
150
|
-
# extraCssFiles:
|
|
151
|
-
# - email-reset.css
|
|
199
|
+
# preservePseudos: true
|
|
152
200
|
|
|
153
201
|
# 输出后缀(可选)
|
|
154
202
|
# output:
|
|
@@ -169,12 +217,26 @@ variables:
|
|
|
169
217
|
<a href="{{ctaUrl}}" style="background-color: {{brandColor}};">{{ctaText}}</a>
|
|
170
218
|
```
|
|
171
219
|
|
|
220
|
+
### HTML 标签在变量中
|
|
221
|
+
|
|
222
|
+
当 `rawHtml: true`(默认)时,变量值中的 HTML 标签直接渲染:
|
|
223
|
+
|
|
224
|
+
```yaml
|
|
225
|
+
variables:
|
|
226
|
+
overview:
|
|
227
|
+
keywords: "CD38-NAD<sup>+</sup> Axis, NO<sub>3</sub><sup>-</sup>"
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
```html
|
|
231
|
+
<p>{{overview.keywords}}</p>
|
|
232
|
+
<!-- 渲染为:CD38-NAD<sup>+</sup> Axis, NO<sub>3</sub><sup>-</sup> -->
|
|
233
|
+
```
|
|
234
|
+
|
|
172
235
|
### Mustache 列表循环
|
|
173
236
|
|
|
174
237
|
支持 `{{#items}}...{{/items}}` 语法遍历数组数据:
|
|
175
238
|
|
|
176
239
|
```yaml
|
|
177
|
-
# juice.yaml - 配置列表数据
|
|
178
240
|
variables:
|
|
179
241
|
products:
|
|
180
242
|
- name: "产品 A"
|
|
@@ -182,12 +244,9 @@ variables:
|
|
|
182
244
|
tag: "热销"
|
|
183
245
|
- name: "产品 B"
|
|
184
246
|
price: "¥199.00"
|
|
185
|
-
- name: "产品 C"
|
|
186
|
-
price: "¥299.00"
|
|
187
247
|
```
|
|
188
248
|
|
|
189
249
|
```html
|
|
190
|
-
<!-- HTML 模板 -->
|
|
191
250
|
{{#products}}
|
|
192
251
|
<div class="product-item">
|
|
193
252
|
<h3>{{name}}</h3>
|
|
@@ -196,55 +255,79 @@ variables:
|
|
|
196
255
|
</div>
|
|
197
256
|
{{/products}}
|
|
198
257
|
|
|
199
|
-
<!-- 空列表备选内容 -->
|
|
200
258
|
{{^products}}
|
|
201
259
|
<p>暂无商品</p>
|
|
202
260
|
{{/products}}
|
|
203
|
-
|
|
204
|
-
<!-- 嵌套循环示例 -->
|
|
205
|
-
{{#features}}
|
|
206
|
-
<div class="feature-column">
|
|
207
|
-
<h4>{{title}}</h4>
|
|
208
|
-
<ul>
|
|
209
|
-
{{#items}}
|
|
210
|
-
<li>{{.}}</li>
|
|
211
|
-
{{/items}}
|
|
212
|
-
</ul>
|
|
213
|
-
</div>
|
|
214
|
-
{{/features}}
|
|
215
261
|
```
|
|
216
262
|
|
|
217
263
|
| 语法 | 说明 | 示例 |
|
|
218
264
|
|------|------|------|
|
|
219
265
|
| `{{#list}}{{/list}}` | 循环遍历 | `{{#products}}{{name}}{{/products}}` |
|
|
220
266
|
| `{{^list}}{{/list}}` | 反向(空列表时显示) | `{{^products}}暂无{{/products}}` |
|
|
221
|
-
| `{{.}}` | 当前元素 | `{{
|
|
267
|
+
| `{{.}}` | 当前元素 | `{{#items}}{{.}}{{/items}}` |
|
|
222
268
|
| `{{#var}}{{/var}}` | 条件渲染(仅当有值时显示) | `{{#tag}}{{tag}}{{/tag}}` |
|
|
223
269
|
|
|
224
270
|
---
|
|
225
271
|
|
|
226
|
-
##
|
|
272
|
+
## 片段组装
|
|
227
273
|
|
|
228
|
-
|
|
274
|
+
### EDM 目录结构
|
|
229
275
|
|
|
230
276
|
```
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
277
|
+
edm/
|
|
278
|
+
├── <brand>/ # 品牌目录
|
|
279
|
+
│ ├── <brand>-template.html # 品牌模板(含 <tbody id="content">)
|
|
280
|
+
│ └── <series>/ # 片段系列目录
|
|
281
|
+
│ ├── snippet.html # 片段 HTML(Mustache 模板片段)
|
|
282
|
+
│ └── juice.yaml # 片段配置(variables)
|
|
234
283
|
```
|
|
235
284
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
285
|
+
### 片段 HTML 格式
|
|
286
|
+
|
|
287
|
+
片段是模板中 `<tbody id="content">` 内的内容片段,会被自动插入并调整缩进:
|
|
239
288
|
|
|
240
|
-
|
|
241
|
-
|
|
289
|
+
```html
|
|
290
|
+
<!-- edm/elabscience/literature/snippet.html -->
|
|
291
|
+
<tr>
|
|
292
|
+
<td></td>
|
|
293
|
+
<td colspan="2">
|
|
294
|
+
<table>
|
|
295
|
+
<tbody>
|
|
296
|
+
<tr>
|
|
297
|
+
<td><img src="{{overview.image}}" /></td>
|
|
298
|
+
<td><strong>{{overview.title}}</strong></td>
|
|
299
|
+
</tr>
|
|
300
|
+
</tbody>
|
|
301
|
+
</table>
|
|
302
|
+
</td>
|
|
303
|
+
<td></td>
|
|
304
|
+
</tr>
|
|
242
305
|
```
|
|
243
306
|
|
|
244
|
-
|
|
245
|
-
> 注册成功后如菜单未立即出现,重启文件资源管理器(`explorer.exe`)即可。
|
|
307
|
+
### 跨品牌检查
|
|
246
308
|
|
|
247
|
-
|
|
309
|
+
片段和模板来自不同品牌时,会输出警告但仍继续执行,避免样式错乱。
|
|
310
|
+
|
|
311
|
+
---
|
|
312
|
+
|
|
313
|
+
## Windows 右键菜单
|
|
314
|
+
|
|
315
|
+
注册后,在 `.html` / `.htm` 文件上右键可看到级联子菜单:
|
|
316
|
+
|
|
317
|
+
```
|
|
318
|
+
📧 用 juice 生成邮件 HTML
|
|
319
|
+
├── ⚡ 生成邮件 HTML(标准 + 压缩) → juice -f
|
|
320
|
+
├── 🧩 邮件片段组装(交互选择模板) → juice -s
|
|
321
|
+
└── 📂 在此目录打开 PowerShell 7 ← 仅在已安装 pwsh 时出现
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
```bash
|
|
325
|
+
# 以管理员身份运行
|
|
326
|
+
juice --install # 注册
|
|
327
|
+
juice --uninstall # 卸载
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
> **注意**:注册/卸载需要**管理员权限**。注册成功后如菜单未立即出现,重启文件资源管理器(`explorer.exe`)即可。
|
|
248
331
|
|
|
249
332
|
---
|
|
250
333
|
|
|
@@ -256,26 +339,24 @@ juice-cli/
|
|
|
256
339
|
│ └── juice.js # CLI 入口
|
|
257
340
|
├── src/
|
|
258
341
|
│ ├── index.js # 核心逻辑(配置合并、模板处理、双输出)
|
|
259
|
-
│
|
|
342
|
+
│ ├── snippet.js # 片段组装模式 + 交互式提示
|
|
343
|
+
│ └── context-menu.js # Windows 右键菜单注册
|
|
260
344
|
├── defaults/
|
|
261
|
-
│ └── juice.yaml # CLI
|
|
262
|
-
├──
|
|
263
|
-
│ ├──
|
|
264
|
-
│ ├── template.html
|
|
265
|
-
│ └──
|
|
345
|
+
│ └── juice.yaml # CLI 内置默认配置
|
|
346
|
+
├── edm/ # EDM 模板库(npm 发布时包含)
|
|
347
|
+
│ ├── elabscience/
|
|
348
|
+
│ │ ├── elabscience-template.html
|
|
349
|
+
│ │ └── literature/
|
|
350
|
+
│ │ ├── snippet.html
|
|
351
|
+
│ │ └── juice.yaml
|
|
352
|
+
│ └── procell/
|
|
353
|
+
│ └── procell-template.html
|
|
266
354
|
├── icons/
|
|
267
|
-
│ └── juice-icon.ico #
|
|
355
|
+
│ └── juice-icon.ico # 右键菜单图标
|
|
268
356
|
├── scripts/
|
|
269
|
-
│ ├── generate-icon.js # 图标生成脚本
|
|
270
357
|
│ └── release.mjs # 发布脚本
|
|
271
|
-
├── .husky/
|
|
272
|
-
│ └── commit-msg # Git hooks - 提交信息校验
|
|
273
|
-
├── .commitlintrc.json # Commitlint 配置
|
|
274
|
-
├── .versionrc # Standard-version 配置
|
|
275
|
-
├── .npmrc # npm 发布配置
|
|
276
358
|
├── CHANGELOG.md # 变更日志(自动生成)
|
|
277
359
|
├── LICENSE # MIT
|
|
278
|
-
├── README.md
|
|
279
360
|
└── package.json
|
|
280
361
|
```
|
|
281
362
|
|
|
@@ -283,55 +364,24 @@ juice-cli/
|
|
|
283
364
|
|
|
284
365
|
## 发布说明
|
|
285
366
|
|
|
286
|
-
本项目使用自动化发布流程,包含以下功能:
|
|
287
|
-
|
|
288
367
|
### 提交信息规范
|
|
289
368
|
|
|
290
369
|
使用 [Conventional Commits](https://www.conventionalcommits.org/) 规范:
|
|
291
370
|
|
|
292
371
|
```
|
|
293
|
-
<type>(<scope>): <subject>
|
|
294
|
-
|
|
295
372
|
feat: 添加新功能
|
|
296
373
|
fix: 修复 bug
|
|
297
374
|
docs: 更新文档
|
|
298
|
-
style: 代码格式调整
|
|
299
|
-
refactor: 重构代码
|
|
300
|
-
perf: 性能优化
|
|
301
|
-
test: 添加测试
|
|
302
|
-
build: 构建系统变更
|
|
303
|
-
ci: CI/CD 配置变更
|
|
304
375
|
chore: 其他变更
|
|
305
|
-
revert: 回退提交
|
|
306
376
|
```
|
|
307
377
|
|
|
308
378
|
### 自动化发布
|
|
309
379
|
|
|
310
380
|
```bash
|
|
311
|
-
#
|
|
312
|
-
npm run release
|
|
313
|
-
|
|
314
|
-
# 预览发布(不实际执行)
|
|
315
|
-
npm run release:dry
|
|
381
|
+
npm run release # 一键发布
|
|
382
|
+
npm run release:dry # 预览
|
|
316
383
|
```
|
|
317
384
|
|
|
318
|
-
**发布流程:**
|
|
319
|
-
1. 检测未提交的文件,询问是否提交
|
|
320
|
-
2. 选择版本更新类型(Major / Minor / Patch)
|
|
321
|
-
3. 确认版本号
|
|
322
|
-
4. 自动更新版本号、生成 CHANGELOG、打 tag
|
|
323
|
-
5. 推送到 origin 和 github 远程仓库
|
|
324
|
-
6. GitHub Actions 自动发布到 npm
|
|
325
|
-
|
|
326
|
-
### 配置文件
|
|
327
|
-
|
|
328
|
-
| 文件 | 说明 |
|
|
329
|
-
|------|------|
|
|
330
|
-
| `.commitlintrc.json` | 提交信息校验规则 |
|
|
331
|
-
| `.versionrc` | 版本更新和 CHANGELOG 生成规则 |
|
|
332
|
-
| `.npmrc` | npm 发布配置 |
|
|
333
|
-
| `.husky/commit-msg` | Git hooks 配置 |
|
|
334
|
-
|
|
335
385
|
---
|
|
336
386
|
|
|
337
387
|
## License
|
package/package.json
CHANGED