Skip to content

Commit

Permalink
Merge pull request #67 from expressots/feature/micro-api
Browse files Browse the repository at this point in the history
feat: update project templates and improve configuration loading for …
  • Loading branch information
rsaz authored Nov 24, 2024
2 parents 7a02d14 + 3553639 commit beb3de8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
37 changes: 26 additions & 11 deletions src/commands/project.commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,27 @@ function getOutDir(): string {
* @param compiler The compiler to load the configuration from
* @returns The configuration
*/
const opinionatedConfig: Array<string> = [
"--watch",
"-r",
"tsconfig-paths/register",
"./src/main.ts",
];
async function opinionatedConfig(): Promise<Array<string>> {
const { entryPoint } = await Compiler.loadConfig();
const config = [
"--watch",
"-r",
"tsconfig-paths/register",
`./src/${entryPoint}.ts`,
];
return config;
}

const nonOpinionatedConfig: Array<string> = ["--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<Array<string>> {
const { entryPoint } = await Compiler.loadConfig();
const config = ["--watch", `./src/${entryPoint}.ts`];
return config;
}

/**
* Dev command module
Expand Down Expand Up @@ -175,15 +188,17 @@ export const runCommand = async ({
}: {
command: string;
}): Promise<void> => {
const { opinionated } = await Compiler.loadConfig();
const { opinionated, entryPoint } = await Compiler.loadConfig();
const outDir = getOutDir();

try {
switch (command) {
case "dev":
execCmd(
"tsx",
opinionated ? opinionatedConfig : nonOpinionatedConfig,
opinionated
? await opinionatedConfig()
: await nonOpinionatedConfig(),
);
break;
case "build":
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/new/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down
7 changes: 5 additions & 2 deletions src/new/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.",
],
},
{
Expand All @@ -202,8 +204,9 @@ const projectForm = async (

// Hashmap of templates and their directories
const templates: Record<string, unknown> = {
"Non-Opinionated": "non_opinionated",
NonOpinionated: "non_opinionated",
Opinionated: "opinionated",
Micro: "micro",
};

if (answer.confirm) {
Expand Down

0 comments on commit beb3de8

Please sign in to comment.