Skip to content

Commit

Permalink
Add output and error handling to hook-runner (#417)
Browse files Browse the repository at this point in the history
* Add output and error handling to hook-runner

* cleanup + linting

* run make format also

* Nicer output when script succeeds
  • Loading branch information
marclefrancois authored Mar 3, 2024
1 parent bfd259e commit edec1f7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
12 changes: 12 additions & 0 deletions cli/src/services/formatters/hook-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,16 @@ export default class HookRunnerFomatter {
});
console.log('');
}
error(command: string, errors: string[]) {
console.log(chalk.red('⚠ '), chalk.bold(chalk.red(`${command}:`)));
errors.forEach((error) => {
console.log(' ', chalk.red(error));
});
console.log('');
}
success(command: string, message: string) {
console.log(chalk.green('✓ '), chalk.bold(chalk.green(`${command}:`)));
console.log(' ', chalk.green(message));
console.log('');
}
}
15 changes: 12 additions & 3 deletions cli/src/services/hook-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,18 @@ export default class HookRunner {
const hooks = this.hooks[name];

if (hooks) {
new Formatter().log(name, hooks);

hooks.forEach(execSync);
const formatter = new Formatter();
formatter.log(name, hooks);

hooks.forEach((hook) => {
try {
const output: string = execSync(hook, {stdio: 'pipe'}).toString();
formatter.success(hook, output);
} catch (error: any) {
formatter.error(hook, [error.stderr.toString()]);
process.exit(error.status);
}
});
}

return this.document.refreshPaths();
Expand Down

0 comments on commit edec1f7

Please sign in to comment.