Skip to content

Commit

Permalink
Refactor hook formatter to not print if no output
Browse files Browse the repository at this point in the history
  • Loading branch information
simonprev committed Mar 3, 2024
1 parent 41516d8 commit 7ec0324
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
22 changes: 15 additions & 7 deletions cli/src/services/formatters/hook-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,30 @@ const capitalizeFirstLetter = (str: string) =>
export default class HookRunnerFomatter {
log(name: string, commands: string[]) {
const operation = capitalizeFirstLetter(decamelize(name, {separator: ' '}));
console.log(chalk.yellow('➤ '), chalk.bold(chalk.yellow(`${operation}:`)));
console.log(chalk.yellow('➤'), chalk.bold(chalk.yellow(`${operation}:`)));

commands.forEach((command) => {
console.log(' ', chalk.yellow(command));
console.log(' ', chalk.yellow(command));
});

console.log('');
}

error(command: string, errors: string[]) {
console.log(chalk.red('⚠ '), chalk.bold(chalk.red(`${command}:`)));
console.log(chalk.red('⚠'), chalk.bold(chalk.red(`${command}:`)));

errors.forEach((error) => {
console.log(' ', chalk.red(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(chalk.green('✓'), chalk.bold(chalk.green(`${command}:`)));

console.log(' ', chalk.green(message));

console.log('');
}
}
}
13 changes: 10 additions & 3 deletions cli/src/services/hook-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,17 @@ export default class HookRunner {

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

if (output.length > 0) {
formatter.error(hook, output);
} else {
formatter.error(hook, [`Exit status: ${error.status}`]);
}

process.exit(error.status);
}
});
Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"ueberauth_github": {:hex, :ueberauth_github, "0.8.3", "1c478629b4c1dae446c68834b69194ad5cead3b6c67c913db6fdf64f37f0328f", [:mix], [{:oauth2, "~> 1.0 or ~> 2.0", [hex: :oauth2, repo: "hexpm", optional: false]}, {:ueberauth, "~> 0.7", [hex: :ueberauth, repo: "hexpm", optional: false]}], "hexpm", "ae0ab2879c32cfa51d7287a48219b262bfdab0b7ec6629f24160564247493cc6"},
"ueberauth_google": {:hex, :ueberauth_google, "0.12.1", "90cf49743588193334f7a00da252f92d90bfd178d766c0e4291361681fafec7d", [:mix], [{:oauth2, "~> 1.0 or ~> 2.0", [hex: :oauth2, repo: "hexpm", optional: false]}, {:ueberauth, "~> 0.10.0", [hex: :ueberauth, repo: "hexpm", optional: false]}], "hexpm", "7f7deacd679b2b66e3bffb68ecc77aa1b5396a0cbac2941815f253128e458c38"},
"ueberauth_microsoft": {:hex, :ueberauth_microsoft, "0.23.0", "5c78e02a83d821ee45f96216bb6140ba688cc79b8b26e7ff438e3abe24615e1d", [:mix], [{:oauth2, "~> 1.0 or ~> 2.0", [hex: :oauth2, repo: "hexpm", optional: false]}, {:ueberauth, "~> 0.7", [hex: :ueberauth, repo: "hexpm", optional: false]}], "hexpm", "0c08d98203e6d3069f30306f09a6cb55b95c2bda94d6f8e90f05bd442ee96b82"},
"ueberauth_oidc": {:git, "https://github.com/DefactoSoftware/ueberauth_oidc.git", "0e46efb1214d848256f2cdfa394b80448a06c9a4", []},
"ueberauth_oidc": {:hex, :ueberauth_oidc, "0.1.7", "d610cbe5ef09881dff52126906b130307adcf02791ce158c1847fd50949b283a", [:mix], [{:httpoison, "~> 1.8", [hex: :httpoison, repo: "hexpm", optional: false]}, {:jose, "~> 1.11", [hex: :jose, repo: "hexpm", optional: false]}, {:openid_connect, "~> 0.2.2", [hex: :openid_connect, repo: "hexpm", optional: false]}, {:plug, "~> 1.11", [hex: :plug, repo: "hexpm", optional: false]}, {:ueberauth, "~> 0.7", [hex: :ueberauth, repo: "hexpm", optional: false]}], "hexpm", "34d612f66a5425af4142d6c9dece887c60188c31e1dc113e5ee8cecdc6c5e8a9"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"},
"unsafe": {:hex, :unsafe, "1.0.2", "23c6be12f6c1605364801f4b47007c0c159497d0446ad378b5cf05f1855c0581", [:mix], [], "hexpm", "b485231683c3ab01a9cd44cb4a79f152c6f3bb87358439c6f68791b85c2df675"},
"vega_lite": {:hex, :vega_lite, "0.1.8", "7f6119126ecaf4bc2c1854084370d7091424f5cce4795fbac044eee9963f0752", [:mix], [{:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: false]}], "hexpm", "6c8a9271f850612dd8a90de8d1ebd433590ed07ffef76fc2397c240dc04d3fdc"},
Expand Down

0 comments on commit 7ec0324

Please sign in to comment.