From f0056ff7cfb3e7ab2b61d49d7cf28132a1bf457c Mon Sep 17 00:00:00 2001 From: Jacob Shuman <44483276+jacob-shuman@users.noreply.github.com> Date: Fri, 27 May 2022 17:36:54 -0600 Subject: [PATCH] feat: show shorthands for -s option --- src/helpers.ts | 14 ++++++++++++++ src/index.ts | 11 ++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/helpers.ts b/src/helpers.ts index f60cb53..0be0f54 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -28,6 +28,20 @@ export const getScripts = (path: string): Scripts => { return scripts; }; +export const displayScripts = (scripts: Scripts, delimiter: string) => { + const shorthandScripts: Record = Object.entries( + scripts + ).reduce( + (acc, [k, v]) => ({ + ...acc, + [`${k} (${shortenScriptName(k, delimiter)})`]: v, + }), + {} + ); + + console.log(shorthandScripts); +}; + export const shortenScriptName = ( scriptName: string, delimiter: string diff --git a/src/index.ts b/src/index.ts index c763276..9b9bb2a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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"; @@ -18,7 +19,11 @@ program .option("-p, --path ", "Path to folder containing package.json.", ".") .option("-d, --delimiter ", "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, @@ -34,7 +39,7 @@ program const scripts = getScripts(options.path); if (options.scripts) { - console.log(scripts); + displayScripts(scripts, options.delimiter); process.exit(0); }