@synaptic-simulations/mach
Version:
The last MSFS instrument bundler you'll ever need.
80 lines • 4.02 kB
JavaScript
;
/*
* SPDX-FileCopyrightText: 2022 Synaptic Simulations and its contributors
* SPDX-License-Identifier: MIT
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BuildLogger = void 0;
const node_path_1 = __importDefault(require("node:path"));
const chalk_1 = __importDefault(require("chalk"));
const filesize_1 = require("filesize");
const signale_1 = __importDefault(require("signale"));
class BuildLogger {
constructor(scope, verbose = false) {
this.logger = new signale_1.default.Signale({
scope,
types: {
file: { badge: " ", label: "file", color: "blue", logLevel: "info" },
errorMessage: { badge: "", label: "", color: "white", logLevel: "error", stream: process.stderr },
errorLocation: { badge: "→", label: "", color: "white", logLevel: "error", stream: process.stderr },
warningMessage: { badge: "", label: "", color: "white", logLevel: "warning", stream: process.stderr },
warningLocation: { badge: "→", label: "", color: "white", logLevel: "warning", stream: process.stderr },
},
});
this.verbose = verbose;
}
buildComplete(name, time, result) {
if (result.warnings.length > 0) {
this.logger.warn(`Built ${name} in ${chalk_1.default.yellowBright(time.toFixed(), "ms")} —`, chalk_1.default.yellowBright(`${result.warnings.length} ${result.warnings.length === 1 ? "warning" : "warnings"}`));
}
else {
this.logger.success(`Built ${name} in ${chalk_1.default.greenBright(time.toFixed(), "ms")}`);
}
if (this.verbose) {
for (const [file, meta] of Object.entries(result.metafile.outputs)) {
this.logger.file(chalk_1.default.gray(`${file} — ${chalk_1.default.cyan((0, filesize_1.filesize)(meta.bytes))}`));
}
}
console.log();
if (result.warnings.length > 0) {
for (const warning of result.warnings) {
this.logger.errorMessage(chalk_1.default.yellowBright(warning.id ? `${warning.text} (${warning.id})` : warning.text));
if (warning.notes.length > 0) {
// esbuild automatically attaches the message "The plugin x was triggered by this import",
// which is not very useful in our case
for (const note of warning.notes.filter(({ text }) => !text.startsWith("The plugin"))) {
this.logger.errorMessage(chalk_1.default.whiteBright(note.text));
}
}
if (warning.location) {
this.logger.errorLocation(`at ${warning.location.file}:${warning.location.line}:${warning.location.column + 1}`);
}
console.log();
}
}
}
buildFailed(errors) {
this.logger.error(`Build failed — ${chalk_1.default.redBright(errors.length, errors.length === 1 ? "error" : "errors")}\n`);
for (const error of errors) {
this.logger.errorMessage(chalk_1.default.redBright(error.id ? `${error.text} (${error.id})` : error.text));
if (error.notes.length > 0) {
for (const note of error.notes) {
this.logger.errorMessage(chalk_1.default.whiteBright(note.text));
}
}
if (error.location) {
this.logger.errorLocation(`at ${error.location.file}:${error.location.line}:${error.location.column + 1}`);
}
console.log();
}
}
changeDetected(file) {
console.clear();
signale_1.default.watch(`Change detected in ${node_path_1.default.relative(process.cwd(), file)}, rebuilding\n`);
}
}
exports.BuildLogger = BuildLogger;
//# sourceMappingURL=logger.js.map