From 23ef6cffbd366cdbc78d40f4b5f1a79309fb854a Mon Sep 17 00:00:00 2001 From: Niloy Sikdar Date: Wed, 19 Oct 2022 22:18:01 +0530 Subject: [PATCH] feat(generate): add colors with the console.log Add colors with the console.log for the debug messages Fixes #3 Signed-off-by: Niloy Sikdar --- src/generate.ts | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/generate.ts b/src/generate.ts index c149cc9..6ed182b 100644 --- a/src/generate.ts +++ b/src/generate.ts @@ -35,6 +35,12 @@ type ArgsSchema = { debug?: boolean; }; +const Colors = { + Reset: '\x1b[0m', + FgYellow: '\x1b[33m', + FgGreen: '\x1b[32m', +}; + function _getArgs(): ArgsSchema { const args: string[] = process.argv.slice(2); @@ -84,7 +90,12 @@ function _generate({ if (js) { for (const finalKey in parsedData) { - debug && console.log(`[JS] Generating for key: ${finalKey}`); + debug && + console.log( + Colors.FgYellow, + `[JS] Generating for key: ${finalKey}`, + Colors.Reset, + ); envConfig = envConfig + ` ${finalKey}: process.env.${finalKey},\n`; } @@ -101,7 +112,12 @@ function _generate({ } } else { for (const finalKey in parsedData) { - debug && console.log(`[TS] Generating for key: ${finalKey}`); + debug && + console.log( + Colors.FgYellow, + `[TS] Generating for key: ${finalKey}`, + Colors.Reset, + ); envConfig = envConfig + ` ${finalKey}: String(process.env.${finalKey}),\n`; } @@ -116,7 +132,9 @@ function _generate({ writeFileSync(outPath, finalConfig); debug && console.log( + Colors.FgGreen, `${out ? out : defaultOutFile} has been generated successfully`, + Colors.Reset, ); }