firebase-tools-extra
Version:
Extra functionality for firebase-tools with support for emulators and auth through service account.
94 lines (93 loc) • 2.59 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var chalk_1 = tslib_1.__importDefault(require("chalk"));
var figures_1 = tslib_1.__importDefault(require("figures"));
var colorMapping = {
warn: 'yellow',
success: 'green',
error: 'red',
};
var iconMapping = {
info: 'ℹ',
warn: '⚠',
success: '✔',
error: '✖',
};
var prefixMapping = {
warn: 'Warning: ',
error: 'Error: ',
};
/**
* Create a function for coloring the log based on type
* @param type - Log type
* @returns A color logger function
*/
function colorLogger(type) {
var color = colorMapping[type];
return function (text) {
var chalkColor = chalk_1.default[color];
return chalkColor ? chalkColor(text) : text;
};
}
/**
* Log using a specific type (colorizes for CLI)
* @param type - Log type
* @param message - Message containing info to log
* @param other - Other values to pass to info
*/
function logType(type, message, other) {
var icon = iconMapping[type];
var prefix = prefixMapping[type];
var colorLog = colorLogger(type);
var args = [
(icon ? colorLog(figures_1.default(icon)) : '') + " " + (prefix ? colorLog(prefix) : '') + message,
];
if (other) {
args.push(other);
}
/* eslint-disable no-console */
console.log.apply(console, tslib_1.__spread(args));
/* eslint-enable no-console */
}
exports.log = console.log; // eslint-disable-line
/**
* Log info within console
* @param message - Message containing info to log
* @param other - Other values to pass to info
* @returns undefined
*/
function info(message, other) {
return logType('info', message, other);
}
exports.info = info;
/**
* Log a success within console (colorized with green)
* @param message - Success message to log
* @param other - Other values to pass to info
* @returns undefined
*/
function success(message, other) {
return logType('success', message, other);
}
exports.success = success;
/**
* Log a warning within the console (colorized with yellow)
* @param message - Warning message to log
* @param other - Other values to pass to info
* @returns undefined
*/
function warn(message, other) {
return logType('warn', message, other);
}
exports.warn = warn;
/**
* Log an error within console (colorized with red)
* @param message - Error message to log
* @param other - Other values to pass to info
* @returns undefined
*/
function error(message, other) {
return logType('error', message, other);
}
exports.error = error;