mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-11 23:04:52 +09:00
Migrate the usage of CommonJS specific code and imports to ESM. Roughly summarised this: - Changes all require() calls to import statement or expressions. - Changes usage of module.exports to export statements. - Replaces require.resolve with import.meta.resolve. - Replaces conditional imports with conditional subpath imports. - Replaces module === require.main with import.meta.main. - Adds the full filename with extention to all relative imports. - Changes all usage of __dirname and __filename to their import.meta equivalents. - Sets "type": "module" in package.json files. - Removes usage of "use strict". - Adds .ts an an alias of .js for the webpack build. Due to differences in how require and import resolves files the plugin entrypoints will have to include the filename and extension after this migration in order to work.
47 lines
974 B
JavaScript
47 lines
974 B
JavaScript
/* eslint-disable no-console */
|
|
import chalk from "chalk";
|
|
|
|
export const levels = Object.freeze({
|
|
fatal: 0,
|
|
error: 1,
|
|
warn: 2,
|
|
audit: 3,
|
|
info: 4,
|
|
verbose: 6,
|
|
});
|
|
|
|
export const colors = {
|
|
fatal: "inverse red",
|
|
error: "bold redBright",
|
|
warn: "bold yellowBright",
|
|
audit: "bold greenBright",
|
|
info: "bold blueBright",
|
|
verbose: "bold grey",
|
|
};
|
|
|
|
let maxLogLevel = levels.info;
|
|
export const logger = {};
|
|
for (let [name, level] of Object.entries(levels)) {
|
|
// eslint-disable-next-line no-loop-func
|
|
logger[name] = message => {
|
|
if (level > maxLogLevel) {
|
|
return;
|
|
}
|
|
let style = chalk;
|
|
for (let part of colors[name].split(" ")) {
|
|
style = style[part];
|
|
}
|
|
if (["fatal", "error"].includes(name)) {
|
|
console.error(`${style(name)} ${message}`);
|
|
} else if (["warn"].includes(name)) {
|
|
console.warn(`${style(name)} ${message}`);
|
|
} else {
|
|
console.log(`${style(name)} ${message}`);
|
|
}
|
|
};
|
|
}
|
|
|
|
export function setLogLevel(level) {
|
|
maxLogLevel = level;
|
|
}
|