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

Refactor/cli v290 adjustments #34

Merged
merged 3 commits into from
Mar 20, 2024
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
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