UNPKG

@shopify/cli-kit

Version:

A set of utilities, interfaces, and models that are common across all the platform features

47 lines 1.56 kB
import { isUnitTest } from '../../public/node/context/local.js'; import { collectLog, stringifyMessage, outputWhereAppropriate, shouldDisplayColors, unstyled, } from '../../public/node/output.js'; /** * Returns a colored or uncolored version of a message, depending on the environment. * * @param message - The message to color or not. * @returns The message with or without colors. */ function withOrWithoutStyle(message) { if (shouldDisplayColors()) { return message; } else { return unstyled(message); } } /** * Prints a log message in the console to stdout. * * @param message - The message to print. */ export function consoleLog(message) { process.stdout.write(`${withOrWithoutStyle(message)}\n`); } /** * Prints a warning message in the console to stderr. * * @param message - The message to print. */ export function consoleWarn(message) { process.stderr.write(`${withOrWithoutStyle(message)}\n`); } /** * Logs an unformatted message at the given log level. * Note: By default, messages are sent through the standard error. * * @param content - The content to be output to the user. * @param logLevel - The log level associated with the message. * @param logger - The logging function to use to output to the user. */ export function output(content, logLevel = 'info', logger = consoleWarn) { if (isUnitTest()) collectLog(logLevel, content); const message = stringifyMessage(content); outputWhereAppropriate(logLevel, logger, message); } //# sourceMappingURL=output.js.map