diff --git a/index.ts b/index.ts index 63a8b2c..abd9bd7 100644 --- a/index.ts +++ b/index.ts @@ -13,7 +13,7 @@ import signale from "signale"; import { description, version } from "./package.json"; import { machBuild, machWatch } from "./src/mach"; -import { type MachArgs, MachArgsSchema, MachConfigSchema } from "./src/types"; +import { type MachArgs, MachArgsSchema, type MachConfig, MachConfigSchema } from "./src/types"; try { dotenv.config(); @@ -23,6 +23,12 @@ try { const cli = new Command(); +const logger = new signale.Signale({ + types: { + error: { badge: "×", label: "error", color: "red", stream: process.stderr }, + }, +}); + const commandWithOptions = (name: string) => cli .command(name) @@ -50,21 +56,24 @@ const commandWithOptions = (name: string) => await import(config.replace(/\\/g, "/")) .then((module) => { // Check config integrity - const result = MachConfigSchema.safeParse(module.default); - if (result.success) { - actionCommand.setOptionValue("config", result.data); - signale.info("Loaded config file", chalk.cyanBright(config), "\n"); - } else { - signale.error("Invalid config file", chalk.redBright(config)); + let result: MachConfig; + try { + result = MachConfigSchema.parse(module.default); + } catch (error) { + logger.error("Invalid config file", chalk.redBright(config)); + logger.error(error); process.exit(1); } + logger.info("Loaded config file", chalk.cyanBright(config), "\n"); + if (actionCommand.getOptionValue("workInConfigDir")) { process.chdir(path.dirname(config)); } }) - .catch(() => { - signale.error("Unable to load config file", chalk.redBright(config)); + .catch((error) => { + logger.error("Unable to load config file", chalk.redBright(config)); + logger.error(error); process.exit(1); }); }); diff --git a/src/logger.ts b/src/logger.ts index 2ffe175..1ad5aac 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -7,12 +7,14 @@ import path from "node:path"; import chalk from "chalk"; import type { Message } from "esbuild"; import { filesize } from "filesize"; -import signale, { type DefaultMethods, type Signale } from "signale"; +import signale, { type SignaleOptions, type DefaultMethods, type Signale } from "signale"; import type { BuildResultWithMeta } from "./types"; export class BuildLogger { - private readonly logger: Signale; + private readonly logger: Signale< + DefaultMethods | "file" | "errorMessage" | "errorLocation" | "warningMessage" | "warningLocation" + >; private readonly verbose: boolean;