nestforge-generator 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +371 -0
- package/README.pt-BR.md +370 -0
- package/dist/features/auth-strategy.js +19 -0
- package/dist/features/auth-strategy.js.map +1 -0
- package/dist/features/database.js +59 -0
- package/dist/features/database.js.map +1 -0
- package/dist/features/dependencies.js +57 -0
- package/dist/features/dependencies.js.map +1 -0
- package/dist/features/language.js +172 -0
- package/dist/features/language.js.map +1 -0
- package/dist/features/markers.js +116 -0
- package/dist/features/markers.js.map +1 -0
- package/dist/generator.js +120 -0
- package/dist/generator.js.map +1 -0
- package/dist/index.js +59 -0
- package/dist/index.js.map +1 -0
- package/dist/prompts.js +137 -0
- package/dist/prompts.js.map +1 -0
- package/package.json +76 -0
- package/templates/drizzle/.env.example +45 -0
- package/templates/drizzle/.env.test +38 -0
- package/templates/drizzle/.github/workflows/ci.yml +119 -0
- package/templates/drizzle/ARCHITECTURE.md +227 -0
- package/templates/drizzle/ARCHITECTURE.pt-BR.md +225 -0
- package/templates/drizzle/CODE_OF_CONDUCT.md +29 -0
- package/templates/drizzle/CODE_OF_CONDUCT.pt-BR.md +27 -0
- package/templates/drizzle/CONTRIBUTING.md +57 -0
- package/templates/drizzle/CONTRIBUTING.pt-BR.md +54 -0
- package/templates/drizzle/Dockerfile +43 -0
- package/templates/drizzle/LICENSE +21 -0
- package/templates/drizzle/README.md +257 -0
- package/templates/drizzle/README.pt-BR.md +257 -0
- package/templates/drizzle/ROADMAP.md +143 -0
- package/templates/drizzle/ROADMAP.pt-BR.md +143 -0
- package/templates/drizzle/TESTING.md +136 -0
- package/templates/drizzle/TESTING.pt-BR.md +136 -0
- package/templates/drizzle/docker-compose.yml +82 -0
- package/templates/drizzle/docs/adding-a-module.md +585 -0
- package/templates/drizzle/docs/features-markers.md +457 -0
- package/templates/drizzle/drizzle.config.ts +49 -0
- package/templates/drizzle/nest-cli.json +8 -0
- package/templates/drizzle/package.json +96 -0
- package/templates/drizzle/src/app.module.ts +72 -0
- package/templates/drizzle/src/auth/auth.controller.ts +283 -0
- package/templates/drizzle/src/auth/auth.module.ts +81 -0
- package/templates/drizzle/src/auth/auth.service.spec.ts +111 -0
- package/templates/drizzle/src/auth/auth.service.ts +631 -0
- package/templates/drizzle/src/auth/drizzle-session.store.ts +263 -0
- package/templates/drizzle/src/auth/dto/forgot-password.dto.ts +9 -0
- package/templates/drizzle/src/auth/dto/login.dto.ts +10 -0
- package/templates/drizzle/src/auth/dto/refresh-token.dto.ts +9 -0
- package/templates/drizzle/src/auth/dto/register.dto.ts +11 -0
- package/templates/drizzle/src/auth/dto/reset-password.dto.ts +10 -0
- package/templates/drizzle/src/auth/guards/github-auth.guard.ts +10 -0
- package/templates/drizzle/src/auth/guards/google-auth.guard.ts +10 -0
- package/templates/drizzle/src/auth/guards/jwt-auth.guard.ts +25 -0
- package/templates/drizzle/src/auth/guards/session-auth.guard.spec.ts +77 -0
- package/templates/drizzle/src/auth/guards/session-auth.guard.ts +37 -0
- package/templates/drizzle/src/auth/session.service.spec.ts +74 -0
- package/templates/drizzle/src/auth/session.service.ts +96 -0
- package/templates/drizzle/src/auth/strategies/github.strategy.ts +41 -0
- package/templates/drizzle/src/auth/strategies/google.strategy.ts +43 -0
- package/templates/drizzle/src/auth/strategies/jwt.strategy.ts +25 -0
- package/templates/drizzle/src/auth/token.service.ts +175 -0
- package/templates/drizzle/src/common/constants/permissions.ts +8 -0
- package/templates/drizzle/src/common/constants/role-permissions.ts +9 -0
- package/templates/drizzle/src/common/constants/role.enum.ts +5 -0
- package/templates/drizzle/src/common/decorators/current-user.decorator.ts +8 -0
- package/templates/drizzle/src/common/decorators/permissions.decorator.ts +7 -0
- package/templates/drizzle/src/common/decorators/public.decorator.ts +4 -0
- package/templates/drizzle/src/common/decorators/roles.decorator.ts +6 -0
- package/templates/drizzle/src/common/filters/http-exception.filter.ts +34 -0
- package/templates/drizzle/src/common/guards/permissions.guard.spec.ts +54 -0
- package/templates/drizzle/src/common/guards/permissions.guard.ts +28 -0
- package/templates/drizzle/src/common/guards/roles.guard.spec.ts +37 -0
- package/templates/drizzle/src/common/guards/roles.guard.ts +24 -0
- package/templates/drizzle/src/common/interceptors/logging.interceptor.ts +23 -0
- package/templates/drizzle/src/common/middleware/csrf.middleware.spec.ts +97 -0
- package/templates/drizzle/src/common/middleware/csrf.middleware.ts +46 -0
- package/templates/drizzle/src/common/utils/avatar-storage.util.ts +32 -0
- package/templates/drizzle/src/common/utils/hash.util.ts +5 -0
- package/templates/drizzle/src/config/env.validation.ts +50 -0
- package/templates/drizzle/src/database/database-lifecycle.service.ts +30 -0
- package/templates/drizzle/src/database/database.constants.ts +2 -0
- package/templates/drizzle/src/database/database.decorators.ts +5 -0
- package/templates/drizzle/src/database/database.module.ts +96 -0
- package/templates/drizzle/src/database/database.types.ts +28 -0
- package/templates/drizzle/src/database/schema/index.ts +11 -0
- package/templates/drizzle/src/database/schema/mysql.schema.ts +215 -0
- package/templates/drizzle/src/database/schema/postgres.schema.ts +218 -0
- package/templates/drizzle/src/database/schema/sqlite.schema.ts +190 -0
- package/templates/drizzle/src/database/seed.ts +152 -0
- package/templates/drizzle/src/health/health.controller.ts +49 -0
- package/templates/drizzle/src/health/health.module.ts +19 -0
- package/templates/drizzle/src/health/indicators/drizzle-health.indicator.spec.ts +71 -0
- package/templates/drizzle/src/health/indicators/drizzle-health.indicator.ts +52 -0
- package/templates/drizzle/src/health/indicators/redis-health.indicator.spec.ts +54 -0
- package/templates/drizzle/src/health/indicators/redis-health.indicator.ts +33 -0
- package/templates/drizzle/src/mail/mail.module.ts +12 -0
- package/templates/drizzle/src/mail/mail.processor.ts +48 -0
- package/templates/drizzle/src/mail/mail.service.ts +24 -0
- package/templates/drizzle/src/mail/templates/email-templates.ts +28 -0
- package/templates/drizzle/src/main.ts +145 -0
- package/templates/drizzle/src/metrics/metrics.controller.ts +22 -0
- package/templates/drizzle/src/metrics/metrics.interceptor.ts +30 -0
- package/templates/drizzle/src/metrics/metrics.module.ts +12 -0
- package/templates/drizzle/src/metrics/metrics.service.ts +34 -0
- package/templates/drizzle/src/types/express-session.d.ts +13 -0
- package/templates/drizzle/src/users/dto/create-user.dto.ts +12 -0
- package/templates/drizzle/src/users/dto/find-users-query.dto.ts +12 -0
- package/templates/drizzle/src/users/dto/update-user.dto.ts +6 -0
- package/templates/drizzle/src/users/entities/user.entity.ts +23 -0
- package/templates/drizzle/src/users/users.controller.ts +165 -0
- package/templates/drizzle/src/users/users.module.ts +10 -0
- package/templates/drizzle/src/users/users.service.spec.ts +301 -0
- package/templates/drizzle/src/users/users.service.ts +213 -0
- package/templates/drizzle/test/auth.e2e-spec.ts +114 -0
- package/templates/drizzle/test/session-auth.e2e-spec.ts +163 -0
- package/templates/drizzle/test/users.e2e-spec.ts +212 -0
- package/templates/drizzle/test/utils/clean-database.ts +104 -0
- package/templates/drizzle/test/utils/e2e-setup.ts +77 -0
- package/templates/drizzle/tsconfig.build.json +4 -0
- package/templates/drizzle/tsconfig.json +25 -0
- package/templates/drizzle/vitest.config.ts +20 -0
- package/templates/drizzle/vitest.e2e.config.ts +19 -0
- package/templates/prisma/.env.example +44 -0
- package/templates/prisma/.env.test +37 -0
- package/templates/prisma/.github/workflows/ci.yml +109 -0
- package/templates/prisma/ARCHITECTURE.md +70 -0
- package/templates/prisma/ARCHITECTURE.pt-BR.md +63 -0
- package/templates/prisma/CODE_OF_CONDUCT.md +29 -0
- package/templates/prisma/CODE_OF_CONDUCT.pt-BR.md +27 -0
- package/templates/prisma/CONTRIBUTING.md +57 -0
- package/templates/prisma/CONTRIBUTING.pt-BR.md +54 -0
- package/templates/prisma/Dockerfile +33 -0
- package/templates/prisma/LICENSE +21 -0
- package/templates/prisma/README.md +267 -0
- package/templates/prisma/README.pt-BR.md +267 -0
- package/templates/prisma/ROADMAP.md +75 -0
- package/templates/prisma/ROADMAP.pt-BR.md +65 -0
- package/templates/prisma/TESTING.md +123 -0
- package/templates/prisma/TESTING.pt-BR.md +123 -0
- package/templates/prisma/docker-compose.yml +78 -0
- package/templates/prisma/docs/adding-a-module.md +230 -0
- package/templates/prisma/docs/features-markers.md +50 -0
- package/templates/prisma/nest-cli.json +8 -0
- package/templates/prisma/package.json +95 -0
- package/templates/prisma/prisma/schema.prisma +105 -0
- package/templates/prisma/prisma/seed.ts +46 -0
- package/templates/prisma/src/app.module.ts +72 -0
- package/templates/prisma/src/auth/auth.controller.ts +283 -0
- package/templates/prisma/src/auth/auth.module.ts +59 -0
- package/templates/prisma/src/auth/auth.service.spec.ts +53 -0
- package/templates/prisma/src/auth/auth.service.ts +224 -0
- package/templates/prisma/src/auth/dto/forgot-password.dto.ts +9 -0
- package/templates/prisma/src/auth/dto/login.dto.ts +10 -0
- package/templates/prisma/src/auth/dto/refresh-token.dto.ts +9 -0
- package/templates/prisma/src/auth/dto/register.dto.ts +11 -0
- package/templates/prisma/src/auth/dto/reset-password.dto.ts +10 -0
- package/templates/prisma/src/auth/guards/github-auth.guard.ts +10 -0
- package/templates/prisma/src/auth/guards/google-auth.guard.ts +10 -0
- package/templates/prisma/src/auth/guards/jwt-auth.guard.ts +25 -0
- package/templates/prisma/src/auth/guards/session-auth.guard.spec.ts +77 -0
- package/templates/prisma/src/auth/guards/session-auth.guard.ts +37 -0
- package/templates/prisma/src/auth/session.service.spec.ts +74 -0
- package/templates/prisma/src/auth/session.service.ts +96 -0
- package/templates/prisma/src/auth/strategies/github.strategy.ts +41 -0
- package/templates/prisma/src/auth/strategies/google.strategy.ts +43 -0
- package/templates/prisma/src/auth/strategies/jwt.strategy.ts +25 -0
- package/templates/prisma/src/auth/token.service.ts +84 -0
- package/templates/prisma/src/common/constants/permissions.ts +8 -0
- package/templates/prisma/src/common/constants/role-permissions.ts +9 -0
- package/templates/prisma/src/common/decorators/current-user.decorator.ts +8 -0
- package/templates/prisma/src/common/decorators/permissions.decorator.ts +7 -0
- package/templates/prisma/src/common/decorators/public.decorator.ts +4 -0
- package/templates/prisma/src/common/decorators/roles.decorator.ts +6 -0
- package/templates/prisma/src/common/filters/http-exception.filter.ts +34 -0
- package/templates/prisma/src/common/guards/permissions.guard.spec.ts +54 -0
- package/templates/prisma/src/common/guards/permissions.guard.ts +28 -0
- package/templates/prisma/src/common/guards/roles.guard.spec.ts +37 -0
- package/templates/prisma/src/common/guards/roles.guard.ts +24 -0
- package/templates/prisma/src/common/interceptors/logging.interceptor.ts +23 -0
- package/templates/prisma/src/common/middleware/csrf.middleware.spec.ts +97 -0
- package/templates/prisma/src/common/middleware/csrf.middleware.ts +46 -0
- package/templates/prisma/src/common/utils/avatar-storage.util.ts +32 -0
- package/templates/prisma/src/common/utils/hash.util.ts +5 -0
- package/templates/prisma/src/config/env.validation.ts +49 -0
- package/templates/prisma/src/database/prisma.module.ts +9 -0
- package/templates/prisma/src/database/prisma.service.ts +13 -0
- package/templates/prisma/src/health/health.controller.ts +49 -0
- package/templates/prisma/src/health/health.module.ts +19 -0
- package/templates/prisma/src/health/indicators/prisma-health.indicator.spec.ts +22 -0
- package/templates/prisma/src/health/indicators/prisma-health.indicator.ts +19 -0
- package/templates/prisma/src/health/indicators/redis-health.indicator.spec.ts +54 -0
- package/templates/prisma/src/health/indicators/redis-health.indicator.ts +33 -0
- package/templates/prisma/src/mail/mail.module.ts +12 -0
- package/templates/prisma/src/mail/mail.processor.ts +48 -0
- package/templates/prisma/src/mail/mail.service.ts +24 -0
- package/templates/prisma/src/mail/templates/email-templates.ts +28 -0
- package/templates/prisma/src/main.ts +92 -0
- package/templates/prisma/src/metrics/metrics.controller.ts +22 -0
- package/templates/prisma/src/metrics/metrics.interceptor.ts +30 -0
- package/templates/prisma/src/metrics/metrics.module.ts +12 -0
- package/templates/prisma/src/metrics/metrics.service.ts +34 -0
- package/templates/prisma/src/types/express-session.d.ts +13 -0
- package/templates/prisma/src/users/dto/create-user.dto.ts +12 -0
- package/templates/prisma/src/users/dto/find-users-query.dto.ts +12 -0
- package/templates/prisma/src/users/dto/update-user.dto.ts +6 -0
- package/templates/prisma/src/users/entities/user.entity.ts +20 -0
- package/templates/prisma/src/users/users.controller.ts +165 -0
- package/templates/prisma/src/users/users.module.ts +10 -0
- package/templates/prisma/src/users/users.service.spec.ts +104 -0
- package/templates/prisma/src/users/users.service.ts +114 -0
- package/templates/prisma/test/auth.e2e-spec.ts +75 -0
- package/templates/prisma/test/session-auth.e2e-spec.ts +163 -0
- package/templates/prisma/test/users.e2e-spec.ts +106 -0
- package/templates/prisma/test/utils/clean-database.ts +14 -0
- package/templates/prisma/test/utils/e2e-setup.ts +58 -0
- package/templates/prisma/tsconfig.build.json +4 -0
- package/templates/prisma/tsconfig.json +25 -0
- package/templates/prisma/vitest.config.ts +20 -0
- package/templates/prisma/vitest.e2e.config.ts +19 -0
- package/templates/typeorm/.env.example +45 -0
- package/templates/typeorm/.env.test +38 -0
- package/templates/typeorm/.github/workflows/ci.yml +116 -0
- package/templates/typeorm/ARCHITECTURE.md +158 -0
- package/templates/typeorm/ARCHITECTURE.pt-BR.md +156 -0
- package/templates/typeorm/CODE_OF_CONDUCT.md +29 -0
- package/templates/typeorm/CODE_OF_CONDUCT.pt-BR.md +27 -0
- package/templates/typeorm/CONTRIBUTING.md +57 -0
- package/templates/typeorm/CONTRIBUTING.pt-BR.md +54 -0
- package/templates/typeorm/Dockerfile +43 -0
- package/templates/typeorm/LICENSE +21 -0
- package/templates/typeorm/README.md +266 -0
- package/templates/typeorm/README.pt-BR.md +266 -0
- package/templates/typeorm/ROADMAP.md +79 -0
- package/templates/typeorm/ROADMAP.pt-BR.md +67 -0
- package/templates/typeorm/TESTING.md +114 -0
- package/templates/typeorm/TESTING.pt-BR.md +114 -0
- package/templates/typeorm/docker-compose.yml +78 -0
- package/templates/typeorm/docs/adding-a-module.md +369 -0
- package/templates/typeorm/docs/features-markers.md +50 -0
- package/templates/typeorm/nest-cli.json +8 -0
- package/templates/typeorm/package.json +98 -0
- package/templates/typeorm/src/app.module.ts +72 -0
- package/templates/typeorm/src/auth/auth.controller.ts +283 -0
- package/templates/typeorm/src/auth/auth.module.ts +86 -0
- package/templates/typeorm/src/auth/auth.service.spec.ts +111 -0
- package/templates/typeorm/src/auth/auth.service.ts +346 -0
- package/templates/typeorm/src/auth/dto/forgot-password.dto.ts +9 -0
- package/templates/typeorm/src/auth/dto/login.dto.ts +10 -0
- package/templates/typeorm/src/auth/dto/refresh-token.dto.ts +9 -0
- package/templates/typeorm/src/auth/dto/register.dto.ts +11 -0
- package/templates/typeorm/src/auth/dto/reset-password.dto.ts +10 -0
- package/templates/typeorm/src/auth/entities/email-verification-token.entity.ts +69 -0
- package/templates/typeorm/src/auth/entities/oauth-account.entity.ts +50 -0
- package/templates/typeorm/src/auth/entities/password-reset-token.entity.ts +69 -0
- package/templates/typeorm/src/auth/entities/refresh-token.entity.ts +69 -0
- package/templates/typeorm/src/auth/entities/session.entity.ts +50 -0
- package/templates/typeorm/src/auth/guards/github-auth.guard.ts +10 -0
- package/templates/typeorm/src/auth/guards/google-auth.guard.ts +10 -0
- package/templates/typeorm/src/auth/guards/jwt-auth.guard.ts +25 -0
- package/templates/typeorm/src/auth/guards/session-auth.guard.spec.ts +77 -0
- package/templates/typeorm/src/auth/guards/session-auth.guard.ts +37 -0
- package/templates/typeorm/src/auth/session.service.spec.ts +74 -0
- package/templates/typeorm/src/auth/session.service.ts +96 -0
- package/templates/typeorm/src/auth/strategies/github.strategy.ts +41 -0
- package/templates/typeorm/src/auth/strategies/google.strategy.ts +43 -0
- package/templates/typeorm/src/auth/strategies/jwt.strategy.ts +25 -0
- package/templates/typeorm/src/auth/token.service.ts +115 -0
- package/templates/typeorm/src/common/constants/permissions.ts +8 -0
- package/templates/typeorm/src/common/constants/role-permissions.ts +9 -0
- package/templates/typeorm/src/common/constants/role.enum.ts +5 -0
- package/templates/typeorm/src/common/decorators/current-user.decorator.ts +8 -0
- package/templates/typeorm/src/common/decorators/permissions.decorator.ts +7 -0
- package/templates/typeorm/src/common/decorators/public.decorator.ts +4 -0
- package/templates/typeorm/src/common/decorators/roles.decorator.ts +6 -0
- package/templates/typeorm/src/common/filters/http-exception.filter.ts +34 -0
- package/templates/typeorm/src/common/guards/permissions.guard.spec.ts +54 -0
- package/templates/typeorm/src/common/guards/permissions.guard.ts +28 -0
- package/templates/typeorm/src/common/guards/roles.guard.spec.ts +37 -0
- package/templates/typeorm/src/common/guards/roles.guard.ts +24 -0
- package/templates/typeorm/src/common/interceptors/logging.interceptor.ts +23 -0
- package/templates/typeorm/src/common/middleware/csrf.middleware.spec.ts +97 -0
- package/templates/typeorm/src/common/middleware/csrf.middleware.ts +46 -0
- package/templates/typeorm/src/common/utils/avatar-storage.util.ts +32 -0
- package/templates/typeorm/src/common/utils/hash.util.ts +5 -0
- package/templates/typeorm/src/config/env.validation.ts +50 -0
- package/templates/typeorm/src/database/data-source.ts +20 -0
- package/templates/typeorm/src/database/database.module.ts +39 -0
- package/templates/typeorm/src/database/seed.ts +81 -0
- package/templates/typeorm/src/database/typeorm-options.ts +49 -0
- package/templates/typeorm/src/health/health.controller.ts +49 -0
- package/templates/typeorm/src/health/health.module.ts +19 -0
- package/templates/typeorm/src/health/indicators/redis-health.indicator.spec.ts +54 -0
- package/templates/typeorm/src/health/indicators/redis-health.indicator.ts +33 -0
- package/templates/typeorm/src/health/indicators/typeorm-health.indicator.spec.ts +49 -0
- package/templates/typeorm/src/health/indicators/typeorm-health.indicator.ts +37 -0
- package/templates/typeorm/src/mail/mail.module.ts +12 -0
- package/templates/typeorm/src/mail/mail.processor.ts +48 -0
- package/templates/typeorm/src/mail/mail.service.ts +24 -0
- package/templates/typeorm/src/mail/templates/email-templates.ts +28 -0
- package/templates/typeorm/src/main.ts +107 -0
- package/templates/typeorm/src/metrics/metrics.controller.ts +22 -0
- package/templates/typeorm/src/metrics/metrics.interceptor.ts +30 -0
- package/templates/typeorm/src/metrics/metrics.module.ts +12 -0
- package/templates/typeorm/src/metrics/metrics.service.ts +34 -0
- package/templates/typeorm/src/types/express-session.d.ts +13 -0
- package/templates/typeorm/src/users/dto/create-user.dto.ts +12 -0
- package/templates/typeorm/src/users/dto/find-users-query.dto.ts +12 -0
- package/templates/typeorm/src/users/dto/update-user.dto.ts +6 -0
- package/templates/typeorm/src/users/entities/user.entity.ts +113 -0
- package/templates/typeorm/src/users/users.controller.ts +165 -0
- package/templates/typeorm/src/users/users.module.ts +13 -0
- package/templates/typeorm/src/users/users.service.spec.ts +183 -0
- package/templates/typeorm/src/users/users.service.ts +124 -0
- package/templates/typeorm/test/auth.e2e-spec.ts +111 -0
- package/templates/typeorm/test/session-auth.e2e-spec.ts +159 -0
- package/templates/typeorm/test/users.e2e-spec.ts +183 -0
- package/templates/typeorm/test/utils/clean-database.ts +65 -0
- package/templates/typeorm/test/utils/e2e-setup.ts +77 -0
- package/templates/typeorm/tsconfig.build.json +4 -0
- package/templates/typeorm/tsconfig.json +25 -0
- package/templates/typeorm/vitest.config.ts +20 -0
- package/templates/typeorm/vitest.e2e.config.ts +19 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# Testing the Prisma template
|
|
2
|
+
|
|
3
|
+
**English** | [Português](TESTING.pt-BR.md)
|
|
4
|
+
|
|
5
|
+
This guide validates a project generated from the NestForge Prisma template.
|
|
6
|
+
|
|
7
|
+
## Prerequisites
|
|
8
|
+
|
|
9
|
+
* Node.js 20 or later
|
|
10
|
+
* npm 10 or later
|
|
11
|
+
* Docker when testing PostgreSQL, MySQL, Redis, or Mailpit
|
|
12
|
+
|
|
13
|
+
SQLite can be tested without Docker.
|
|
14
|
+
|
|
15
|
+
## Prepare the environment
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install
|
|
19
|
+
cp .env.example .env
|
|
20
|
+
cp .env.example .env.test
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Use different databases in `.env` and `.env.test`. Never run E2E tests against the development or production database.
|
|
24
|
+
|
|
25
|
+
Generate Prisma Client:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm run prisma:generate
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Apply the development schema
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm run prisma:migrate -- --name init
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Run the seed when the generated project includes password authentication:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm run prisma:seed
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Static validation
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
npm run build
|
|
47
|
+
npm run lint
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Unit tests
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
npm test
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
For coverage:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
npm run test:cov
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Unit tests mock Prisma and Redis, so they do not require real services.
|
|
63
|
+
|
|
64
|
+
## E2E tests
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
npm run test:e2e
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
The `pretest:e2e` script runs `prisma migrate deploy` with `.env.test` before the suite starts.
|
|
71
|
+
|
|
72
|
+
Depending on the generated authentication strategy, the suite may cover:
|
|
73
|
+
|
|
74
|
+
* registration and login;
|
|
75
|
+
* refresh token rotation and logout;
|
|
76
|
+
* Session/Cookies and CSRF;
|
|
77
|
+
* user CRUD;
|
|
78
|
+
* RBAC and permissions.
|
|
79
|
+
|
|
80
|
+
## Database-specific checks
|
|
81
|
+
|
|
82
|
+
### PostgreSQL
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
docker compose up -d postgres
|
|
86
|
+
npm run prisma:migrate -- --name init
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### MySQL
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
docker compose up -d mysql
|
|
93
|
+
npm run prisma:migrate -- --name init
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### SQLite
|
|
97
|
+
|
|
98
|
+
Set the database URL to a local file:
|
|
99
|
+
|
|
100
|
+
```dotenv
|
|
101
|
+
DATABASE_URL="file:./dev.db"
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Then run:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
npm run prisma:migrate -- --name init
|
|
108
|
+
npm run build
|
|
109
|
+
npm test
|
|
110
|
+
npm run test:e2e
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Final checklist
|
|
114
|
+
|
|
115
|
+
* [ ] Dependencies install successfully
|
|
116
|
+
* [ ] Prisma Client is generated
|
|
117
|
+
* [ ] Migrations are applied
|
|
118
|
+
* [ ] Seed runs when applicable
|
|
119
|
+
* [ ] Build passes
|
|
120
|
+
* [ ] Lint passes
|
|
121
|
+
* [ ] Unit tests pass
|
|
122
|
+
* [ ] E2E tests pass
|
|
123
|
+
* [ ] `.env.test` uses an isolated database
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# Testando o template Prisma
|
|
2
|
+
|
|
3
|
+
[English](TESTING.md) | **Português**
|
|
4
|
+
|
|
5
|
+
Este guia valida um projeto gerado a partir do template Prisma do NestForge.
|
|
6
|
+
|
|
7
|
+
## Pré-requisitos
|
|
8
|
+
|
|
9
|
+
* Node.js 20 ou superior
|
|
10
|
+
* npm 10 ou superior
|
|
11
|
+
* Docker para testar PostgreSQL, MySQL, Redis ou Mailpit
|
|
12
|
+
|
|
13
|
+
SQLite pode ser testado sem Docker.
|
|
14
|
+
|
|
15
|
+
## Preparar o ambiente
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install
|
|
19
|
+
cp .env.example .env
|
|
20
|
+
cp .env.example .env.test
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Use bancos diferentes em `.env` e `.env.test`. Nunca execute testes E2E no banco de desenvolvimento ou produção.
|
|
24
|
+
|
|
25
|
+
Gere o Prisma Client:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm run prisma:generate
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Aplicar o schema de desenvolvimento
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm run prisma:migrate -- --name init
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Execute o seed quando o projeto gerado incluir autenticação por senha:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm run prisma:seed
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Validação estática
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
npm run build
|
|
47
|
+
npm run lint
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Testes unitários
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
npm test
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Para cobertura:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
npm run test:cov
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Os testes unitários simulam Prisma e Redis, portanto não exigem serviços reais.
|
|
63
|
+
|
|
64
|
+
## Testes E2E
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
npm run test:e2e
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
O script `pretest:e2e` executa `prisma migrate deploy` com `.env.test` antes do início da suíte.
|
|
71
|
+
|
|
72
|
+
Dependendo da estratégia de autenticação gerada, a suíte pode cobrir:
|
|
73
|
+
|
|
74
|
+
* cadastro e login;
|
|
75
|
+
* rotação de refresh token e logout;
|
|
76
|
+
* Session/Cookies e CSRF;
|
|
77
|
+
* CRUD de usuários;
|
|
78
|
+
* RBAC e permissions.
|
|
79
|
+
|
|
80
|
+
## Verificações específicas por banco
|
|
81
|
+
|
|
82
|
+
### PostgreSQL
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
docker compose up -d postgres
|
|
86
|
+
npm run prisma:migrate -- --name init
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### MySQL
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
docker compose up -d mysql
|
|
93
|
+
npm run prisma:migrate -- --name init
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### SQLite
|
|
97
|
+
|
|
98
|
+
Defina a URL do banco como um arquivo local:
|
|
99
|
+
|
|
100
|
+
```dotenv
|
|
101
|
+
DATABASE_URL="file:./dev.db"
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Depois execute:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
npm run prisma:migrate -- --name init
|
|
108
|
+
npm run build
|
|
109
|
+
npm test
|
|
110
|
+
npm run test:e2e
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Checklist final
|
|
114
|
+
|
|
115
|
+
* [ ] As dependências são instaladas corretamente
|
|
116
|
+
* [ ] O Prisma Client é gerado
|
|
117
|
+
* [ ] As migrations são aplicadas
|
|
118
|
+
* [ ] O seed executa quando aplicável
|
|
119
|
+
* [ ] O build passa
|
|
120
|
+
* [ ] O lint passa
|
|
121
|
+
* [ ] Os testes unitários passam
|
|
122
|
+
* [ ] Os testes E2E passam
|
|
123
|
+
* [ ] `.env.test` usa um banco isolado
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
version: "3.9"
|
|
2
|
+
|
|
3
|
+
services:
|
|
4
|
+
api:
|
|
5
|
+
build:
|
|
6
|
+
context: .
|
|
7
|
+
dockerfile: Dockerfile
|
|
8
|
+
container_name: nestforge-api
|
|
9
|
+
ports:
|
|
10
|
+
- "3000:3000"
|
|
11
|
+
env_file:
|
|
12
|
+
- .env
|
|
13
|
+
depends_on:
|
|
14
|
+
# nestforge:feature:database:postgres
|
|
15
|
+
- postgres
|
|
16
|
+
# nestforge:feature:database:postgres:end
|
|
17
|
+
# nestforge:feature:database:mysql
|
|
18
|
+
- mysql
|
|
19
|
+
# nestforge:feature:database:mysql:end
|
|
20
|
+
- redis
|
|
21
|
+
volumes:
|
|
22
|
+
- ./src:/app/src
|
|
23
|
+
command: npm run start:dev
|
|
24
|
+
|
|
25
|
+
# nestforge:feature:database:postgres
|
|
26
|
+
postgres:
|
|
27
|
+
image: postgres:16-alpine
|
|
28
|
+
container_name: nestforge-postgres
|
|
29
|
+
restart: unless-stopped
|
|
30
|
+
environment:
|
|
31
|
+
POSTGRES_USER: nestforge
|
|
32
|
+
POSTGRES_PASSWORD: nestforge
|
|
33
|
+
POSTGRES_DB: nestforge
|
|
34
|
+
ports:
|
|
35
|
+
- "5432:5432"
|
|
36
|
+
volumes:
|
|
37
|
+
- postgres_data:/var/lib/postgresql/data
|
|
38
|
+
# nestforge:feature:database:postgres:end
|
|
39
|
+
|
|
40
|
+
# nestforge:feature:database:mysql
|
|
41
|
+
mysql:
|
|
42
|
+
image: mysql:8
|
|
43
|
+
container_name: nestforge-mysql
|
|
44
|
+
restart: unless-stopped
|
|
45
|
+
environment:
|
|
46
|
+
MYSQL_USER: nestforge
|
|
47
|
+
MYSQL_PASSWORD: nestforge
|
|
48
|
+
MYSQL_ROOT_PASSWORD: nestforge
|
|
49
|
+
MYSQL_DATABASE: nestforge
|
|
50
|
+
ports:
|
|
51
|
+
- "3306:3306"
|
|
52
|
+
volumes:
|
|
53
|
+
- mysql_data:/var/lib/mysql
|
|
54
|
+
# nestforge:feature:database:mysql:end
|
|
55
|
+
|
|
56
|
+
redis:
|
|
57
|
+
image: redis:7-alpine
|
|
58
|
+
container_name: nestforge-redis
|
|
59
|
+
restart: unless-stopped
|
|
60
|
+
ports:
|
|
61
|
+
- "6379:6379"
|
|
62
|
+
|
|
63
|
+
mailpit:
|
|
64
|
+
image: axllent/mailpit:latest
|
|
65
|
+
container_name: nestforge-mailpit
|
|
66
|
+
restart: unless-stopped
|
|
67
|
+
ports:
|
|
68
|
+
- "8025:8025" # UI
|
|
69
|
+
- "1025:1025" # SMTP
|
|
70
|
+
|
|
71
|
+
# nestforge:feature:database:postgres
|
|
72
|
+
volumes:
|
|
73
|
+
postgres_data:
|
|
74
|
+
# nestforge:feature:database:postgres:end
|
|
75
|
+
# nestforge:feature:database:mysql
|
|
76
|
+
volumes:
|
|
77
|
+
mysql_data:
|
|
78
|
+
# nestforge:feature:database:mysql:end
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
# Como adicionar um novo módulo
|
|
2
|
+
|
|
3
|
+
Este guia mostra o passo a passo pra adicionar um recurso novo seguindo as convenções do NestForge, usando um módulo `posts` (posts de blog) como exemplo. Adapte os nomes pro seu caso.
|
|
4
|
+
|
|
5
|
+
## 1. Adicione o model no Prisma
|
|
6
|
+
|
|
7
|
+
Em `prisma/schema.prisma`:
|
|
8
|
+
|
|
9
|
+
```prisma
|
|
10
|
+
model Post {
|
|
11
|
+
id String @id @default(uuid())
|
|
12
|
+
title String
|
|
13
|
+
content String
|
|
14
|
+
authorId String
|
|
15
|
+
author User @relation(fields: [authorId], references: [id], onDelete: Cascade)
|
|
16
|
+
createdAt DateTime @default(now())
|
|
17
|
+
updatedAt DateTime @updatedAt
|
|
18
|
+
|
|
19
|
+
@@map("posts")
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Não esqueça de adicionar a relação inversa no `model User`:
|
|
24
|
+
|
|
25
|
+
```prisma
|
|
26
|
+
posts Post[]
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Gere a migration:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npx prisma migrate dev --name add_posts
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## 2. Crie a estrutura de pastas
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
src/posts/
|
|
39
|
+
├── dto/
|
|
40
|
+
│ ├── create-post.dto.ts
|
|
41
|
+
│ └── update-post.dto.ts
|
|
42
|
+
├── entities/
|
|
43
|
+
│ └── post.entity.ts
|
|
44
|
+
├── posts.controller.ts
|
|
45
|
+
├── posts.service.ts
|
|
46
|
+
└── posts.module.ts
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## 3. DTOs com Zod
|
|
50
|
+
|
|
51
|
+
`src/posts/dto/create-post.dto.ts`:
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import { z } from 'zod';
|
|
55
|
+
import { createZodDto } from 'nestjs-zod';
|
|
56
|
+
|
|
57
|
+
export const createPostSchema = z.object({
|
|
58
|
+
title: z.string().min(3).describe('Título do post'),
|
|
59
|
+
content: z.string().min(10).describe('Conteúdo do post'),
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
export class CreatePostDto extends createZodDto(createPostSchema) {}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
`src/posts/dto/update-post.dto.ts`:
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
import { createZodDto } from 'nestjs-zod';
|
|
69
|
+
import { createPostSchema } from './create-post.dto';
|
|
70
|
+
|
|
71
|
+
export const updatePostSchema = createPostSchema.partial();
|
|
72
|
+
|
|
73
|
+
export class UpdatePostDto extends createZodDto(updatePostSchema) {}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## 4. Entity (o que a API expõe)
|
|
77
|
+
|
|
78
|
+
`src/posts/entities/post.entity.ts` — mesmo se não houver nada sensível pra esconder agora, criar a entity já deixa o padrão pronto pra quando houver:
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
export class PostEntity {
|
|
82
|
+
id: string;
|
|
83
|
+
title: string;
|
|
84
|
+
content: string;
|
|
85
|
+
authorId: string;
|
|
86
|
+
createdAt: Date;
|
|
87
|
+
updatedAt: Date;
|
|
88
|
+
|
|
89
|
+
constructor(partial: Partial<PostEntity>) {
|
|
90
|
+
Object.assign(this, partial);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## 5. Service (regra de negócio)
|
|
96
|
+
|
|
97
|
+
`src/posts/posts.service.ts`:
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
import { Injectable, NotFoundException } from '@nestjs/common';
|
|
101
|
+
import { PrismaService } from '../database/prisma.service';
|
|
102
|
+
import { CreatePostDto } from './dto/create-post.dto';
|
|
103
|
+
import { UpdatePostDto } from './dto/update-post.dto';
|
|
104
|
+
import { PostEntity } from './entities/post.entity';
|
|
105
|
+
|
|
106
|
+
@Injectable()
|
|
107
|
+
export class PostsService {
|
|
108
|
+
constructor(private readonly prisma: PrismaService) {}
|
|
109
|
+
|
|
110
|
+
async create(authorId: string, dto: CreatePostDto) {
|
|
111
|
+
const post = await this.prisma.post.create({ data: { ...dto, authorId } });
|
|
112
|
+
return new PostEntity(post);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async findOne(id: string) {
|
|
116
|
+
const post = await this.prisma.post.findUnique({ where: { id } });
|
|
117
|
+
if (!post) throw new NotFoundException('Post não encontrado');
|
|
118
|
+
return new PostEntity(post);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async update(id: string, dto: UpdatePostDto) {
|
|
122
|
+
await this.findOne(id);
|
|
123
|
+
const post = await this.prisma.post.update({ where: { id }, data: dto });
|
|
124
|
+
return new PostEntity(post);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async remove(id: string) {
|
|
128
|
+
await this.findOne(id);
|
|
129
|
+
await this.prisma.post.delete({ where: { id } });
|
|
130
|
+
return { message: 'Post removido com sucesso' };
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## 6. Controller (guards + permissions)
|
|
136
|
+
|
|
137
|
+
Se o recurso precisa de controle de acesso, adicione a permission em `src/common/constants/permissions.ts` e no mapeamento `src/common/constants/role-permissions.ts` antes de usar:
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
// permissions.ts
|
|
141
|
+
export enum Permission {
|
|
142
|
+
// ...existentes
|
|
143
|
+
PostCreate = 'post:create',
|
|
144
|
+
PostDelete = 'post:delete',
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
`src/posts/posts.controller.ts`:
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
import { Body, Controller, Delete, Get, Param, Patch, Post } from '@nestjs/common';
|
|
152
|
+
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
|
153
|
+
import { PostsService } from './posts.service';
|
|
154
|
+
import { CreatePostDto } from './dto/create-post.dto';
|
|
155
|
+
import { UpdatePostDto } from './dto/update-post.dto';
|
|
156
|
+
import { Permissions } from '../common/decorators/permissions.decorator';
|
|
157
|
+
import { Permission } from '../common/constants/permissions';
|
|
158
|
+
import { CurrentUser } from '../common/decorators/current-user.decorator';
|
|
159
|
+
|
|
160
|
+
@ApiTags('posts')
|
|
161
|
+
@ApiBearerAuth()
|
|
162
|
+
@Controller('posts')
|
|
163
|
+
export class PostsController {
|
|
164
|
+
constructor(private readonly postsService: PostsService) {}
|
|
165
|
+
|
|
166
|
+
@Post()
|
|
167
|
+
@Permissions(Permission.PostCreate)
|
|
168
|
+
create(@CurrentUser() user: { id: string }, @Body() dto: CreatePostDto) {
|
|
169
|
+
return this.postsService.create(user.id, dto);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
@Get(':id')
|
|
173
|
+
findOne(@Param('id') id: string) {
|
|
174
|
+
return this.postsService.findOne(id);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
@Patch(':id')
|
|
178
|
+
update(@Param('id') id: string, @Body() dto: UpdatePostDto) {
|
|
179
|
+
return this.postsService.update(id, dto);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
@Delete(':id')
|
|
183
|
+
@Permissions(Permission.PostDelete)
|
|
184
|
+
remove(@Param('id') id: string) {
|
|
185
|
+
return this.postsService.remove(id);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## 7. Module
|
|
191
|
+
|
|
192
|
+
`src/posts/posts.module.ts`:
|
|
193
|
+
|
|
194
|
+
```ts
|
|
195
|
+
import { Module } from '@nestjs/common';
|
|
196
|
+
import { PostsService } from './posts.service';
|
|
197
|
+
import { PostsController } from './posts.controller';
|
|
198
|
+
|
|
199
|
+
@Module({
|
|
200
|
+
controllers: [PostsController],
|
|
201
|
+
providers: [PostsService],
|
|
202
|
+
exports: [PostsService],
|
|
203
|
+
})
|
|
204
|
+
export class PostsModule {}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Registre no `src/app.module.ts` (dentro do array `imports`):
|
|
208
|
+
|
|
209
|
+
```ts
|
|
210
|
+
import { PostsModule } from './posts/posts.module';
|
|
211
|
+
// ...
|
|
212
|
+
PostsModule,
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
## 8. Testes
|
|
216
|
+
|
|
217
|
+
- **Unitário** (`src/posts/posts.service.spec.ts`): mocke o `PrismaService` como em `src/users/users.service.spec.ts` — sem banco real.
|
|
218
|
+
- **E2e** (`test/posts.e2e-spec.ts`): use os helpers de `test/utils/e2e-setup.ts` e `test/utils/clean-database.ts` (adicione `prisma.post.deleteMany()` na limpeza) e siga o padrão de `test/users.e2e-spec.ts`.
|
|
219
|
+
|
|
220
|
+
## Checklist rápido
|
|
221
|
+
|
|
222
|
+
- [ ] Model no `schema.prisma` + migration
|
|
223
|
+
- [ ] DTOs com Zod (`createZodDto`)
|
|
224
|
+
- [ ] Entity (mesmo sem campo sensível ainda)
|
|
225
|
+
- [ ] Service sem lógica no controller
|
|
226
|
+
- [ ] Permissions novas cadastradas em `permissions.ts` e `role-permissions.ts`, se necessário
|
|
227
|
+
- [ ] Module registrado no `AppModule`
|
|
228
|
+
- [ ] Teste unitário do service
|
|
229
|
+
- [ ] Teste e2e do fluxo principal
|
|
230
|
+
- [ ] Atualizar `ROADMAP.md` se o módulo fechar um item do roadmap
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Marcadores de features (feature markers)
|
|
2
|
+
|
|
3
|
+
O `templates/prisma` é usado tanto como projeto standalone quanto como fonte pra CLI (`packages/cli`) gerar projetos. Quando um recurso é **opcional** na CLI (ex: Swagger, Redis, RBAC), o código dele precisa ficar marcado no template, pra CLI saber o que remover quando o usuário responde "não" naquela pergunta.
|
|
4
|
+
|
|
5
|
+
Se você está adicionando código ligado a um recurso que já existe como pergunta na CLI (ou propondo um recurso novo opcional), marque o trecho seguindo esta convenção.
|
|
6
|
+
|
|
7
|
+
## Marcador de bloco
|
|
8
|
+
|
|
9
|
+
Envolve um trecho de código (uma ou várias linhas) dentro de um arquivo que tem outras coisas não-opcionais também.
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
// nestforge:feature:swagger
|
|
13
|
+
@ApiTags('users')
|
|
14
|
+
// nestforge:feature:swagger:end
|
|
15
|
+
@Controller('users')
|
|
16
|
+
export class UsersController {
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
- Recurso **habilitado**: a CLI remove só as duas linhas de marcador, o `@ApiTags('users')` fica.
|
|
20
|
+
- Recurso **desabilitado**: a CLI remove o bloco inteiro (marcador + `@ApiTags('users')`).
|
|
21
|
+
|
|
22
|
+
O nome depois de `nestforge:feature:` tem que ser exatamente o mesmo nas duas linhas (abertura e `:end`), e bater com o nome usado no array `features` da CLI (`docker`, `swagger`, `validation`, `redis`, `rbac`).
|
|
23
|
+
|
|
24
|
+
Funciona em qualquer arquivo cuja linguagem use `//` para comentário (`.ts`, `.js`). **Não funciona em JSON** (`package.json`) — pra dependências, ver a seção final deste documento.
|
|
25
|
+
|
|
26
|
+
## Marcador de arquivo inteiro
|
|
27
|
+
|
|
28
|
+
Quando o arquivo **inteiro** só faz sentido se o recurso estiver ligado (ex: `src/mail/mail.service.ts`, que só existe por causa do Redis/BullMQ), marque a primeira linha do arquivo:
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
// nestforge:feature-file:redis
|
|
32
|
+
import { Injectable } from '@nestjs/common';
|
|
33
|
+
// ...resto do arquivo normalmente
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
- Recurso **habilitado**: a CLI remove só essa primeira linha, o resto do arquivo fica intacto.
|
|
37
|
+
- Recurso **desabilitado**: a CLI apaga o arquivo inteiro.
|
|
38
|
+
|
|
39
|
+
Se, depois de remover arquivos, uma pasta ficar vazia (ex: `src/mail/` inteira desapareceu), a CLI remove a pasta também — não precisa se preocupar em limpar pasta manualmente.
|
|
40
|
+
|
|
41
|
+
## Dependências no `package.json`
|
|
42
|
+
|
|
43
|
+
JSON não aceita comentário, então marcador não funciona ali. Em vez disso, o mapeamento fica direto no código da CLI: `packages/cli/src/features/dependencies.ts`, no objeto `FEATURE_DEPENDENCIES`. Se seu recurso opcional adiciona uma dependência nova ao `package.json` do template, adicione ela nesse mapa também.
|
|
44
|
+
|
|
45
|
+
## Checklist ao adicionar um recurso opcional novo
|
|
46
|
+
|
|
47
|
+
- [ ] Todo trecho de código exclusivo do recurso está marcado (bloco ou arquivo inteiro)
|
|
48
|
+
- [ ] O nome do marcador bate com o valor usado em `features` na CLI (`packages/cli/src/prompts.ts`)
|
|
49
|
+
- [ ] Dependências novas do `package.json` estão em `FEATURE_DEPENDENCIES` (`packages/cli/src/features/dependencies.ts`)
|
|
50
|
+
- [ ] Testado gerando o projeto com o recurso ligado **e** desligado — o projeto tem que compilar/rodar dos dois jeitos
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nestforge",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Production-ready NestJS starter with Prisma, Authentication, Docker, Testing, CI/CD and Clean Architecture.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Jeiel Alves <https://github.com/jeiel2013>",
|
|
7
|
+
"private": true,
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "nest build",
|
|
10
|
+
"start": "nest start",
|
|
11
|
+
"start:dev": "nest start --watch",
|
|
12
|
+
"start:debug": "nest start --debug --watch",
|
|
13
|
+
"start:prod": "node dist/main.js",
|
|
14
|
+
"lint": "eslint \"{src,test}/**/*.ts\" --fix",
|
|
15
|
+
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
16
|
+
"test": "vitest run",
|
|
17
|
+
"test:watch": "vitest",
|
|
18
|
+
"test:cov": "vitest run --coverage",
|
|
19
|
+
"pretest:e2e": "dotenv -e .env.test -- npx prisma migrate deploy",
|
|
20
|
+
"test:e2e": "dotenv -e .env.test -- vitest run --config ./vitest.e2e.config.ts",
|
|
21
|
+
"prisma:generate": "prisma generate",
|
|
22
|
+
"prisma:migrate": "prisma migrate dev",
|
|
23
|
+
"prisma:deploy": "prisma migrate deploy",
|
|
24
|
+
"prisma:seed": "prisma db seed",
|
|
25
|
+
"prisma:studio": "prisma studio"
|
|
26
|
+
},
|
|
27
|
+
"prisma": {
|
|
28
|
+
"seed": "ts-node prisma/seed.ts"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@nestjs/common": "^11.0.0",
|
|
32
|
+
"@nestjs/config": "^4.0.0",
|
|
33
|
+
"@nestjs/core": "^11.0.0",
|
|
34
|
+
"@nestjs/jwt": "^11.0.0",
|
|
35
|
+
"@nestjs/passport": "^11.0.0",
|
|
36
|
+
"@nestjs/platform-express": "^11.0.0",
|
|
37
|
+
"@nestjs/swagger": "^11.0.0",
|
|
38
|
+
"@nestjs/throttler": "^6.5.0",
|
|
39
|
+
"@nestjs/bullmq": "^11.0.0",
|
|
40
|
+
"@nestjs/terminus": "^11.0.0",
|
|
41
|
+
"@prisma/client": "^6.0.0",
|
|
42
|
+
"@quixo3/prisma-session-store": "^3.1.21",
|
|
43
|
+
"express-session": "^1.19.0",
|
|
44
|
+
"bullmq": "^5.0.0",
|
|
45
|
+
"bcryptjs": "^2.4.3",
|
|
46
|
+
"class-transformer": "^0.5.1",
|
|
47
|
+
"helmet": "^8.0.0",
|
|
48
|
+
"ioredis": "^5.4.1",
|
|
49
|
+
"multer": "^1.4.5-lts.1",
|
|
50
|
+
"nestjs-pino": "^4.1.0",
|
|
51
|
+
"nestjs-zod": "^3.0.0",
|
|
52
|
+
"nodemailer": "^6.9.15",
|
|
53
|
+
"passport": "^0.7.0",
|
|
54
|
+
"passport-jwt": "^4.0.1",
|
|
55
|
+
"passport-google-oauth20": "^2.0.0",
|
|
56
|
+
"passport-github2": "^0.1.12",
|
|
57
|
+
"pino-http": "^10.3.0",
|
|
58
|
+
"prom-client": "^15.1.3",
|
|
59
|
+
"reflect-metadata": "^0.2.2",
|
|
60
|
+
"rxjs": "^7.8.1",
|
|
61
|
+
"zod": "^3.23.8"
|
|
62
|
+
},
|
|
63
|
+
"devDependencies": {
|
|
64
|
+
"@nestjs/cli": "^11.0.0",
|
|
65
|
+
"@nestjs/schematics": "^11.0.0",
|
|
66
|
+
"@nestjs/testing": "^11.0.0",
|
|
67
|
+
"@types/bcryptjs": "^2.4.6",
|
|
68
|
+
"@types/express-session": "^1.19.0",
|
|
69
|
+
"@types/multer": "^1.4.12",
|
|
70
|
+
"@types/node": "^22.0.0",
|
|
71
|
+
"@types/nodemailer": "^6.4.16",
|
|
72
|
+
"@types/passport-jwt": "^4.0.1",
|
|
73
|
+
"@types/passport-google-oauth20": "^2.0.16",
|
|
74
|
+
"@types/passport-github2": "^1.2.9",
|
|
75
|
+
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
76
|
+
"@typescript-eslint/parser": "^8.0.0",
|
|
77
|
+
"@vitest/coverage-v8": "^2.1.0",
|
|
78
|
+
"@swc/core": "^1.13.0",
|
|
79
|
+
"unplugin-swc": "^1.5.10",
|
|
80
|
+
"eslint": "^9.0.0",
|
|
81
|
+
"eslint-config-prettier": "^9.1.0",
|
|
82
|
+
"pino-pretty": "^13.1.3",
|
|
83
|
+
"prettier": "^3.3.3",
|
|
84
|
+
"prisma": "^6.0.0",
|
|
85
|
+
"supertest": "^7.0.0",
|
|
86
|
+
"@types/supertest": "^6.0.2",
|
|
87
|
+
"dotenv-cli": "^7.4.2",
|
|
88
|
+
"ts-node": "^10.9.2",
|
|
89
|
+
"typescript": "^5.6.0",
|
|
90
|
+
"vitest": "^2.1.0"
|
|
91
|
+
},
|
|
92
|
+
"engines": {
|
|
93
|
+
"node": ">=20"
|
|
94
|
+
}
|
|
95
|
+
}
|