Skip to content

Commit

Permalink
feat(cli): Added title option to CLI application config
Browse files Browse the repository at this point in the history
  • Loading branch information
sullivanpj committed Dec 22, 2023
1 parent 9416a1a commit 272deb0
Show file tree
Hide file tree
Showing 5 changed files with 4,792 additions and 849 deletions.
4 changes: 3 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
"@storm-software/config-tools": "latest",
"chalk": "5.3.0",
"commander": "11.1.0",
"console-table-printer": "2.11.2"
"console-table-printer": "2.11.2",
"figlet": "^1.7.0"
},
"devDependencies": {
"@types/figlet": "^1.5.8",
"@types/node": "^20.10.5"
},
"publishConfig": {
Expand Down
57 changes: 54 additions & 3 deletions packages/cli/src/program/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { EMPTY_STRING, NEWLINE_STRING } from "@storm-stack/utilities";
import chalk from "chalk";
import { AddHelpTextContext, Argument, Command, Option } from "commander";
import { Table } from "console-table-printer";
import { text } from "figlet";
import { CLIArgument, CLICommand, CLIConfig, CLIOption } from "../types";
import { registerShutdown } from "./shutdown";

Expand Down Expand Up @@ -63,10 +64,60 @@ export async function createCLIProgram(cliConfig: CLIConfig): Promise<void> {
const logger = StormLog.create(config);

try {
logger.info(`Starting ${cliConfig.name ?? "Storm CLI Application"}`);
logger.start(cliConfig.name ?? "Storm CLI Application");
if (cliConfig.banner?.hide !== true) {
text(
cliConfig.banner?.name ?? cliConfig.name ?? config.name ?? "Storm CLI",
cliConfig.banner?.options ?? {
font: cliConfig.banner?.font ?? "Larry 3D"
},
function (err, data) {
if (err) {
return;
}

console.log(chalk.hex(config.colors.primary)(data));
}
);

if (cliConfig.by?.hide !== true) {
text(
`by ${cliConfig.by?.name ?? config.organization ?? "Storm"}`,
cliConfig.banner?.options ?? { font: cliConfig.by?.font ?? "Doom" },
function (err, data) {
if (err) {
return;
}

console.log(chalk.hex(config.colors.primary)(data));
}
);
}
}

const program = new Command(cliConfig.name ?? "Storm CLI Application");
logger.info(`⚡ Starting the ${cliConfig.name ?? "Storm CLI"} application`);
logger.info(
`\nWebsite: ${
cliConfig.homepageUrl ?? config.homepage
} \nDocumentation: ${
cliConfig.documentationUrl ?? config.homepage.endsWith("/")
? `${config.homepage}docs`
: `${config.homepage}/docs`
} \nRepository: ${cliConfig.repositoryUrl ?? config.repository} \n`
);
logger.info(
`\n This software is distributed under the ${
cliConfig.license ?? config.license
} license. \nFor more information, please visit ${
cliConfig.licenseUrl ??
cliConfig.documentationUrl ??
config.homepage.endsWith("/")
? `${config.homepage}license`
: `${config.homepage}/license`
} \n`
);

logger.start(cliConfig.name ?? "Storm CLI Application");
const program = new Command(cliConfig.name ?? "Storm CLI");
const shutdown = registerShutdown({
logger,
onShutdown: () => {
Expand Down
15 changes: 15 additions & 0 deletions packages/cli/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
import { MaybePromise } from "@storm-stack/utilities";
import { Command } from "commander";
import { Fonts, Options } from "figlet";

export interface CLIConfig {
name: string;
banner?: CLITitle;
by?: CLITitle;
description: string;
homepageUrl?: string;
documentationUrl?: string;
repositoryUrl?: string;
license?: string;
licenseUrl?: string;
commands: CLICommand[];
preAction: (command: Command) => MaybePromise<void>;
postAction: (command: Command) => MaybePromise<void>;
}

export interface CLITitle {
name?: string;
font?: Fonts;
options?: Options;
hide?: boolean;
}

export interface CLICommand {
name: string;
description: string;
Expand Down

0 comments on commit 272deb0

Please sign in to comment.