benawad / destiny

Prettier for File Structures
MIT License
3.53k stars 81 forks source link

collapse top level index folder #151

Open benawad opened 4 years ago

benawad commented 4 years ago

its weird to have a folder called index so just bring up all the files in it one level

AnatoleLucet commented 4 years ago

From this:

src/
├── index
│   ├── header
│   │   └── button.ts
│   └── header.ts
└── index.ts

to this:

src/
├── header
│   └── button.ts
├── header.ts
└── index.ts

?

I mean, why not. But I think we must implement this under a config option / cli flag and not make it the default.

benawad commented 4 years ago

But I think we must implement this under a config option / cli flag and not make it the default.

How come?

AnatoleLucet commented 4 years ago

In a single entry point folder (like our src folder on Destiny's codebase) why not, but I'd be the chaos on a multiple entry points folder. For example, when using Destiny on sub folders of src this approach may not fit since each folder have multiple entry points (e.g. a components folder).

AnatoleLucet commented 4 years ago

I think Destiny should be able to run on any kind of js / js-like codebase without any issue and then be configurable to suit the user's preferences

benawad commented 4 years ago

How does it break down for multiple entry points?

AnatoleLucet commented 4 years ago

Current output:

components/
├── header
│   ├── wrapper
│   │   └── uniqueButton.js
│   └── wrapper.js
├── footer
│   ├── links
│   │   └── link.js
│   └── links.js
├── header.js
└── footer.js

Your proposal output:

components/
├── wrapper
│   └── uniqueButton.js
├── links
│   └── link.js
├── wrapper.js
├── links.js
├── header.js
└── footer.js

How can you find out which file is dependent on whom? Also, what if both footer.js and header.js has a deps with the same name e.g. layout.js (not a shared deps, just the same file name). We'd need to rename these two files so they can be in the same folder.

benawad commented 4 years ago

What do you think of collapsing it only if the folders name is index?

AnatoleLucet commented 4 years ago

I'm not sure. Some apps name their entry point main.js, app.js, server.js, etc... I don't know if it's a good idea to do something specific based on a file's name (except for ignoring folders / files like node_modules or something). I still think we should do this as a flag / config option. We may need something like a destiny init to ask this kind of questions though.

AnatoleLucet commented 4 years ago

Or else, we can detect if there's one single file at top level. It seems pretty obvious but it didn't click until now...

src/
├── [name]
└── [name].*

Then why not. But with this, I think we should also give an option to the user so he can disable this feature if he wants to.

But I'm not sure how we'll deal with shared deps. Shall we do this only if there's no shared folder at top level, or merge it with the one that will be moved to top? If we merge them, what about duplicated files name? Shall we throw a warning that we can't bring everything to top level because two files have the same name? Or maybe we can rename one of the two?

benawad commented 4 years ago

that's a good point, I think merging is probably the right choice, but I'll think on this.