Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create combined index.ts when outputToNestJsResourceStructure and reExport are set to true #22

Closed
gwesterman opened this issue Jun 1, 2023 · 6 comments

Comments

@gwesterman
Copy link

When setting both outputToNestJsResourceStructure and reExport to true, no index.ts is created that re-exports from the individual dto and entity folders.

Perhaps a third option could be added to enable this behavior.

@Brakebein
Copy link
Owner

I can't reproduce this issue. Can you please share all your config?

@gwesterman
Copy link
Author

generator nestjsDto {
  provider                        = "prisma-generator-nestjs-dto"
  output                          = "../../libs/api/models/generated"
  outputToNestJsResourceStructure = "true"
  reExport                        = "true"
  flatResourceStructure           = "false"
  exportRelationModifierClasses   = "true"
  createDtoPrefix                 = "Create"
  updateDtoPrefix                 = "Update"
  dtoSuffix                       = "Dto"
  entityPrefix                    = ""
  entitySuffix                    = ""
  classValidation                 = "true"
  fileNamingStyle                 = "kebab"
  noDependencies                  = "false"
  outputType                      = "class"
  definiteAssignmentAssertion     = "true"
  prettier                        = "true"
}

This will generate the following structure:

.
├── ...
├── generated
│   ├── model1 
│   │   ├── dto
│   │   │   ├── ..
│   │   │   └── index.ts
│   │   └── entity
│   │       ├── ..
│   │       └── index.ts
│   ├── model2
│   │   ├── dto
│   │   │   ├── ..
│   │   │   └── index.ts
│   │   └── entity
│   │       ├── ..
│   │       └── index.ts
│   └── ...
└── ...

There is a barrel index.ts for every dto and entity folder, but there are no barrel in the parent folders that re-export them. This is a something that I currently have to maintain manually in the root level generated.

If I set the configuration to the following:

generator nestjsDto {
 ...
  outputToNestJsResourceStructure = "false"
  flatResourceStructure           = "true"
  reExport                        = "true"
 ...
}

I get this folder structure, where every file, including a barrel index.ts is contained within a single root folder.

.
├── ...
├── generated
│   ├── connect-model1 .dto.ts
│   ├── connect-model1 .entity.ts
│   ├── create-model1 .dto.ts
│   ├── create-model1 .entity.ts
│   ├── model1.dto.ts
│   ├── model1.entity.ts
│   ├── model2.dto.ts
│   ├── model2.entity.ts
│   ├── update-model1 .dto.ts
│   ├── update-model1 .entity.ts
│   ├── index..ts
│   └── ...
└── ...

This is quite messy but allows me to export everything from a single barrel index.ts, which is quite useful.

I would like to have the following folder structure:

.
├── ...
├── generated
│   ├── model1 
│   │   ├── dto
│   │   │   ├── ..
│   │   │   └── index.ts
│   │   ├── entity
│   │   │   ├── ..
│   │   │   └── index.ts
│   │   └── index.ts
│   ├── model1 
│   │   ├── dto
│   │   │   ├── ..
│   │   │   └── index.ts
│   │   ├── entity
│   │   │   ├── ..
│   │   │   └── index.ts
│   │   └── index.ts
│   ├── index.ts
│   └── ...
└── ...

Here generated/index.ts exports everything from generated/model1/index.ts and generated/model2/index.ts

while generated/model1/index.ts exports everything from generated/model1/dto/index.ts and generated/model1/entity/index.ts.

and generated/model2/index.ts exports everything from generated/model2/dto/index.ts and generated/model2/entity/index.ts.

This allows me to re-export everything from a single barrel index.ts on the root level but also keep the models separate from each other in, keeping things a little more tidy.

@Brakebein
Copy link
Owner

What about setting all 3 options to true?

generator nestjsDto {
 ...
  outputToNestJsResourceStructure = "true"
  flatResourceStructure           = "true"
  reExport                        = "true"
 ...
}

It would generate a structure like below having model1 and model2 separated, but model1.dto.ts and model1.entity.ts are in the same folder with a common index.ts:

.
├── ...
├── generated
│   ├── model1 
│   │   ├─ model1.dto.ts
│   │   ├─ model1.entity.ts
│   │   ├─ create-model1.dto.ts
│   │   ├─ ...
│   │   └─ index.ts
│   ├── model2
│   │   ├─ model2.dto.ts
│   │   ├─ model2.entity.ts
│   │   ├─ create-model2.dto.ts
│   │   ├─ ...
│   │   └─ index.ts
│   └── ...
└── ...

@gwesterman
Copy link
Author

This would still require maintaining a barrel file on the root level manually. It's the smallest of inconveniences, I just wanted to put it out there ;-)

@Brakebein
Copy link
Owner

Ah, I missed the last index.ts in the generated folder in your example.

@Brakebein
Copy link
Owner

I added a combined index.ts in the root output folder. Please checkout https://www.npmjs.com/package/@brakebein/prisma-generator-nestjs-dto/v/1.18.0-beta4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants