Skip to content

Commit

Permalink
Merge pull request #34 from expressots/refactor/cli-v290-adjustments
Browse files Browse the repository at this point in the history
Refactor/cli v290 adjustments
  • Loading branch information
rsaz authored Mar 20, 2024
2 parents f758f1b + 1782206 commit 51d675f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 40 deletions.
70 changes: 35 additions & 35 deletions src/new/cli.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
import { Argv, CommandModule } from "yargs";
import { projectForm } from "./form";

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

const createProject = (): CommandModule<CommandModuleArgs, any> => {
const packageManagers: Array<string> = ["npm", "yarn", "pnpm"];
const packageManagers: Array<string> = [
"npm",
"yarn",
"pnpm",
...(process.platform !== "win32" ? ["bun"] : []),
];

if (process.platform !== "win32") {
packageManagers.push("bun");
}
const commandOptions = (yargs: Argv): Argv => {
return yargs
.positional("project-name", {
describe: "The name of the project",
type: "string",
})
.option("template", {
describe: "The project template to use",
type: "string",
choices: ["opinionated", "non-opinionated"],
alias: "t",
})
.option("package-manager", {
describe: "The package manager to use",
type: "string",
choices: packageManagers,
alias: "p",
})
.option("directory", {
describe: "The directory for new project",
type: "string",
alias: "d",
})
.implies("package-manager", "template")
.implies("template", "package-manager");
};

const createProject = (): CommandModule<CommandModuleArgs, any> => {
return {
command: "new <project-name> [package-manager] [template] [directory]",
describe: "Create a new project",
builder: (yargs: Argv): Argv => {
yargs
.positional("project-name", {
describe: "The name of the project",
type: "string",
})
.option("template", {
describe: "The project template to use",
type: "string",
choices: ["opinionated", "non-opinionated"],
alias: "t",
})
.option("package-manager", {
describe: "The package manager to use",
type: "string",
choices: packageManagers,
alias: "p",
})
.option("directory", {
describe: "The directory for new project",
type: "string",
alias: "d",
})
.implies("package-manager", "template")
.implies("template", "package-manager");

return yargs;
},
builder: commandOptions,
handler: async ({
projectName,
packageManager,
Expand Down
13 changes: 8 additions & 5 deletions src/new/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ function changePackageName({
}

enum Template {
"non-opinionated" = "Non-Opinionated :: A simple ExpressoTS project.",
opinionated = "Opinionated :: A complete ExpressoTS project with an opinionated structure and features.",
"non-opinionated" = "Non-Opinionated :: Allows users to choose where to scaffold resources, offering flexible project organization.",
opinionated = "Opinionated :: Automatically scaffolds resources into a preset project structure. (Recommended)",
}

const enum PackageManager {
Expand Down Expand Up @@ -145,8 +145,10 @@ const projectForm = async (projectName: string, args: any[]): Promise<void> => {
name: "template",
message: "Select a template",
choices: [
"Opinionated :: A complete ExpressoTS project with an opinionated structure and features.",
"Non-Opinionated :: A simple ExpressoTS project.",
`Opinionated :: Automatically scaffolds resources into a preset project structure. (${chalk.yellow(
"Recommended",
)})`,
"Non-Opinionated :: Allows users to choose where to scaffold resources, offering flexible project organization.",
],
},
{
Expand Down Expand Up @@ -239,7 +241,7 @@ const projectForm = async (projectName: string, args: any[]): Promise<void> => {

console.log("\n");
console.log(
"🐎 Project ",
"🐎 Project",
chalk.green(answer.name),
"created successfully!",
);
Expand Down Expand Up @@ -277,6 +279,7 @@ const projectForm = async (projectName: string, args: any[]): Promise<void> => {
),
),
);
console.log("\n");
}
};

Expand Down

0 comments on commit 51d675f

Please sign in to comment.