@bscotch/stitch
Version:
Stitch: The GameMaker Studio 2 Asset Pipeline Development Kit.
98 lines • 3.44 kB
JavaScript
import { Pathy, pathy } from '@bscotch/pathy';
import { createStringifier, isArray, isPlainObject, } from '@bscotch/stringify';
import { Logger } from '@bscotch/logger';
import { dateDifferenceHours } from '@bscotch/utility';
import color from 'picocolors';
import { pathToFileURL } from 'url';
const prettyStringify = createStringifier({
skipUndefinedObjectValues: true,
stringifiers: [
{
ifInstanceof: Pathy,
stringify(node) {
const displayCwd = pathy(process.env.DISPLAY_CWD || process.cwd());
let normalized = node.value.relativeFrom(displayCwd);
if (normalized.includes(' ')) {
normalized = pathToFileURL(node.value.absolute).toString();
}
return color.magenta(normalized);
},
},
{
ifInstanceof: Date,
stringify(node) {
let string = node.value.toISOString();
if (dateDifferenceHours(new Date(), node.value) < 1) {
string = `${node.value.getHours()}:${`${node.value.getMinutes()}`.padStart(2, '0')}.${node.value.getSeconds()}`;
}
return color.cyan(string);
},
},
{
test(node) {
return ((node.parentIsArray || node.parentIsPlainObject) && node.maxIndex);
},
prefix(node) {
let prefix = ' '.repeat(node.depth);
if (node.parentIsPlainObject) {
prefix += `${node.key}: `;
}
if (isArray(node.value) || isPlainObject(node.value)) {
prefix += '\n';
}
return color.gray(prefix);
},
suffix(node) {
if (isArray(node.value) || isPlainObject(node.value)) {
return '';
}
return '\n';
},
},
{
test(node) {
return (!isPlainObject(node.value) &&
!isArray(node.value) &&
node.maxIndex !== 0);
},
stringify(node) {
if (node.value instanceof Error) {
return `${color.red(node.value.name + ': ')} ${node.value.message}`;
}
else if (typeof node.value === 'string') {
return node.value;
}
else {
return color.cyan(`${node.value}`);
}
},
},
],
});
export const logger = new Logger({
formatter(level, message, ...content) {
message =
level === 'error'
? color.red(message)
: level === 'warn'
? color.yellow(message)
: message;
if (typeof content != 'undefined') {
message += '\n' + prettyStringify(content);
}
return message;
},
});
export function debug(message, content) {
return logger.log('debug', message, content);
}
export function info(message, content) {
return logger.log('info', message, content);
}
export function error(message, content) {
return logger.log('error', message, content);
}
export function warn(message, content) {
return logger.log('warn', message, content);
}
//# sourceMappingURL=log.js.map