Skip to content

Commit

Permalink
feat: show shorthands for -s option
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-shuman committed May 27, 2022
1 parent 681eed8 commit f0056ff
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ export const getScripts = (path: string): Scripts => {
return scripts;
};

export const displayScripts = (scripts: Scripts, delimiter: string) => {
const shorthandScripts: Record<string, string> = Object.entries(
scripts
).reduce(
(acc, [k, v]) => ({
...acc,
[`${k} (${shortenScriptName(k, delimiter)})`]: v,
}),
{}
);

console.log(shorthandScripts);
};

export const shortenScriptName = (
scriptName: string,
delimiter: string
Expand Down
11 changes: 8 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { program } from "commander";
import chalk from "chalk";
import packageJson from "../package.json";
import {
findScript,
getScripts,
displayScripts,
findScript,
runScript,
shortenScriptNames,
} from "./helpers";
Expand All @@ -18,7 +19,11 @@ program
.option("-p, --path <path>", "Path to folder containing package.json.", ".")
.option("-d, --delimiter <delim>", "Character to separate words by.", ":")
.option("-a, --auto", "Run the selected script without confirmation.", false)
.option("-s, --scripts", "Display scripts in found package.json.", false)
.option(
"-s, --scripts",
"Display scripts and shorthands in found package.json.",
false
)
.action(
async (
query: string,
Expand All @@ -34,7 +39,7 @@ program
const scripts = getScripts(options.path);

if (options.scripts) {
console.log(scripts);
displayScripts(scripts, options.delimiter);
process.exit(0);
}

Expand Down

0 comments on commit f0056ff

Please sign in to comment.