Skip to content

Commit beb3de8

Browse files
authored
Merge pull request #67 from expressots/feature/micro-api
feat: update project templates and improve configuration loading for …
2 parents 7a02d14 + 3553639 commit beb3de8

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"@codecov/vite-plugin": "^0.0.1-beta.9",
6767
"@commitlint/cli": "19.2.1",
6868
"@commitlint/config-conventional": "19.1.0",
69-
"@expressots/shared": "0.1.0",
69+
"@expressots/shared": "0.3.0",
7070
"@release-it/conventional-changelog": "7.0.2",
7171
"@types/chalk-animation": "1.6.1",
7272
"@types/cli-progress": "3.11.0",

src/commands/project.commands.ts

+26-11
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,27 @@ function getOutDir(): string {
4444
* @param compiler The compiler to load the configuration from
4545
* @returns The configuration
4646
*/
47-
const opinionatedConfig: Array<string> = [
48-
"--watch",
49-
"-r",
50-
"tsconfig-paths/register",
51-
"./src/main.ts",
52-
];
47+
async function opinionatedConfig(): Promise<Array<string>> {
48+
const { entryPoint } = await Compiler.loadConfig();
49+
const config = [
50+
"--watch",
51+
"-r",
52+
"tsconfig-paths/register",
53+
`./src/${entryPoint}.ts`,
54+
];
55+
return config;
56+
}
5357

54-
const nonOpinionatedConfig: Array<string> = ["--watch", "./src/main.ts"];
58+
/**
59+
* Load the configuration from the compiler
60+
* @param compiler The compiler to load the configuration from
61+
* @returns The configuration
62+
*/
63+
async function nonOpinionatedConfig(): Promise<Array<string>> {
64+
const { entryPoint } = await Compiler.loadConfig();
65+
const config = ["--watch", `./src/${entryPoint}.ts`];
66+
return config;
67+
}
5568

5669
/**
5770
* Dev command module
@@ -175,15 +188,17 @@ export const runCommand = async ({
175188
}: {
176189
command: string;
177190
}): Promise<void> => {
178-
const { opinionated } = await Compiler.loadConfig();
191+
const { opinionated, entryPoint } = await Compiler.loadConfig();
179192
const outDir = getOutDir();
180193

181194
try {
182195
switch (command) {
183196
case "dev":
184197
execCmd(
185198
"tsx",
186-
opinionated ? opinionatedConfig : nonOpinionatedConfig,
199+
opinionated
200+
? await opinionatedConfig()
201+
: await nonOpinionatedConfig(),
187202
);
188203
break;
189204
case "build":
@@ -212,10 +227,10 @@ export const runCommand = async ({
212227
config = [
213228
"-r",
214229
`./${outDir}/register-path.js`,
215-
`./${outDir}/src/main.js`,
230+
`./${outDir}/src/${entryPoint}.js`,
216231
];
217232
} else {
218-
config = [`./${outDir}/main.js`];
233+
config = [`./${outDir}/${entryPoint}.js`];
219234
}
220235
clearScreen();
221236
execCmd("node", config);

src/new/cli.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const commandOptions = (yargs: Argv): Argv => {
2222
.option("template", {
2323
describe: "The project template to use",
2424
type: "string",
25-
choices: ["opinionated", "non-opinionated"],
25+
choices: ["opinionated", "non-opinionated", "micro"],
2626
alias: "t",
2727
})
2828
.option("package-manager", {

src/new/form.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,9 @@ function renameEnvFile(directory: string): void {
120120
}
121121

122122
enum Template {
123-
"non-opinionated" = "Non-Opinionated :: Allows users to choose where to scaffold resources, offering flexible project organization.",
123+
nonopinionated = "Non-Opinionated :: Start with a clean slate and build your project from scratch.",
124124
opinionated = "Opinionated :: Automatically scaffolds resources into a preset project structure. (Recommended)",
125+
micro = "Micro :: A minimalistic template for building micro api's.",
125126
}
126127

127128
const enum PackageManager {
@@ -180,6 +181,7 @@ const projectForm = async (
180181
"Recommended",
181182
)})`,
182183
"Non-Opinionated :: Allows users to choose where to scaffold resources, offering flexible project organization.",
184+
"Micro :: A minimalistic template for building micro api's.",
183185
],
184186
},
185187
{
@@ -202,8 +204,9 @@ const projectForm = async (
202204

203205
// Hashmap of templates and their directories
204206
const templates: Record<string, unknown> = {
205-
"Non-Opinionated": "non_opinionated",
207+
NonOpinionated: "non_opinionated",
206208
Opinionated: "opinionated",
209+
Micro: "micro",
207210
};
208211

209212
if (answer.confirm) {

0 commit comments

Comments
 (0)