Skip to content

Commit d3e09fb

Browse files
committed
refactor: the exported filename uses the hump style
1 parent 586f340 commit d3e09fb

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/generate.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import fetch from 'node-fetch'
22
import { JSDOM } from 'jsdom'
33
import fs from 'fs-extra'
44
import { transform } from '@babel/core'
5-
import { moduleBabelConfig, allModulesBabelConfig, replaceAll } from './utils'
5+
import {
6+
moduleBabelConfig, allModulesBabelConfig, replaceAll,
7+
toHumpName, toComponentName,
8+
} from './utils'
69

710
const sourceFile = `${__dirname}/../.source`
811

@@ -29,8 +32,8 @@ type Icon = React.FunctionComponent<Props>;\n`
2932
const icons = document.querySelectorAll('.geist-list .icon')
3033
const promises = Array.from(icons).map((icon: Element) => {
3134
const name: string = icon.querySelector('.geist-text').textContent
32-
const componentName =
33-
name.slice(0, 1).toUpperCase() + name.slice(1).replace(/-(.)/g, (g) => g[1].toUpperCase())
35+
const componentName = toComponentName(name)
36+
const fileName = toHumpName(name)
3437

3538
const svg = icon.querySelector('svg')
3639
const styles = parseStyles(svg.getAttribute('style'))
@@ -43,11 +46,11 @@ const ${componentName} = ({ color, size, ...props }) => {
4346
}
4447
export default ${componentName};`
4548

46-
exports += `export { default as ${componentName} } from './${componentName}';\n`
49+
exports += `export { default as ${componentName} } from './${fileName}';\n`
4750
definition += `export const ${componentName}: Icon;\n`
4851

4952
return fs.outputFile(
50-
`${__dirname}/../dist/${componentName}.js`,
53+
`${__dirname}/../dist/${fileName}.js`,
5154
transform(component, moduleBabelConfig).code
5255
)
5356
})

src/utils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,14 @@ export const replaceAll = (
1717
return target.split(find).join(replace)
1818
}
1919

20+
export const toHumpName = (name: string): string => {
21+
return name.replace(/-(.)/g, (g) => g[1].toUpperCase())
22+
}
23+
24+
export const toComponentName = (name: string): string => {
25+
const first = name.slice(0, 1).toUpperCase()
26+
const last = toHumpName(name.slice(1))
27+
return `${first}${last}`
28+
}
29+
30+

0 commit comments

Comments
 (0)