Skip to content

Commit

Permalink
Merge pull request #202 from samchon/features/options
Browse files Browse the repository at this point in the history
Close #201 - `DynamicModule` supports detailed options
  • Loading branch information
samchon authored Dec 22, 2022
2 parents 1e9f029 + 181bae2 commit 574fd23
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nestia",
"version": "4.0.0",
"version": "4.0.1",
"description": "Nestia CLI",
"main": "bin/index.js",
"bin": {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestia/core",
"version": "1.0.2",
"version": "1.0.3",
"description": "Super-fast validation decorators of NestJS",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -58,7 +58,7 @@
"raw-body": "*",
"reflect-metadata": "*",
"rxjs": "*",
"typia": "^3.4.11"
"typia": "^3.4.15"
},
"peerDependencies": {
"ttypescript": ">= 1.5.15",
Expand Down
8 changes: 6 additions & 2 deletions packages/core/src/decorators/DynamicModule.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { Module } from "@nestjs/common";
import { ModuleMetadata } from "@nestjs/common/interfaces";

import { Creator } from "../typings/Creator";
import { load_controllers } from "./internal/load_controller";

export namespace DynamicModule {
export async function mount(path: string): Promise<object> {
export async function mount(
path: string,
options: Omit<ModuleMetadata, "controllers"> = {},
): Promise<object> {
// LOAD CONTROLLERS
const controllers: Creator<object>[] = await load_controllers(path);

// RETURN WITH DECORATING
@Module({ controllers })
@Module({ ...options, controllers })
class NestiaModule {}
return NestiaModule;
}
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/decorators/EncryptedModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,19 @@ export namespace EncryptedModule {
*
* @param path Directory path of the controller classes
* @param password Encryption password or its getter function
* @param options Additional options except controller
* @returns Class decorated module instance
*/
export async function dynamic(
path: string,
password: IEncryptionPassword | IEncryptionPassword.Closure,
options: Omit<ModuleMetadata, "controllers"> = {},
): Promise<object> {
// LOAD CONTROLLERS
const controllers: Creator<object>[] = await load_controllers(path);

// RETURNS WITH DECORATING
@EncryptedModule({ controllers }, password)
@EncryptedModule({ ...options, controllers }, password)
class NestiaModule {}
return NestiaModule;
}
Expand Down
6 changes: 2 additions & 4 deletions packages/core/src/executable/internal/CoreSetupWizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,13 @@ export namespace CoreSetupWizard {
* - "is": Use typia.isStringify() function
* - "validate": Use typia.validateStringify() function
*/
"stringify": "is",
"stringify": "is"
}`) as Comment.CommentObject,
);
if (typia === undefined)
plugins.push(
Comment.parse(`{
"transform": "typia/lib/transform",
"numeric": true, // check isNaN() and isFinite()
"functional": false, // validate function type
"transform": "typia/lib/transform"
}`) as Comment.CommentObject,
);
await fs.promises.writeFile(
Expand Down
23 changes: 12 additions & 11 deletions src/NestiaSetupWizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,16 @@ import fs from "fs";

export namespace NestiaSetupWizard {
export async function ttypescript(manager: string): Promise<void> {
await prepare(manager);
const { CoreSetupWizard } = await import(
"@nestia/core/lib/executable/internal/CoreSetupWizard"
);
CoreSetupWizard.ttypescript(manager);
const wizard = await prepare(manager);
await wizard.ttypescript(manager);
}

export async function tsPatch(manager: string): Promise<void> {
await prepare(manager);
const { CoreSetupWizard } = await import(
"@nestia/core/lib/executable/internal/CoreSetupWizard"
);
CoreSetupWizard.tsPatch(manager);
const wizard = await prepare(manager);
await wizard.tsPatch(manager);
}

export async function prepare(manager: string): Promise<any> {
async function prepare(manager: string) {
if (fs.existsSync("package.json") === false)
halt(() => {})("make package.json file or move to it.");

Expand All @@ -27,6 +21,13 @@ export namespace NestiaSetupWizard {
);
add(manager)(pack)("@nestia/core", false);
add(manager)(pack)("@nestia/sdk", false);

const modulo: typeof import("@nestia/core/lib/executable/internal/CoreSetupWizard") =
await import(
process.cwd() +
"/node_modules/@nestia/core/lib/executable/internal/CoreSetupWizard"
);
return modulo.CoreSetupWizard;
}
}

Expand Down

0 comments on commit 574fd23

Please sign in to comment.