Skip to content

Commit 3a8296a

Browse files
committed
update scan for desired behavior
1 parent 89944c4 commit 3a8296a

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/scan.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ function hyphenate (str: string):string {
1212
return str.replace(/\B([A-Z])/g, '-$1').toLowerCase()
1313
}
1414

15+
function compareCaseInsensitive (str1 = '', str2 = '') {
16+
return str1.toLocaleLowerCase() === str2.toLocaleLowerCase()
17+
}
18+
1519
export async function scanComponents (dirs: ScanDir[], srcDir: string): Promise<Component[]> {
1620
const components: Component[] = []
1721
const filePaths = new Set<string>()
@@ -38,15 +42,13 @@ export async function scanComponents (dirs: ScanDir[], srcDir: string): Promise<
3842
const fileName = basename(filePath, extname(filePath))
3943
const fileNameParts = fileName.toLowerCase() === 'index' ? [] : splitByCase(fileName)
4044

41-
const componentNameParts: string[] = []
42-
43-
while (prefixParts.length &&
44-
(prefixParts[0] || '').toLowerCase() !== (fileNameParts[0] || '').toLowerCase()
45-
) {
46-
componentNameParts.push(prefixParts.shift()!)
45+
for (const p of prefixParts) {
46+
if (compareCaseInsensitive(p, fileNameParts[0])) {
47+
fileNameParts.shift()
48+
}
4749
}
4850

49-
const componentName = pascalCase(componentNameParts) + pascalCase(fileNameParts)
51+
const componentName = pascalCase(prefixParts) + pascalCase(fileNameParts)
5052

5153
if (resolvedNames.has(componentName)) {
5254
// eslint-disable-next-line no-console

test/unit/scanner.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ test('scanner', async () => {
1818
'FormInputText',
1919
'FormInputTextArea',
2020
'FormInputRadio',
21-
'FormLayout',
21+
'FormLayoutsLayout',
2222
'Header',
2323
'DeepNestedMyComponent',
2424
'UiNotificationWrapper',
25-
'MyFancyButton'
25+
'MyFormFancyButton'
2626
]
2727

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

0 commit comments

Comments
 (0)