@stagepass/cli 2.3.0-beta.1 → 2.3.0
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/package.json +1 -1
- package/src/commands/start.js +25 -1
- package/src/lib/prompts.js +33 -5
package/package.json
CHANGED
package/src/commands/start.js
CHANGED
|
@@ -215,6 +215,30 @@ export function summarizeCertFindings(report) {
|
|
|
215
215
|
return issues;
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
+
/**
|
|
219
|
+
* Honest one-line cert summary when nothing failed hard enough to offer repair.
|
|
220
|
+
* Never says "ok" for a root or a site check that did not run or was not ok.
|
|
221
|
+
* The Caddy :443 reason is included only when every skip came from that check.
|
|
222
|
+
* @param {{ root?: { status?: string }, handshakes?: { status?: string, reason?: string }[] }} report
|
|
223
|
+
*/
|
|
224
|
+
function certStatusLine(report) {
|
|
225
|
+
const root = report?.root?.status;
|
|
226
|
+
const rootLabel =
|
|
227
|
+
root === 'ok' ? 'root ok' : root === 'warn' ? 'root warning' : 'root not checked';
|
|
228
|
+
const hs = report?.handshakes || [];
|
|
229
|
+
if (!hs.length) return `Certificates: ${rootLabel}, site TLS not checked.`;
|
|
230
|
+
const skips = hs.filter((h) => h.status === 'skip');
|
|
231
|
+
if (skips.length) {
|
|
232
|
+
const why = skips.every((h) => /not serving :443/.test(String(h.reason || '')))
|
|
233
|
+
? ' (Caddy not serving :443)'
|
|
234
|
+
: '';
|
|
235
|
+
return `Certificates: ${rootLabel}, site TLS not checkable${why}.`;
|
|
236
|
+
}
|
|
237
|
+
const sitesOk = hs.every((h) => h.status === 'ok');
|
|
238
|
+
if (root === 'ok' && sitesOk) return 'Certificates: ok';
|
|
239
|
+
return `Certificates: ${rootLabel}, site TLS ${sitesOk ? 'ok' : 'not ok'}.`;
|
|
240
|
+
}
|
|
241
|
+
|
|
218
242
|
/**
|
|
219
243
|
* @param {object} [options]
|
|
220
244
|
*/
|
|
@@ -283,7 +307,7 @@ export async function start(options = {}) {
|
|
|
283
307
|
);
|
|
284
308
|
}
|
|
285
309
|
} else {
|
|
286
|
-
console.log(chalk.dim(
|
|
310
|
+
console.log(chalk.dim(certStatusLine(certReport)));
|
|
287
311
|
}
|
|
288
312
|
} catch (error) {
|
|
289
313
|
console.log(
|
package/src/lib/prompts.js
CHANGED
|
@@ -2,18 +2,46 @@ import { confirm as defaultConfirm } from '@inquirer/prompts';
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Confirm prompt (defaults to `@inquirer/prompts` confirm).
|
|
5
|
-
* Injectable for unit tests.
|
|
5
|
+
* Injectable for unit tests. Single choke point for every confirmation in
|
|
6
|
+
* the CLI, so an abort here ends the process before any caller's own
|
|
7
|
+
* try/catch can run: no stack trace, 130 for SIGINT, 1 for EOF/closed stdin.
|
|
6
8
|
*
|
|
7
9
|
* @param {string} message
|
|
8
10
|
* @param {object} [options]
|
|
9
11
|
* @param {boolean} [options.default]
|
|
10
12
|
* @param {(opts: { message: string, default?: boolean }) => Promise<boolean>} [options.confirm]
|
|
13
|
+
* @param {(code: number) => void} [options.exit]
|
|
14
|
+
* @param {(msg: string) => void} [options.write]
|
|
11
15
|
* @returns {Promise<boolean>}
|
|
12
16
|
*/
|
|
13
17
|
export async function confirm(message, options = {}) {
|
|
14
18
|
const confirmFn = options.confirm || defaultConfirm;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
const exit = options.exit ?? ((code) => process.exit(code));
|
|
20
|
+
const write = options.write ?? ((msg) => process.stderr.write(msg));
|
|
21
|
+
// Byte 0x03 is a readline event, not a process signal (raw mode has ISIG
|
|
22
|
+
// off). A real SIGINT is caught by signal-exit, which re-raises it and the
|
|
23
|
+
// process dies before this await's catch runs. Handle that signal here,
|
|
24
|
+
// synchronously, and only while a real prompt is on screen.
|
|
25
|
+
const onSigInt = options.confirm
|
|
26
|
+
? null
|
|
27
|
+
: () => {
|
|
28
|
+
write('Aborted.\n');
|
|
29
|
+
exit(130);
|
|
30
|
+
};
|
|
31
|
+
if (onSigInt) process.on('SIGINT', onSigInt);
|
|
32
|
+
try {
|
|
33
|
+
return await confirmFn({
|
|
34
|
+
message: String(message || ''),
|
|
35
|
+
default: options.default === true,
|
|
36
|
+
});
|
|
37
|
+
} catch (error) {
|
|
38
|
+
if (error && error.name === 'ExitPromptError') {
|
|
39
|
+
write('Aborted.\n');
|
|
40
|
+
exit(/SIGINT/.test(String(error.message)) ? 130 : 1);
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
throw error;
|
|
44
|
+
} finally {
|
|
45
|
+
if (onSigInt) process.off('SIGINT', onSigInt);
|
|
46
|
+
}
|
|
19
47
|
}
|