myst-cli
Version:
Command line tools for MyST
49 lines (48 loc) ⢠1.98 kB
JavaScript
import chalk from 'chalk';
export function createServerLogger(session, opts) {
const logger = {
debug(data) {
const line = data.trim();
if (!line || line.startsWith('>') || line.startsWith('Watching'))
return;
if (line.includes('File changed: app/content'))
return; // This is shown elsewhere
if (line.includes('http://')) {
const [, ipAndPort] = line.split('http://');
const port = ipAndPort.split(':')[1].replace(/[^0-9]/g, '');
const local = `http://${opts.host}:${port}`;
opts.ready();
session.log.info(`\nš Server started on port ${port}! š„³ š\n\n\n\tš ${chalk.green(local)} š\n\n`);
session.showUpgradeNotice?.();
return;
}
session.log.info(line
.replace(/šæ/g, 'š')
.replace(/(GET) /, 'š $1 ')
.replace(/(POST) /, 'š¦ $1 '));
},
error(data) {
const line = data.trim();
if (!line)
return;
// This is a spurious Remix warning https://github.com/remix-run/remix/issues/2677
if (line.includes('is not listed in your package.json dependencies'))
return;
if (line.includes('was not found in your node_modules'))
return;
// This is the punycode deprecation warning
if (line.includes('--trace-deprecation') || line.includes('DEP0040'))
return;
if (line.startsWith('Rebuilding')) {
session.log.debug(line);
return;
}
if (line.startsWith('Done in')) {
session.log.info(`ā”ļø ${line.replace('Done', 'Compiled')}`);
return;
}
session.log.error(data);
},
};
return logger;
}