myst-cli
Version:
Command line tools for MyST
50 lines (49 loc) ⢠2.06 kB
JavaScript
import chalk from 'chalk';
export function createServerLogger(session, ready) {
const logger = {
debug(data) {
var _a;
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('started at http://')) {
const [, ipAndPort] = line.split('http://');
const port = ipAndPort.split(':')[1].replace(/[^0-9]/g, '');
const local = `http://localhost:${port}`;
ready();
session.log.info(`\nš Server started on port ${port}! š„³ š\n\n\n\tš ${chalk.green(local)} š\n\n`);
(_a = session.showUpgradeNotice) === null || _a === void 0 ? void 0 : _a.call(session);
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;
}