Skip to content

Commit

Permalink
feat: fixed nested resource gen e add fn comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rsaz committed Mar 29, 2024
1 parent 0a105bb commit 3a2c26c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/generate/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ type CreateTemplateProps = {

/**
* Create a template based on the schematic
* @param schematic
* @param path
* @param method
* @param schematic - the schematic to create
* @param path - the path to create the schematic
* @param method - the http method
* @returns the file created
*/
export const createTemplate = async ({
Expand Down
7 changes: 7 additions & 0 deletions src/generate/utils/nonopininated-cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ import {
writeTemplate,
} from "./command-utils";

/**
* Process the non-opinionated command
* @param schematic - The schematic
* @param target - The target
* @param method - The method
* @param expressoConfig - The expresso config
*/
export async function nonOpinionatedProcess(
schematic: string,
target: string,
Expand Down
44 changes: 38 additions & 6 deletions src/generate/utils/opinionated-cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,21 @@ import {
writeTemplate,
} from "./command-utils";
import { addControllerToModule } from "../../utils/add-controller-to-module";
import { addModuleToContainer, addModuleToContainerNestedPath } from "../../utils/add-module-to-container";
import {
addModuleToContainer,
addModuleToContainerNestedPath,
} from "../../utils/add-module-to-container";
import { ExpressoConfig } from "../../@types";

/**
* Process commands for opinionated service scaffolding
* @param schematic - Resource to scaffold
* @param target - Target path
* @param method - HTTP method
* @param expressoConfig - Expresso configuration [expressots.config.ts]
* @param pathStyle - Path command style [sugar, nested, single]
* @returns
*/
export async function opinionatedProcess(
schematic: string,
target: string,
Expand Down Expand Up @@ -73,7 +85,6 @@ export async function opinionatedProcess(
});

if (pathStyle === PathStyle.Sugar) {
console.log("Sugar");
await generateModuleServiceSugarPath(
f.outputPath,
m.className,
Expand All @@ -83,15 +94,13 @@ export async function opinionatedProcess(
m.folderToScaffold,
);
} else if (pathStyle === PathStyle.Nested) {
console.log("Nested");
await generateModuleServiceNestedPath(
f.outputPath,
m.className,
m.path,
m.folderToScaffold,
);
} else if (pathStyle === PathStyle.Single) {
console.log("Single");
await generateModuleServiceSinglePath(
f.outputPath,
m.className,
Expand Down Expand Up @@ -284,6 +293,14 @@ async function generateUseCaseService(
});
}

/**
* Generate a use case
* @param outputPath - The output path
* @param className - The class name
* @param moduleName - The module name
* @param path - The path
* @param fileName - The file name
*/
async function generateUseCase(
outputPath: string,
className: string,
Expand Down Expand Up @@ -444,7 +461,7 @@ async function generateMiddleware(
}

/**
* Generate a module for service scaffolding
* Generate a module for service scaffolding with sugar path
* @param outputPath - The output path
* @param className - The class name
* @param moduleName - The module name
Expand Down Expand Up @@ -507,6 +524,13 @@ async function generateModuleServiceSugarPath(
);
}

/**
* Generate a module for service scaffolding with single path
* @param outputPath - The output path
* @param className - The class name
* @param moduleName - The module name
* @param path - The path
*/
async function generateModuleServiceSinglePath(
outputPathController: string,
className: string,
Expand Down Expand Up @@ -562,13 +586,21 @@ async function generateModuleServiceSinglePath(
);
}

/**
* Generate a module for service scaffolding with nested path
* @param outputPathController
* @param className
* @param path
* @param folderToScaffold
* @returns
*/
async function generateModuleServiceNestedPath(
outputPathController: string,
className: string,
path: string,
folderToScaffold: string,
): Promise<void> {
const moduleFileName = nodePath.basename(path, '/');
const moduleFileName = nodePath.basename(path, "/");
const newModulePath = nodePath
.join(folderToScaffold, path, "..")
.normalize();
Expand Down

0 comments on commit 3a2c26c

Please sign in to comment.