Skip to content

Commit

Permalink
fix: use hyphenate instead of kebabCase (fixes #165)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Mar 11, 2021
1 parent f396cfa commit 3de27ff
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/scan.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { basename, extname, join, dirname, relative } from 'upath'
import globby from 'globby'
import { kebabCase, pascalCase, splitByCase } from 'scule'
import { pascalCase, splitByCase } from 'scule'
import type { ScanDir, Component } from './types'

export function sortDirsByPathLength ({ path: pathA }: ScanDir, { path: pathB }: ScanDir): number {
return pathB.split(/[\\/]/).filter(Boolean).length - pathA.split(/[\\/]/).filter(Boolean).length
}

// vue@2 src/shared/util.js
function hyphenate (str: string):string {
return str.replace(/\B([A-Z])/g, '-$1').toLowerCase()
}

export async function scanComponents (dirs: ScanDir[], srcDir: string): Promise<Component[]> {
const components: Component[] = []
const filePaths = new Set<string>()
Expand Down Expand Up @@ -54,7 +59,7 @@ export async function scanComponents (dirs: ScanDir[], srcDir: string): Promise<
resolvedNames.set(componentName, filePath)

const pascalName = pascalCase(componentName)
const kebabName = kebabCase(componentName)
const kebabName = hyphenate(componentName)
const shortPath = relative(srcDir, filePath)
const chunkName = 'components/' + kebabName

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion test/fixture/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<IconHome />
<MAwesome />
<Functional />
<PAScal />
<NComponent />
</div>
</template>
2 changes: 1 addition & 1 deletion test/unit/scanner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test('scanner', async () => {
'Bar',
'Big',
'Mouse',
'PAScal',
'NComponent',
'Foo',
'Functional',
'FunctionalChild',
Expand Down
2 changes: 1 addition & 1 deletion test/unit/tagExtractor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { extractTags } from '../../src/tagExtractor'
test('with template', async () => {
const tags = await extractTags(path.resolve('test/fixture/pages/index.vue'))

expect(tags).toEqual(['Header', 'Foo', 'LazyBar', 'BaseButton', 'IconHome', 'MAwesome', 'Functional', 'PAScal', 'div'])
expect(tags).toEqual(['Header', 'Foo', 'LazyBar', 'BaseButton', 'IconHome', 'MAwesome', 'Functional', 'NComponent', 'div'])
})

test('without template', async () => {
Expand Down

0 comments on commit 3de27ff

Please sign in to comment.