From 3553639f2a507c9423985ca7177246324bebdecd Mon Sep 17 00:00:00 2001 From: Richard Zampieri Date: Sat, 23 Nov 2024 18:47:21 -0800 Subject: [PATCH] feat: update project templates and improve configuration loading for CLI commands --- package.json | 2 +- src/commands/project.commands.ts | 37 ++++++++++++++++++++++---------- src/new/cli.ts | 2 +- src/new/form.ts | 7 ++++-- 4 files changed, 33 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 2a6e80a..f33127a 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,7 @@ "@codecov/vite-plugin": "^0.0.1-beta.9", "@commitlint/cli": "19.2.1", "@commitlint/config-conventional": "19.1.0", - "@expressots/shared": "0.1.0", + "@expressots/shared": "0.3.0", "@release-it/conventional-changelog": "7.0.2", "@types/chalk-animation": "1.6.1", "@types/cli-progress": "3.11.0", diff --git a/src/commands/project.commands.ts b/src/commands/project.commands.ts index 41c001d..879e206 100644 --- a/src/commands/project.commands.ts +++ b/src/commands/project.commands.ts @@ -44,14 +44,27 @@ function getOutDir(): string { * @param compiler The compiler to load the configuration from * @returns The configuration */ -const opinionatedConfig: Array = [ - "--watch", - "-r", - "tsconfig-paths/register", - "./src/main.ts", -]; +async function opinionatedConfig(): Promise> { + const { entryPoint } = await Compiler.loadConfig(); + const config = [ + "--watch", + "-r", + "tsconfig-paths/register", + `./src/${entryPoint}.ts`, + ]; + return config; +} -const nonOpinionatedConfig: Array = ["--watch", "./src/main.ts"]; +/** + * Load the configuration from the compiler + * @param compiler The compiler to load the configuration from + * @returns The configuration + */ +async function nonOpinionatedConfig(): Promise> { + const { entryPoint } = await Compiler.loadConfig(); + const config = ["--watch", `./src/${entryPoint}.ts`]; + return config; +} /** * Dev command module @@ -175,7 +188,7 @@ export const runCommand = async ({ }: { command: string; }): Promise => { - const { opinionated } = await Compiler.loadConfig(); + const { opinionated, entryPoint } = await Compiler.loadConfig(); const outDir = getOutDir(); try { @@ -183,7 +196,9 @@ export const runCommand = async ({ case "dev": execCmd( "tsx", - opinionated ? opinionatedConfig : nonOpinionatedConfig, + opinionated + ? await opinionatedConfig() + : await nonOpinionatedConfig(), ); break; case "build": @@ -212,10 +227,10 @@ export const runCommand = async ({ config = [ "-r", `./${outDir}/register-path.js`, - `./${outDir}/src/main.js`, + `./${outDir}/src/${entryPoint}.js`, ]; } else { - config = [`./${outDir}/main.js`]; + config = [`./${outDir}/${entryPoint}.js`]; } clearScreen(); execCmd("node", config); diff --git a/src/new/cli.ts b/src/new/cli.ts index dfb10e7..1a82ae8 100644 --- a/src/new/cli.ts +++ b/src/new/cli.ts @@ -22,7 +22,7 @@ const commandOptions = (yargs: Argv): Argv => { .option("template", { describe: "The project template to use", type: "string", - choices: ["opinionated", "non-opinionated"], + choices: ["opinionated", "non-opinionated", "micro"], alias: "t", }) .option("package-manager", { diff --git a/src/new/form.ts b/src/new/form.ts index 596eabb..d41e041 100644 --- a/src/new/form.ts +++ b/src/new/form.ts @@ -120,8 +120,9 @@ function renameEnvFile(directory: string): void { } enum Template { - "non-opinionated" = "Non-Opinionated :: Allows users to choose where to scaffold resources, offering flexible project organization.", + nonopinionated = "Non-Opinionated :: Start with a clean slate and build your project from scratch.", opinionated = "Opinionated :: Automatically scaffolds resources into a preset project structure. (Recommended)", + micro = "Micro :: A minimalistic template for building micro api's.", } const enum PackageManager { @@ -180,6 +181,7 @@ const projectForm = async ( "Recommended", )})`, "Non-Opinionated :: Allows users to choose where to scaffold resources, offering flexible project organization.", + "Micro :: A minimalistic template for building micro api's.", ], }, { @@ -202,8 +204,9 @@ const projectForm = async ( // Hashmap of templates and their directories const templates: Record = { - "Non-Opinionated": "non_opinionated", + NonOpinionated: "non_opinionated", Opinionated: "opinionated", + Micro: "micro", }; if (answer.confirm) {