Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log error when command failed #50

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions src/commands/cms/stackbit.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -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);
})
);

Expand Down
3 changes: 2 additions & 1 deletion src/commands/cms/staticcms.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -75,7 +76,7 @@ const staticcms = new Command('staticcms')
options.revert,
options.cleanup,
options.debug
);
).catch(logErrorAndExit);
});

export default staticcms;
3 changes: 2 additions & 1 deletion src/commands/cms/storyblok.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -72,7 +73,7 @@ const storyblok = new Command('storyblok')
options.revert,
options.cleanup,
options.debug
);
).catch(logErrorAndExit);
});

export default storyblok;
3 changes: 2 additions & 1 deletion src/commands/cms/uniform.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -48,7 +49,7 @@ const uniform = new Command('uniform')
options.revert,
options.cleanup,
options.debug
);
).catch(logErrorAndExit);
});

export default uniform;
8 changes: 7 additions & 1 deletion src/commands/example/demo.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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;
5 changes: 3 additions & 2 deletions src/commands/schema/dereference.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -34,8 +35,8 @@ const dereference = new Command('dereference')
options.rcOnly,
options.revert,
options.cleanup,
options.debug,
);
options.debug
).catch(logErrorAndExit);
});

export default dereference;
3 changes: 2 additions & 1 deletion src/commands/schema/layer.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -42,7 +43,7 @@ const types = new Command('layer')
options.revert,
options.cleanup,
options.debug
);
).catch(logErrorAndExit);
});

export default types;
3 changes: 2 additions & 1 deletion src/commands/schema/types.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -36,7 +37,7 @@ const types = new Command('types')
options.revert,
options.cleanup,
options.debug
);
).catch(logErrorAndExit);
});

export default types;
3 changes: 2 additions & 1 deletion src/commands/tokens/compile.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -36,7 +37,7 @@ const init = new Command('compile')
options.revert,
options.cleanup,
options.debug
);
).catch(logErrorAndExit);
});

export default init;
5 changes: 3 additions & 2 deletions src/commands/tokens/init.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -35,8 +36,8 @@ const init = new Command('init')
options.rcOnly,
options.revert,
options.cleanup,
options.debug,
);
options.debug
).catch(logErrorAndExit);
});

export default init;
10 changes: 8 additions & 2 deletions src/commands/tokens/tofigma.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -9,7 +10,7 @@ const init = new Command('tofigma')
.option(
'--token-dictionary-path <directory>',
chalkTemplate`relative path from project root to your token dictionary, default {bold src/token/dictionary}`,
'src/token/dictionary',
'src/token/dictionary'
)
.option(
'--rc-only',
Expand All @@ -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;
5 changes: 5 additions & 0 deletions src/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,8 @@ export const getLogger = (

return winston.loggers.get(label);
};

export const logErrorAndExit = (error: any) => {
console.error(error);
process.exit(1);
};