mikededo / dartBarrelFileGenerator

VSCode extension that generates barrel files for Dart projects
MIT License
25 stars 9 forks source link

Option for putting generated file at the same level as target folder #75

Closed khwgit closed 1 year ago

khwgit commented 1 year ago

Could it be possible to have the generated file like this?

models\
  course.dart\
  user.dart\
models.dart\ <- The generated file which exports models/course.dart and models/user.dart

This structure can make the import paths look better.

import '../models.dart';
// or this if I only want the course model
import '../models/course.dart'

Btw this extension is really helpful to organise the files, especially in a big project. Nice work!

mikededo commented 1 year ago

Hi @drinkmorecola! Thanks for opening an issue 👋🏼!

There's the option GDBF: Current with subfolders. I have now seen that it is not documented in the readme!

Could you try it and see if it helps?

Thanks for the support!

mikededo commented 1 year ago

I'm closing the issue now as I'm not receiving any response! The option I have proposed it should produce the output you are looking for.

If there's any issue, reopen the issue!

khwgit commented 1 year ago

Sorry for late reply. That result is a bit different from what I’m expecting. The generated file is in the target folder (E.g. the path of generated file in the example is ../models/models.dart), but I want the path to be ../models.dart, which means the models.dart is out of the models folder. They should be at the same level.

mikededo commented 1 year ago

Just something that I do not understand from your example: course.dart and user.dart are files or folders? The / at the end makes it confusing as normally folders are ended with the dash.

The thing is that I don't understand how the files are structured. Can you use this tool to generate the file tree?

khwgit commented 1 year ago

🙈they are files. Here’s the correct example.

models/
  course.dart
  user.dart
models.dart
mikededo commented 1 year ago

So models.dart is outside the models/ folder?

khwgit commented 1 year ago

Yes that’s what I mean.

mikededo commented 1 year ago

Does the models folder have a parent component?

If so, you can do:

  1. In your settings, turn to true the dartBarrelFileGenerator.promptName. This will display an input when you are generating a barrel file.
  2. Right click the parent folder and generate for the current with subfolders.
  3. An input will show and ask you for a name. Enter the name you want (models in this case).

It should generate a barrel file outside the models/ folder with the models.dart name.

Would that help you?

khwgit commented 1 year ago

If there are more than one folders, for example

models/
  course.dart
  user.dart
services/
  service.dart

The generated models.dart will export files under services too, which is unexpected.

mikededo commented 1 year ago

Yes, it will. I'm planning on also adding a feature that would allow you to exclude folders. As of now this is not possible.

I'm sorry but what you are asking for it is really complex to do, and I'm currently not with enough time to do it. I also have the feeling that this is a really ad-hoc case, so I would need to find a solution for many specific cases, therefore implementing complexity in the code. 🙏🏼

Nonetheless, I would not recommend having barrel files outside the folder from they should be exported, as this breaks with the idea of why they exist.

I will close the issue but I will keep the idea in mind. Maybe if I have time enough I will try to find a solution...

khwgit commented 1 year ago

Really appreciate your patience!