Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ function hyphenate (str: string):string {
return str.replace(/\B([A-Z])/g, '-$1').toLowerCase()
}

function compareCaseInsensitive (str1 = '', str2 = '') {
return str1.toLocaleLowerCase() === str2.toLocaleLowerCase()
}

export async function scanComponents (dirs: ScanDir[], srcDir: string): Promise<Component[]> {
const components: Component[] = []
const filePaths = new Set<string>()
Expand All @@ -38,15 +42,13 @@ export async function scanComponents (dirs: ScanDir[], srcDir: string): Promise<
const fileName = basename(filePath, extname(filePath))
const fileNameParts = fileName.toLowerCase() === 'index' ? [] : splitByCase(fileName)

const componentNameParts: string[] = []

while (prefixParts.length &&
(prefixParts[0] || '').toLowerCase() !== (fileNameParts[0] || '').toLowerCase()
) {
componentNameParts.push(prefixParts.shift()!)
for (const p of prefixParts) {
if (compareCaseInsensitive(p, fileNameParts[0])) {
fileNameParts.shift()
}
}

const componentName = pascalCase(componentNameParts) + pascalCase(fileNameParts)
const componentName = pascalCase(prefixParts) + pascalCase(fileNameParts)

if (resolvedNames.has(componentName)) {
// eslint-disable-next-line no-console
Expand Down
3 changes: 3 additions & 0 deletions test/fixture/components/my/form/MyFancyButton.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<div>MyFancyButton</div>
</template>
5 changes: 3 additions & 2 deletions test/unit/scanner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ test('scanner', async () => {
'FormInputText',
'FormInputTextArea',
'FormInputRadio',
'FormLayout',
'FormLayoutsLayout',
'Header',
'DeepNestedMyComponent',
'UiNotificationWrapper'
'UiNotificationWrapper',
'MyFormFancyButton'
]

expect(components.map(c => c.pascalName).sort()).toEqual(expectedComponents.sort())
Expand Down