juice-email-cli 2.3.6 → 2.3.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/bin/juice.js +29 -6
- package/package.json +1 -1
package/bin/juice.js
CHANGED
|
@@ -5,6 +5,29 @@ const { program } = require('commander');
|
|
|
5
5
|
const path = require('path');
|
|
6
6
|
const pkg = require('../package.json');
|
|
7
7
|
const { run } = require('../src/index');
|
|
8
|
+
let ExitPromptError;
|
|
9
|
+
try {
|
|
10
|
+
({ ExitPromptError } = require('@inquirer/core'));
|
|
11
|
+
} catch (_) {}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Wrap an async action handler to catch Ctrl+C and other errors gracefully.
|
|
15
|
+
*/
|
|
16
|
+
function safeAction(fn) {
|
|
17
|
+
return async (...args) => {
|
|
18
|
+
try {
|
|
19
|
+
await fn(...args);
|
|
20
|
+
} catch (err) {
|
|
21
|
+
if (ExitPromptError && err instanceof ExitPromptError) {
|
|
22
|
+
// Ctrl+C — exit silently
|
|
23
|
+
process.exit(0);
|
|
24
|
+
}
|
|
25
|
+
console.error('\n' + require('chalk').red(` ✘ ${err.message}`));
|
|
26
|
+
if (process.env.DEBUG) console.error(err);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
8
31
|
|
|
9
32
|
program
|
|
10
33
|
.name('juice')
|
|
@@ -87,7 +110,7 @@ program
|
|
|
87
110
|
.option('--templates', '列出所有模板')
|
|
88
111
|
.option('--series', '列出所有系列')
|
|
89
112
|
.option('--snippets', '列出所有片段')
|
|
90
|
-
.action(async (viewPath, options) => {
|
|
113
|
+
.action(safeAction(async (viewPath, options) => {
|
|
91
114
|
const { runViewMode } = require('../src/view');
|
|
92
115
|
await runViewMode({
|
|
93
116
|
viewPath: viewPath || null,
|
|
@@ -96,7 +119,7 @@ program
|
|
|
96
119
|
: (options.series ? 'series'
|
|
97
120
|
: (options.snippets ? 'snippets' : null)),
|
|
98
121
|
});
|
|
99
|
-
});
|
|
122
|
+
}));
|
|
100
123
|
|
|
101
124
|
// ─── Subcommand: juice init ─────────────────────────────────────────────
|
|
102
125
|
program
|
|
@@ -106,7 +129,7 @@ program
|
|
|
106
129
|
.option('-s, --snippet <file-path>', '仅拷贝片段 HTML 文件')
|
|
107
130
|
.option('-c, --config <file-path>', '仅拷贝配置 YAML 文件')
|
|
108
131
|
.option('--all [target]', '拷贝整个 EDM 资源目录到当前或指定目录')
|
|
109
|
-
.action(async (initPath, options) => {
|
|
132
|
+
.action(safeAction(async (initPath, options) => {
|
|
110
133
|
const { runInitMode } = require('../src/init');
|
|
111
134
|
await runInitMode({
|
|
112
135
|
initPath: initPath || null,
|
|
@@ -115,11 +138,11 @@ program
|
|
|
115
138
|
config: options.config || null,
|
|
116
139
|
all: options.all !== undefined ? (options.all || true) : null,
|
|
117
140
|
});
|
|
118
|
-
});
|
|
141
|
+
}));
|
|
119
142
|
|
|
120
143
|
// ─── Default action (backward compatible) ───────────────────────────────
|
|
121
144
|
program
|
|
122
|
-
.action(async (options) => {
|
|
145
|
+
.action(safeAction(async (options) => {
|
|
123
146
|
// 注册/卸载右键菜单
|
|
124
147
|
if (options.install) {
|
|
125
148
|
const { registerContextMenu } = require('../src/context-menu');
|
|
@@ -161,7 +184,7 @@ program
|
|
|
161
184
|
// 全交互模式:无 --snippet,无 -f
|
|
162
185
|
const { runInteractiveMode } = require('../src/snippet');
|
|
163
186
|
await runInteractiveMode({ config: options.config });
|
|
164
|
-
});
|
|
187
|
+
}));
|
|
165
188
|
|
|
166
189
|
program.allowUnknownOption(false);
|
|
167
190
|
program.parse(process.argv);
|
package/package.json
CHANGED