From 2c6440509143184976cbbe98e597fbe8b979e35b Mon Sep 17 00:00:00 2001 From: Chapman Pendery Date: Wed, 28 Aug 2024 12:22:33 -0700 Subject: [PATCH 1/4] fix: generators that console log should be captured and redirected to logfile Signed-off-by: Chapman Pendery --- src/commands/root.ts | 2 ++ src/utils/log.ts | 14 +++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/commands/root.ts b/src/commands/root.ts index 91899538..8788aa67 100644 --- a/src/commands/root.ts +++ b/src/commands/root.ts @@ -33,6 +33,8 @@ export const action = (program: Command) => async (options: RootCommandOptions) await loadLocalSpecsSet(); + log.overrideConsole(); + const shell = options.shell ?? ((await inferShell()) as unknown as Shell | undefined); if (shell == null) { program.error(`Unable to identify shell, use the -s/--shell option to provide your shell`, { exitCode: 1 }); diff --git a/src/utils/log.ts b/src/utils/log.ts index ec32b4f0..76288685 100644 --- a/src/utils/log.ts +++ b/src/utils/log.ts @@ -28,9 +28,21 @@ const debug = (content: object) => { }); }; +// eslint-disable-next-line @typescript-eslint/no-explicit-any +const getLogFunction = (level: "error" | "log") => (...data: any[]) => debug({msg: `console.${level}`, data: data.toString()}); + +const logConsole = { + ...console, + log: getLogFunction("log"), + error: getLogFunction("error"), +} + +// eslint-disable-next-line no-global-assign +const overrideConsole = () => console = logConsole + export const enable = async () => { await reset(); logEnabled = true; }; -export default { reset, debug, enable }; +export default { reset, debug, enable, overrideConsole }; From 6dd779ed0dd3cb227a0bd3f26dca356817ad1f90 Mon Sep 17 00:00:00 2001 From: Chapman Pendery Date: Wed, 28 Aug 2024 12:33:53 -0700 Subject: [PATCH 2/4] style: formatting Signed-off-by: Chapman Pendery --- src/utils/log.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/utils/log.ts b/src/utils/log.ts index 76288685..20d39a40 100644 --- a/src/utils/log.ts +++ b/src/utils/log.ts @@ -29,16 +29,19 @@ const debug = (content: object) => { }; // eslint-disable-next-line @typescript-eslint/no-explicit-any -const getLogFunction = (level: "error" | "log") => (...data: any[]) => debug({msg: `console.${level}`, data: data.toString()}); +const getLogFunction = + (level: "error" | "log") => + (...data: any[]) => + debug({ msg: `console.${level}`, data: data.toString() }); const logConsole = { ...console, log: getLogFunction("log"), error: getLogFunction("error"), -} +}; // eslint-disable-next-line no-global-assign -const overrideConsole = () => console = logConsole +const overrideConsole = () => (console = logConsole); export const enable = async () => { await reset(); From b3d4ac4038731160f5d79c521d3440538ca98bd6 Mon Sep 17 00:00:00 2001 From: Chapman Pendery Date: Wed, 28 Aug 2024 12:39:46 -0700 Subject: [PATCH 3/4] fix: any warning Signed-off-by: Chapman Pendery --- src/utils/log.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/utils/log.ts b/src/utils/log.ts index 20d39a40..b8fcd8d5 100644 --- a/src/utils/log.ts +++ b/src/utils/log.ts @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +/* eslint-disable @typescript-eslint/no-explicit-any */ + import os from "node:os"; import path from "node:path"; import fs from "node:fs"; @@ -28,7 +30,7 @@ const debug = (content: object) => { }); }; -// eslint-disable-next-line @typescript-eslint/no-explicit-any + const getLogFunction = (level: "error" | "log") => (...data: any[]) => From 01a3b44c148ea9440a65d1503b7f72629f513eb0 Mon Sep 17 00:00:00 2001 From: Chapman Pendery Date: Wed, 28 Aug 2024 12:41:01 -0700 Subject: [PATCH 4/4] style: format Signed-off-by: Chapman Pendery --- src/utils/log.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/utils/log.ts b/src/utils/log.ts index b8fcd8d5..19c1bd25 100644 --- a/src/utils/log.ts +++ b/src/utils/log.ts @@ -30,7 +30,6 @@ const debug = (content: object) => { }); }; - const getLogFunction = (level: "error" | "log") => (...data: any[]) =>