alinea
Version:
Headless git-based CMS
52 lines (50 loc) • 1.56 kB
JavaScript
import "../../chunks/chunk-NZLE2WMY.js";
// src/cli/util/Report.ts
var isBrowser = typeof window !== "undefined";
function reportWarning(...messages) {
const message = formatMessages(messages, "warning");
console[isBrowser ? "warn" : "log"](message);
}
function reportFatal(...messages) {
const message = formatMessages(messages, "error", red);
console[isBrowser ? "error" : "log"](message);
}
function reportError(error) {
const messages = Array(error.message);
const stack = error.stack?.split("\n").slice(1);
if (stack) messages.push(...stack.map((line) => line.trim()));
return reportFatal(...messages);
}
function formatMessages(messages, type, color = yellow) {
return messages.reduce(
(res, line, index) => {
const isLast = index === messages.length - 1;
const isMain = index === 0;
const connector = gray(isLast ? "\u2570" : isMain ? "\u2502" : "\u251C");
res += "\n";
res += ` ${connector} ${isMain ? bold(line) : gray(line)}`;
if (isLast) res += "\n";
return res;
},
` ${bold(color("\u0251"))} ${color(type)}`
);
}
var ansiSupported = typeof process !== "undefined" && (process.stdout?.isTTY || process.env?.FORCE_COLOR);
var ansi = (start, end = 39) => (input) => ansiSupported ? `\x1B[${start}m${input}\x1B[${end}m` : input;
var red = ansi(31);
var gray = ansi(90);
var cyan = ansi(36);
var yellow = ansi(33);
var bold = ansi(1, 0);
var redBg = ansi(41, 49);
export {
bold,
cyan,
gray,
red,
redBg,
reportError,
reportFatal,
reportWarning,
yellow
};