Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eklemen/dynamod
Generate NestJS dynamic module boilerplate via cli
https://github.com/eklemen/dynamod
Last synced: about 2 months ago
JSON representation
Generate NestJS dynamic module boilerplate via cli
- Host: GitHub
- URL: https://github.com/eklemen/dynamod
- Owner: eklemen
- License: mit
- Created: 2021-08-17T19:22:41.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-04-17T03:24:02.000Z (over 2 years ago)
- Last Synced: 2024-04-25T15:02:59.506Z (8 months ago)
- Language: JavaScript
- Size: 103 KB
- Stars: 6
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dynamod
Generate boilerplate for [NestJS dynamic modules](https://docs.nestjs.com/fundamentals/dynamic-modules#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.](#usage-within-an-existing-nestjs-project)
[2. Generate a standalone package that you can build and publish to npm or use within your monorepo.](#usage-as-package)
### Usage within an existing NestJS project
```shell
# within /my-cool-project
npx dynamod## example
npx dynamod banana
```
**NOTE: this will place the directory within `./src`**#### Output
```shell
./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.```shell
mkdir examplemod
cd examplemodnpx dynamod examplemod --package
# or
npx dynamod examplemod -p
```#### Output
```shell
./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
| Config | Flag | Output |
|--------|------|--------|
| Scaffold as standalone package| --package
-p | Generate 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
```typescript
@Module({
// ...
imports: [
ConfigModule.forRoot(),
BananaModule.registerAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => ({
someValue: configService.get('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.