Skip to content

Commit

Permalink
feat: resource list panel
Browse files Browse the repository at this point in the history
  • Loading branch information
rsaz committed Mar 29, 2024
1 parent 8ef1714 commit 249cc73
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 14 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"@expressots/boost-ts": "1.1.1",
"chalk-animation": "2.0.3",
"cli-progress": "3.11.2",
"cli-table3": "^0.6.4",
"degit": "2.8.4",
"glob": "10.2.6",
"inquirer": "8.0.0",
Expand Down
4 changes: 2 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { runCommandModule } from "./commands/project.commands";
import { generateProject } from "./generate";
import { helpCommand } from "./help/cli";
import { infoProject } from "./info";
import { createProject } from "./new";
import { generateProviders } from "./providers";

export const CLI_VERSION = "1.3.4";

console.log(`\n[🐎 Expressots]\n`);

yargs(hideBin(process.argv))
Expand All @@ -19,6 +18,7 @@ yargs(hideBin(process.argv))
.command(generateProviders())
.command(generateProject())
.command(infoProject())
.command(helpCommand())
.example("$0 new expressots-demo", "Create interactively")
.example("$0 new expressots-demo -d ./", "Create interactively with path")
.example("$0 new expressots-demo -p yarn -t opinionated", "Create silently")
Expand Down
18 changes: 18 additions & 0 deletions src/help/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { CommandModule } from "yargs";
import { helpForm } from "./form";

// eslint-disable-next-line @typescript-eslint/ban-types
type CommandModuleArgs = {};

const helpCommand = (): CommandModule<CommandModuleArgs, any> => {
return {
command: "resources",
describe: "Resource list",
aliases: ["r"],
handler: async () => {
await helpForm();
},
};
};

export { helpCommand };
46 changes: 46 additions & 0 deletions src/help/form.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import chalk from "chalk";
import CliTable3 from "cli-table3";

const helpForm = async (): Promise<void> => {
const table = new CliTable3({
head: [
chalk.green("Name"),
chalk.green("Alias"),
chalk.green("Description"),
],
colWidths: [15, 10, 60],
});

table.push(
["new project", "new", "Generate a new project"],
["info", "i", "Provides project information"],
["resources", "r", "Displays cli commands and resources"],
["help", "h", "Show command help"],
[
"service",
"g s",
"Generate a service [controller, usecase, dto, module]",
],
["controller", "g c", "Generate a controller"],
["usecase", "g u", "Generate a usecase"],
["dto", "g d", "Generate a dto"],
["entity", "g e", "Generate an entity"],
["provider", "g p", "Generate a provider"],
["module", "g mo", "Generate a module"],
["middleware", "g mi", "Generate a middleware"],
);
console.log(
chalk.bold.white("ExpressoTS:", `${chalk.green("Resources List")}`),
);
console.log(chalk.whiteBright(table.toString()));
console.log(
chalk.bold.white(
`📝 More info: ${chalk.green(
"https://doc.expresso-ts.com/docs/category/cli",
)}`,
),
);
console.log("\n");
};

export { helpForm };
Empty file added src/help/index.ts
Empty file.
46 changes: 34 additions & 12 deletions src/info/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,27 @@ import chalk from "chalk";
import path from "path";
import fs from "fs";
import os from "os";
import { CLI_VERSION } from "../cli";
import { printError } from "../utils/cli-ui";
import { exec } from "child_process";
import util from "util";

const execPromisified = util.promisify(exec);

async function getCLIVersion(): Promise<string> {
try {
const { stdout } = await execPromisified("npm list -g @expressots/cli");
const version = stdout;
const versionRegex = /@expressots\/cli@(\d+\.\d+\.\d+)/;
const versionMatch: string = version.match(versionRegex)?.[1];
return versionMatch;
} catch (error) {
printError(
"CLI version not available.",
"Unable to get the CLI version.",
);
}
return "";
}

function getInfosFromPackage() {
try {
Expand All @@ -16,10 +35,12 @@ function getInfosFromPackage() {
const packageJson = JSON.parse(fileContents);

console.log(chalk.green("ExpressoTS Project:"));
console.log(chalk.bold(`\tName: ${packageJson.name}`));
console.log(chalk.bold(`\tDescription: ${packageJson.description}`));
console.log(chalk.bold(`\tVersion: ${packageJson.version}`));
console.log(chalk.bold(`\tAuthor: ${packageJson.author}`));
console.log(chalk.white(`\tName: ${packageJson.name}`));
console.log(chalk.white(`\tDescription: ${packageJson.description}`));
console.log(chalk.white(`\tVersion: ${packageJson.version}`));
console.log(chalk.white(`\tAuthor: ${packageJson.author}`));

//getCLIVersion();
} catch (error) {
printError(
"No project information available.",
Expand All @@ -28,15 +49,16 @@ function getInfosFromPackage() {
}
}

const infoForm = async (): Promise<void> => {
console.log(chalk.green("System informations:"));
console.log(chalk.bold(`\tOS Version: ${os.version()}`));
console.log(chalk.bold(`\tNodeJS version: ${process.version}`));
const infoForm = (): void => {
const cliVersion = "1.6.0"; //await getCLIVersion();
getInfosFromPackage();

console.log(chalk.green("System information:"));
console.log(chalk.white(`\tOS Version: ${os.version()}`));
console.log(chalk.white(`\tNodeJS version: ${process.version}`));

console.log(chalk.green("CLI Version:"));
console.log(chalk.bold(`\tCurrent version: v${CLI_VERSION}`));

getInfosFromPackage();
console.log(chalk.white(`\tCurrent version: v${cliVersion}`));
};

export { infoForm };

0 comments on commit 249cc73

Please sign in to comment.