From 5df9d9c6bdffafb8401b134c6f3efd6b73a40ef5 Mon Sep 17 00:00:00 2001 From: Christopher Hiller Date: Sat, 5 Aug 2023 19:39:11 -0700 Subject: [PATCH] fix: --json can now fail Also `--linger` outputs the temp dir(s) in non-JSON mode. --- src/cli.ts | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/cli.ts b/src/cli.ts index 435fc7481..584bae68f 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -147,17 +147,25 @@ async function main(args: string[]): Promise { .removeAllListeners(events.RUN_SCRIPTS_FAILED); output = result; }; - const writeResult = () => { + const cleanup = () => { smoker .removeAllListeners(events.SMOKE_OK) .removeAllListeners(events.SMOKE_FAILED); + }; + const writeOk = () => { + cleanup(); + console.log(JSON.stringify(output, null, 2)); + }; + const writeFailed = () => { + cleanup(); console.log(JSON.stringify(output, null, 2)); + process.exitCode = 1; }; smoker .once(events.RUN_SCRIPTS_OK, setResult) .once(events.RUN_SCRIPTS_FAILED, setResult) - .once(events.SMOKE_FAILED, writeResult) - .once(events.SMOKE_OK, writeResult); + .once(events.SMOKE_FAILED, writeFailed) + .once(events.SMOKE_OK, writeOk); await smoker.smoke(); } else { const spinner = ora(); @@ -264,6 +272,14 @@ async function main(args: string[]): Promise { }) .on(events.SMOKE_OK, () => { spinner.succeed('Lovey-dovey! 💖'); + }) + .on(events.LINGERED, (dirs) => { + console.error( + `Lingering ${pluralize('temp directory', dirs.length)}:\n`, + ); + for (const dir of dirs) { + console.error(` ${yellow(dir)}`); + } }); await smoker.smoke(); }