Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update the CLI generate command schematic to pass the HTTP method #9

Merged
merged 16 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ package-lock.json
expressots.config.ts

*.tgz

*.container.ts
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"singleQuote": false,
"trailingComma": "all",
"tabWidth": 4
}
20 changes: 19 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
{
"cSpell.ignoreWords": [
"Expresso"
]
],
"workbench.colorCustomizations": {
// "activityBar.foreground": "#38e715",
// "activityBarBadge.background": "#248d0f",
// "activityBarBadge.foreground": "#fcfcfc",
// "sideBar.border": "#38e715",
// "sideBarTitle.foreground": "#38e715",
// "sideBarSectionHeader.border": "#38e715",
// "editorGroupHeader.border": "#38e715",
// "editorGroupHeader.tabsBorder": "#38e715",
// "tab.border": "#38e715",
// "tab.activeBorderTop": "#38e715",
// "panel.border": "#38e715",
// "statusBar.border": "#38e715",
// "statusBar.foreground": "#38e715"
},
"editor.rulers": [
120
],
}
4 changes: 2 additions & 2 deletions expressots.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ExpressoConfig, Pattern } from "./src/types";
const config: ExpressoConfig = {
sourceRoot: "src",
scaffoldPattern: Pattern.KEBAB_CASE,
opinionated: true
opinionated: false
};

export default config;
export default config;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@expressots/cli",
"version": "1.3.0-dev",
"version": "1.3.0-rc-1",
"description": "Expressots CLI - modern, fast, lightweight nodejs web framework (@cli)",
"author": "Richard Zampieri",
"license": "MIT",
Expand Down Expand Up @@ -46,6 +46,7 @@
"chalk-animation": "^1",
"cli-progress": "^3.11.2",
"degit": "^2.8.4",
"glob": "^10.2.6",
"inquirer": "^8.0.0",
"mustache": "^4.2.0",
"ts-node": "^10.9.1",
Expand Down
61 changes: 38 additions & 23 deletions src/generate/cli.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
import { CommandModule, Argv } from "yargs";
import { Argv, CommandModule } from "yargs";
import { createTemplate } from "./form";
import chalk from "chalk";

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

const coerceSchematicAliases = (arg: string) => {
switch (arg) {
case "u":
return "usecase";
case "c":
return "controller";
case "d":
return "dto";
case "s":
return "service";
case "p":
return "provider";
case "e":
return "entity";
default:
return arg;
}
};

const generateProject = (): CommandModule<CommandModuleArgs, any> => {
return {
command: "generate [schematic] [path]",
Expand All @@ -17,6 +36,7 @@ const generateProject = (): CommandModule<CommandModuleArgs, any> => {
"dto",
"service",
"provider",
"entity",
] as const,
describe: "The schematic to generate",
type: "string",
Expand All @@ -26,33 +46,28 @@ const generateProject = (): CommandModule<CommandModuleArgs, any> => {
yargs.positional("path", {
describe: "The path to generate the schematic",
type: "string",
alias: "d",
});

yargs.positional("method", {
choices: [
"get",
"post",
"put",
"patch",
"delete",
] as const,
describe: "HTTP method",
type: "string",
alias: "m",
});

return yargs;
},
handler: async ({ schematic, path }) => {
const file = await createTemplate({ schematic, path });

console.log(chalk.green(`> ${file.split(".")[0]} ${schematic} created! 🚀`))
handler: async ({ schematic, path, method }) => {
await createTemplate({ schematic, path, method });
},
};
};

const coerceSchematicAliases = (arg: string) => {
switch (arg) {
case "u":
return "usecase";
case "c":
return "controller";
case "d":
return "dto";
case "s":
return "service";
case "p":
return "provider";
default:
return arg;
}
};

export { generateProject };
Loading