diff --git a/lib/cli.ts b/lib/cli.ts index 50bb372..094b643 100644 --- a/lib/cli.ts +++ b/lib/cli.ts @@ -1,6 +1,7 @@ #!/usr/bin/env node import yargs from "yargs"; +import { alerts } from "./core"; import { IMPLEMENTATIONS } from "./implementations"; import { main } from "./main"; import { Aliases, NAME_FORMATS } from "./sass"; @@ -145,4 +146,8 @@ const { _: patterns, ...rest } = yargs .parseSync(); // eslint-disable-next-line @typescript-eslint/no-floating-promises -main(patterns[0] as string, { ...rest }); +main(patterns[0] as string, { ...rest }).catch((error) => { + alerts.error("Encountered an error while generating type definitions."); + alerts.error(error); + process.exitCode = 1; +}); diff --git a/lib/core/alerts.ts b/lib/core/alerts.ts index 1d80e48..9a9922e 100644 --- a/lib/core/alerts.ts +++ b/lib/core/alerts.ts @@ -34,10 +34,10 @@ const withLogLevelsRestriction = const error = withLogLevelsRestriction( ["verbose", "error", "info"], - (message: string) => console.log(chalk.red(message)) + (message: string) => console.warn(chalk.red(message)) ); const warn = withLogLevelsRestriction(["verbose"], (message: string) => - console.log(chalk.yellowBright(message)) + console.warn(chalk.yellowBright(message)) ); const notice = withLogLevelsRestriction( ["verbose", "info"], diff --git a/lib/load.ts b/lib/load.ts index 7c590b6..569895a 100644 --- a/lib/load.ts +++ b/lib/load.ts @@ -1,7 +1,7 @@ import { bundleRequire } from "bundle-require"; import JoyCon from "joycon"; import path from "path"; -import { alerts, CLIOptions, ConfigOptions } from "./core"; +import { CLIOptions, ConfigOptions } from "./core"; import { getDefaultImplementation } from "./implementations"; import { nameFormatDefault } from "./sass"; import { @@ -39,25 +39,16 @@ export const loadConfig = async (): Promise< ); if (configPath) { - try { - const configModule = await bundleRequire({ - filepath: configPath, - }); + const configModule = await bundleRequire({ + filepath: configPath, + }); - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - const config: ConfigOptions = - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - configModule.mod.config || configModule.mod.default || configModule.mod; + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + const config: ConfigOptions = + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + configModule.mod.config || configModule.mod.default || configModule.mod; - return config; - } catch (error) { - alerts.error( - // eslint-disable-next-line @typescript-eslint/restrict-template-expressions - `An error occurred loading the config file "${configPath}":\n${error}` - ); - - return {}; - } + return config; } return {};