-
-
Notifications
You must be signed in to change notification settings - Fork 379
feat: directory namespaces support #8
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
Conversation
Change "dirs" to "include_dirs" (easier to understand) Add Namespaces as array filled with strings Add allowFolderNames as boolean
Fix `dirs` to `include_dirs`
Add Split, Join and isEmpty Helpers Update getNameFromFilePath to support new Features: Namespacing and allowFolderNames Fix Windows Issue with "index-named" components
Adjust new Options (dirs -> include_dirs) Call new Options within getNameFromFilePath
Oh and small Editnote: |
Thanks and the feature is good to have! I will have a closer look next Monday, before that, can you revert the formatting changes first? I would like to use 2 spaces for indentation and no semi. Thanks. |
Sure will do! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good but a few naming things.
I will pull down to test out when we made these changes.
Thanks!
README.md
Outdated
ViteComponents() | ||
] | ||
} | ||
plugins: [ViteComponents()], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you revet formatting change in this file? Thanks.
src/types.ts
Outdated
@@ -6,22 +6,40 @@ export interface Options { | |||
* Relative paths to the directory to search for components. | |||
* @default 'src/components' | |||
*/ | |||
dirs: string | string[] | |||
include_dirs: string | string[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
include_dirs: string | string[] | |
dirs: string | string[] |
It's better to not introduce a breaking change. And I think it's ok to call it dirs
for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you thought about the one Feature that i didnt had time to figure out?
exclude_dirs
, thats basically the only reason why i swapped this to include_dirs
, other then that i agree!
Atm it would be breaking, but if the exclude feature isnt available for now, i would leave it at dirs
!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, maybe we can just expose inlcudeGlobs
& excludeGlobs
later on to it so users can have better controls on this.
src/types.ts
Outdated
* @default false | ||
*/ | ||
|
||
allowFolderNames: boolean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not very share about the naming. But allow
something does not sounds good to an optional feature. Maybe:
- folderToPrefix
- folderNamespace
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah right, both options i didnt like!
folderNamespace would be good
src/types.ts
Outdated
* Only works if Foldernames are allowed | ||
* @default "['global', 'partials']" | ||
*/ | ||
namespaces: string[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
namespaces
might be too general for this feature. Maybe
- globalNamespaces
- globalPrefixes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
globalNamespaces sounds better here!
src/utils.ts
Outdated
export function split(str: string, sep: string) { | ||
return str == '' ? [] : str.split(sep) | ||
} | ||
|
||
export function join(arr: string[], sep: string) { | ||
return arr == null ? '' : Array.prototype.join.call(arr, sep) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not necessarily, just added them for convience, made the code a little bit more readable
test/fixture/src/App.vue
Outdated
{ label: 'First Level' }, | ||
{ label: 'First Level', children: [{ label: 'Second Level' }] }, | ||
{ label: "First Level" }, | ||
{ label: "First Level", children: [{ label: "Second Level" }] }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert the formating, thanks!
src/utils.ts
Outdated
@@ -28,17 +44,51 @@ export function matchGlobs(filepath: string, globs: string[]) { | |||
return false | |||
} | |||
|
|||
export function getNameFromFilePath(filePath: string): string { | |||
export function getNameFromFilePath(filePath: string, includedFrom: string | string[], allowFolderNames: boolean, namespaces: string[]): string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can pass the entire options here
export function getNameFromFilePath(filePath: string, includedFrom: string | string[], allowFolderNames: boolean, namespaces: string[]): string { | |
export function getNameFromFilePath(filePath: string, options: Options): string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right! Completely oversaw that 👍
A few changes:
Thanks for your work! |
Hello there,
so ive created a smaller Pull Request that basically implements some Features that i had in my own
vite-autoloader
.Due to it not beeing in Typescript ive converted all Features that were missing now over to this Plugin!
Features:
Allow Folder Names ( boolean )
This is just a simple Idea, if you for example got the following Folder Structure:
Components within these Subfolders would be generated like the following:
book.vue
,uiButton.vue
,layoutContent.vue
,transitionFade.vue
This allows Users to have Componentnames based on their Foldestructure.
Namespacing ( array with strings )
An Additional Feature to the first one: the user can allow specific Foldernames to be ignored within their Folderstructure:
This would result in the components beeing named as:
avatar.vue
,listItem.vue
Include_dirs and exclude_dirs ( array with strings )
Pretty Simple, ive just changed
dirs
toinclude_dirs
to make it more recognizable.I wanted to allow the Options also to
exclude_dirs
. This would mean that a User could ignore certain Folders within theinclude_dirs
from getting autoloaded.Unfortunately i didnt had the time to implement this in the current Repo, but i will try to add it later on!
Bugs:
Currently there is only one Bug existent which is, if a component is loaded its name will
normalize
fromcontext.ts
.Ends up with:
Uibutton.vue
rather thenuiButton.vue
. I could change this behavior fromnormalize
tokebabCase
, but this would enforce a specific Loadingstyle. It would be great if a component could be loaded no matter how it is written:ui-button.vue
,uiButton.vue
,Uibutton.vue
,UiButton.vue
etcBut due to my Typescript beeing a littly rusty i couldnt find a quick Solution that didnt break everything! I also fixed one Issue that
index-named
components were not loaded properly if they got their parent directory name.Last but not least: I dont like the current
allowFolderNames
Option, so if someone finds a better name for it, feel free to change it! and please verify if this works onMACOS
andLinux
, because i am currently limited toWindows 10 64Bit
.Greetings,
Subwaytime