2.0.0 • Published 2 years ago

dynamod v2.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

dynamod

Generate boilerplate for NestJS dynamic modules similar to how the native NestJS cli lets you create simple modules/services.

Usage

There are two main usages for this generator.

1. Generate a module within an existing project.

2. Generate a standalone package that you can build and publish to npm or use within your monorepo.

Usage within an existing NestJS project

# within /my-cool-project
npx dynamod <module name>

## example
npx dynamod banana

NOTE: this will place the directory within ./src

Output

./src
├──banana
   ├── banana.constants.ts
   ├── banana.module.ts
   ├── banana.service.ts
   └── interfaces
       ├── banana-module.interfaces.ts
       └── index.ts

Usage as package

This will create the directory as a kebab-case version of the module name.

mkdir examplemod
cd examplemod

npx dynamod examplemod --package
# or
npx dynamod examplemod -p

Output

./examplemod/
  ├── README.md
  ├── nest-cli.json
  ├── package.json
  ├── src
  │   ├── __tests__
  │   │   └── examplemod.spec.ts
  │   ├── examplemod.constants.ts
  │   ├── examplemod.module.ts
  │   ├── examplemod.service.ts
  │   ├── index.ts
  │   └── interfaces
  │       ├── examplemod-module.interfaces.ts
  │       └── index.ts
  ├── tsconfig.build.json
  └── tsconfig.json

Options

ConfigFlagOutput
Scaffold as standalone package--package -pGenerate the module to be a standalone package (to publish to npm for example). Generates extra files: package.json, readme, and dotfiles.

Final product either way sets you up with register and registerAsync methods in your module.

Use within your app

@Module({
  // ...
  imports: [
    ConfigModule.forRoot(),
    BananaModule.registerAsync({
      imports: [ConfigModule],
      useFactory: async (configService: ConfigService) => ({
        someValue: configService.get<string>('SOME_VALUE'),
        anotherValue: 'static config',
      }),
      inject: [ConfigService],
    }),
  ],
  // ...
})

Most of the boilerplate code is in the *.module.ts file. The main part you will need to modify is the options and options interface that get passed into .register() and .registerAsync().

You should not need to modify createAsyncProviders() or .createAsyncProviders() as they are private internally used methods to build the dynamic module.

2.0.0

2 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago