From 12fbb4ce0f08c000400768a00ce0d64cfaf2d361 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Tue, 27 Aug 2024 12:52:13 +0530 Subject: [PATCH] refactor: cleanup error output and do not add red color to help output --- packages/cli/medusa-cli/src/create-cli.ts | 32 +++++++++++++---------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/packages/cli/medusa-cli/src/create-cli.ts b/packages/cli/medusa-cli/src/create-cli.ts index c1c7ea334e4e0..02575e26adbfb 100644 --- a/packages/cli/medusa-cli/src/create-cli.ts +++ b/packages/cli/medusa-cli/src/create-cli.ts @@ -35,7 +35,7 @@ function buildLocalCommands(cli, isLocalProject) { function resolveLocalCommand(command) { if (!isLocalProject) { - cli.showHelp() + cli.showHelp((s: string) => console.log(s)) } try { @@ -44,12 +44,8 @@ function buildLocalCommands(cli, isLocalProject) { )! return require(cmdPath).default } catch (err) { - if (!process.env.NODE_ENV?.startsWith("prod")) { - console.log("--------------- ERROR ---------------------") - console.log(err) - console.log("-------------------------------------------") - } - cli.showHelp() + console.error(err) + cli.showHelp((s: string) => console.error(s)) } } @@ -484,15 +480,23 @@ export default (argv) => { const arg = argv.slice(2)[0] const suggestion = arg ? didYouMean(arg, availableCommands) : `` - if (!process.env.NODE_ENV?.startsWith("prod")) { - console.log("--------------- ERROR ---------------------") - console.log(err) - console.log("-------------------------------------------") + if (msg) { + reporter.error(msg) + console.log() + } + if (suggestion) { + reporter.info(suggestion) + console.log() + } + + if (err) { + console.error("--------------- ERROR ---------------------") + console.error(err) + console.error("-------------------------------------------") } - cli.showHelp() - reporter.info(suggestion) - reporter.info(msg) + cli.showHelp((s: string) => console.error(s)) + process.exit(1) }) .parse(argv.slice(2)) }