Skip to content

Commit

Permalink
feat(cli): add git hook to script info output
Browse files Browse the repository at this point in the history
  • Loading branch information
umbopepato committed Oct 30, 2020
1 parent 26ed86c commit dba1ba6
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions src/scripts_info.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,41 @@
import { blue, bold, gray } from "../deps.ts";
import {
isScriptObject,
ScriptDefinition,
ScriptsConfiguration,
} from "./scripts_config.ts";
import { blue, bold, gray, red } from "../deps.ts";
import { ScriptDefinition, ScriptsConfiguration } from "./scripts_config.ts";
import { flattenCommands, normalizeScript } from "./normalize_script.ts";
import { isScriptObject } from "./util.ts";

export function printScriptsInfo(config: ScriptsConfiguration) {
const scripts = Object.entries(config.scripts);
console.log(
`Available scripts:\n\n${
scripts.map(([name, value]) =>
`• ${blue(bold(name))}\n${scriptInfo(value)}`
).join("\n\n")
}\n\nTo run a script pass its name as the first argument to the ${
bold("vr")
} command (ie: ${
bold(`vr ${scripts[0][0]}`)
}).\nAny additional arguments will be passed to the script.`,
);
console.log(`
🦖 ${bold("Available scripts")}
${
scripts.map(([name, value]) =>
` • ${blue(bold(name))}\n${scriptInfo(value)}`
).join("\n\n")
}
To run a script pass its name as the first argument to the ${
bold("vr")
} command:
$ ${bold(`vr ${scripts[0][0]}`)}
Any additional arguments will be passed to the script.
`);
}

function scriptInfo(script: ScriptDefinition): string {
let info = [];
if (script instanceof Object && isScriptObject(script) && script.desc) {
info.push(` ${script.desc}`);
const info = [];
if (isScriptObject(script)) {
if (script.desc) info.push(` ${script.desc}`);
if (script.githook) {
info.push(` ${gray("Runs at")} ${red(script.githook)}`);
}
}
const commands = flattenCommands(normalizeScript(script, {}));
info.push(
gray(
` $ ${commands.map((c) => c.cmd).slice(0, 3).join(", ")}${
` $ ${commands.map((c) => c.cmd).slice(0, 3).join(", ")}${
commands.length > 3 ? "..." : ""
}`,
),
Expand Down

0 comments on commit dba1ba6

Please sign in to comment.