diff --git a/src/commands/cms/stackbit.ts b/src/commands/cms/stackbit.ts index 0c623dc..1977a7b 100644 --- a/src/commands/cms/stackbit.ts +++ b/src/commands/cms/stackbit.ts @@ -1,6 +1,6 @@ import { Command } from 'commander'; import chalkTemplate from 'chalk-template'; -import runTask from '../../tasks/cms/stackbit-task.js'; +import { logErrorAndExit } from '../../logging.js'; const stackbit = new Command('stackbit') .description( @@ -62,18 +62,20 @@ const stackbit = new Command('stackbit') .option('--debug', 'show debugging output', false) .action((options) => import('./../../tasks/cms/stackbit-task.js').then((runTask) => { - runTask.default( - options.componentsPath, - options.configurationPath, - options.updateConfig, - options.templates, - options.globals, - options.components, - options.rcOnly, - options.revert, - options.cleanup, - options.debug - ); + runTask + .default( + options.componentsPath, + options.configurationPath, + options.updateConfig, + options.templates, + options.globals, + options.components, + options.rcOnly, + options.revert, + options.cleanup, + options.debug + ) + .catch(logErrorAndExit); }) ); diff --git a/src/commands/cms/staticcms.ts b/src/commands/cms/staticcms.ts index 59291be..d0d7e0d 100644 --- a/src/commands/cms/staticcms.ts +++ b/src/commands/cms/staticcms.ts @@ -1,6 +1,7 @@ import { Command } from 'commander'; import chalkTemplate from 'chalk-template'; import runTask from '../../tasks/cms/staticcms-task.js'; +import { logErrorAndExit } from '../../logging.js'; const staticcms = new Command('staticcms') .description( @@ -75,7 +76,7 @@ const staticcms = new Command('staticcms') options.revert, options.cleanup, options.debug - ); + ).catch(logErrorAndExit); }); export default staticcms; diff --git a/src/commands/cms/storyblok.ts b/src/commands/cms/storyblok.ts index 8b828d0..0273965 100644 --- a/src/commands/cms/storyblok.ts +++ b/src/commands/cms/storyblok.ts @@ -1,6 +1,7 @@ import { Command } from 'commander'; import chalkTemplate from 'chalk-template'; import runTask from '../../tasks/cms/storyblok-task.js'; +import { logErrorAndExit } from '../../logging.js'; const storyblok = new Command('storyblok') .description( @@ -72,7 +73,7 @@ const storyblok = new Command('storyblok') options.revert, options.cleanup, options.debug - ); + ).catch(logErrorAndExit); }); export default storyblok; diff --git a/src/commands/cms/uniform.ts b/src/commands/cms/uniform.ts index 0f7f0be..33698e9 100644 --- a/src/commands/cms/uniform.ts +++ b/src/commands/cms/uniform.ts @@ -1,6 +1,7 @@ import { Command } from 'commander'; import chalkTemplate from 'chalk-template'; import runTask from '../../tasks/cms/uniform-task.js'; +import { logErrorAndExit } from '../../logging.js'; const uniform = new Command('uniform') .description( @@ -48,7 +49,7 @@ const uniform = new Command('uniform') options.revert, options.cleanup, options.debug - ); + ).catch(logErrorAndExit); }); export default uniform; diff --git a/src/commands/example/demo.ts b/src/commands/example/demo.ts index d58cbf7..3a128f5 100644 --- a/src/commands/example/demo.ts +++ b/src/commands/example/demo.ts @@ -1,6 +1,7 @@ import { Command } from 'commander'; import chalkTemplate from 'chalk-template'; import runTask from '../../tasks/example/example-task.js'; +import { logErrorAndExit } from '../../logging.js'; const demo = new Command('demo') .description( @@ -19,7 +20,12 @@ const demo = new Command('demo') .option('--cleanup', 'clean up tmp dirs before running', true) .option('--debug', 'show debugging output', false) .action((options) => { - runTask(options.rcOnly, options.revert, options.cleanup, options.debug); + runTask( + options.rcOnly, + options.revert, + options.cleanup, + options.debug + ).catch(logErrorAndExit); }); export default demo; diff --git a/src/commands/schema/dereference.ts b/src/commands/schema/dereference.ts index 6170b6d..4b597cd 100644 --- a/src/commands/schema/dereference.ts +++ b/src/commands/schema/dereference.ts @@ -1,6 +1,7 @@ import { Command } from 'commander'; import chalkTemplate from 'chalk-template'; import runTask from '../../tasks/schema/dereference-task.js'; +import { logErrorAndExit } from '../../logging.js'; const dereference = new Command('dereference') .description( @@ -34,8 +35,8 @@ const dereference = new Command('dereference') options.rcOnly, options.revert, options.cleanup, - options.debug, - ); + options.debug + ).catch(logErrorAndExit); }); export default dereference; diff --git a/src/commands/schema/layer.ts b/src/commands/schema/layer.ts index 664bef6..72f717d 100644 --- a/src/commands/schema/layer.ts +++ b/src/commands/schema/layer.ts @@ -1,6 +1,7 @@ import { Command } from 'commander'; import chalkTemplate from 'chalk-template'; import runTask from '../../tasks/schema/layer-task.js'; +import { logErrorAndExit } from '../../logging.js'; const types = new Command('layer') .description( @@ -42,7 +43,7 @@ const types = new Command('layer') options.revert, options.cleanup, options.debug - ); + ).catch(logErrorAndExit); }); export default types; diff --git a/src/commands/schema/types.ts b/src/commands/schema/types.ts index 9ff1981..9000ee9 100644 --- a/src/commands/schema/types.ts +++ b/src/commands/schema/types.ts @@ -1,6 +1,7 @@ import { Command } from 'commander'; import chalkTemplate from 'chalk-template'; import runTask from '../../tasks/schema/types-task.js'; +import { logErrorAndExit } from '../../logging.js'; const types = new Command('types') .description( @@ -36,7 +37,7 @@ const types = new Command('types') options.revert, options.cleanup, options.debug - ); + ).catch(logErrorAndExit); }); export default types; diff --git a/src/commands/tokens/compile.ts b/src/commands/tokens/compile.ts index 6719c7d..81fa8db 100644 --- a/src/commands/tokens/compile.ts +++ b/src/commands/tokens/compile.ts @@ -1,6 +1,7 @@ import { Command } from 'commander'; import chalkTemplate from 'chalk-template'; import runTask from '../../tasks/tokens/compile-task.js'; +import { logErrorAndExit } from '../../logging.js'; const init = new Command('compile') .description( @@ -36,7 +37,7 @@ const init = new Command('compile') options.revert, options.cleanup, options.debug - ); + ).catch(logErrorAndExit); }); export default init; diff --git a/src/commands/tokens/init.ts b/src/commands/tokens/init.ts index ebe95b0..38bf330 100644 --- a/src/commands/tokens/init.ts +++ b/src/commands/tokens/init.ts @@ -1,6 +1,7 @@ import { Command } from 'commander'; import chalkTemplate from 'chalk-template'; import runTask from '../../tasks/tokens/init-task.js'; +import { logErrorAndExit } from '../../logging.js'; const init = new Command('init') .description( @@ -35,8 +36,8 @@ const init = new Command('init') options.rcOnly, options.revert, options.cleanup, - options.debug, - ); + options.debug + ).catch(logErrorAndExit); }); export default init; diff --git a/src/commands/tokens/tofigma.ts b/src/commands/tokens/tofigma.ts index c66a34b..8e3bdde 100644 --- a/src/commands/tokens/tofigma.ts +++ b/src/commands/tokens/tofigma.ts @@ -1,6 +1,7 @@ import { Command } from 'commander'; import chalkTemplate from 'chalk-template'; import runTask from '../../tasks/tokens/tofigma-task.js'; +import { logErrorAndExit } from '../../logging.js'; const init = new Command('tofigma') .description( @@ -9,7 +10,7 @@ const init = new Command('tofigma') .option( '--token-dictionary-path ', chalkTemplate`relative path from project root to your token dictionary, default {bold src/token/dictionary}`, - 'src/token/dictionary', + 'src/token/dictionary' ) .option( '--rc-only', @@ -24,7 +25,12 @@ const init = new Command('tofigma') .option('--cleanup', 'clean up tmp dirs before running', true) .option('--debug', 'show debugging output', false) .action((options) => { - runTask(options.rcOnly, options.revert, options.cleanup, options.debug); + runTask( + options.rcOnly, + options.revert, + options.cleanup, + options.debug + ).catch(logErrorAndExit); }); export default init; diff --git a/src/logging.ts b/src/logging.ts index 43de065..f89efe5 100644 --- a/src/logging.ts +++ b/src/logging.ts @@ -307,3 +307,8 @@ export const getLogger = ( return winston.loggers.get(label); }; + +export const logErrorAndExit = (error: any) => { + console.error(error); + process.exit(1); +};