From 83d8c88c1acb6dcc2118f2813665e6452a51039c Mon Sep 17 00:00:00 2001 From: naman-contentstack Date: Fri, 10 Oct 2025 16:34:15 +0530 Subject: [PATCH] fix:updated logger implementation --- src/commands/tsgen.ts | 26 ++++++++++---------------- src/lib/helper.ts | 23 ++++++----------------- 2 files changed, 16 insertions(+), 33 deletions(-) diff --git a/src/commands/tsgen.ts b/src/commands/tsgen.ts index 4d7b78c..71c4073 100644 --- a/src/commands/tsgen.ts +++ b/src/commands/tsgen.ts @@ -1,5 +1,5 @@ import { Command } from "@contentstack/cli-command"; -import { flags, FlagInput } from "@contentstack/cli-utilities"; +import { flags, FlagInput, log } from "@contentstack/cli-utilities"; import * as path from "path"; import * as fs from "fs"; import { cliux } from "@contentstack/cli-utilities"; @@ -170,6 +170,7 @@ export default class TypeScriptCodeGeneratorCommand extends Command { token: config.token, environment: config.environment, namespace: namespace, + logger: log, }; // Add region or host based on whether it's a custom region @@ -207,6 +208,7 @@ export default class TypeScriptCodeGeneratorCommand extends Command { systemFields: includeSystemFields, isEditableTags: includeEditableTags, includeReferencedEntry, + logger: log, }); fs.writeFileSync(outputPath, result || ""); @@ -219,24 +221,16 @@ export default class TypeScriptCodeGeneratorCommand extends Command { "Generation completed successfully with partial schema", ) ) { - cliux.print("", {}); - cliux.print( - "Type generation completed successfully with partial schema!", - { color: "green", bold: true }, + cliux.print(""); + log.success("Type generation completed successfully with partial schema!"); + log.warn( + "Some content types were skipped due to validation issues, but types were generated for valid content types." ); - cliux.print( - "Some content types were skipped due to validation issues, but types were generated for valid content types.", - { color: "yellow" }, - ); - cliux.print( - "Check the output above for details on what was skipped and suggestions for fixing issues.", - { color: "cyan" }, + log.info( + "Check the output above for details on what was skipped and suggestions for fixing issues." ); } else { - cliux.print( - `Successfully added the Content Types to '${outputPath}'.`, - { color: "green" }, - ); + log.success(`Successfully added the Content Types to '${outputPath}'.`); } // this.log(`Wrote ${outputPath} Content Types to '${result.outputPath}'.`) diff --git a/src/lib/helper.ts b/src/lib/helper.ts index 566afae..a4af862 100644 --- a/src/lib/helper.ts +++ b/src/lib/helper.ts @@ -1,4 +1,4 @@ -import { cliux } from "@contentstack/cli-utilities"; +import { log } from "@contentstack/cli-utilities"; export const sanitizePath = (str: string) => { return str @@ -32,10 +32,7 @@ export const printFormattedError = (error: FormattedError, context: string) => { error.error_message.includes("numeric identifiers") ) { // Just print our detailed message as-is, no extra formatting - cliux.print(error.error_message, { - color: "red", - bold: true, - }); + log.error(error.error_message); return; } @@ -83,20 +80,12 @@ export const printFormattedError = (error: FormattedError, context: string) => { } // Print formatted error output - cliux.print(`Type generation failed: ${errorMessage}`, { - color: "red", - bold: true, - }); + log.error(`Type generation failed: ${errorMessage}`); if (hint) { - cliux.print(`Tip: ${hint}`, { color: "yellow" }); + log.warn(`Tip: ${hint}`); } - cliux.print(`Error context: ${context}`, { - color: "cyan", - }); - - cliux.print(`Timestamp: ${error?.timestamp || new Date().toISOString()}`, { - color: "gray", - }); + log.info(`Error context: ${context}`); + log.info(`Timestamp: ${error?.timestamp || new Date().toISOString()}`); };