Skip to content

Commit

Permalink
feat: update the CLI generate command schematic to pass the HTTP meth…
Browse files Browse the repository at this point in the history
…od (#9)

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

* Merge branch 'main' of https://github.com/expressots/expressots-cli into ETS-237-generate-command-schematic-to-pass-the-http-method

* fix: add entity schematic

* fix: validate http method, add module opinionated

* fix: update non-opinionated gen slash

* fix: scaffold slash, binding scope add

* fix: add http method specific template on scaffold

* fix: add response type on res from express

* fix: add template usecase, and single path module

* fix: module scaffold based on modulepath

* fix: standard message on scaffold resources

* fix: non opinionated edge cases fixes

* fix: update controller to module path non-op

* fix: removing unnecessary consoles

* fix: update version to rc-1

---------

Co-authored-by: Richard Zampieri <[email protected]>
  • Loading branch information
juliano-soares and rsaz committed May 31, 2023
1 parent acb5d3f commit 67059b6
Show file tree
Hide file tree
Showing 21 changed files with 577 additions and 149 deletions.
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

0 comments on commit 67059b6

Please sign in to comment.