Skip to content

Commit

Permalink
fix CamelCase issue
Browse files Browse the repository at this point in the history
  • Loading branch information
hallee9000 committed Nov 7, 2019
1 parent c8a580f commit 67ae557
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
7 changes: 4 additions & 3 deletions bin/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ const generateIndex = () => {
}

// generate attributes code
const attrsToString = (attrs) => {
const attrsToString = (attrs, style) => {
console.log(style)
return Object.keys(attrs).map((key) => {
// should distinguish fill or stroke
if (key === 'width' || key === 'height' || key === 'fill' || key === 'stroke') {
if (key === 'width' || key === 'height' || key === style) {
return key + '={' + attrs[key] + '}';
}
if (key === 'otherProps') {
Expand All @@ -66,7 +67,7 @@ const generateIconCode = async ({name}) => {
const code = fs.readFileSync(location)
const svgCode = await processSvg(code)
const ComponentName = names.componentName
const element = getElementCode(ComponentName, attrsToString(getAttrs(names.style)), svgCode)
const element = getElementCode(ComponentName, attrsToString(getAttrs(names.style), names.style), svgCode)
const component = format({
text: element,
eslintConfig: {
Expand Down
2 changes: 1 addition & 1 deletion bin/processSvg.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ async function processSvg(svg) {
// remove semicolon inserted by prettier
// because prettier thinks it's formatting JSX not HTML
.then(svg => svg.replace(/;/g, ''))
.then(svg => svg.replace(/([a-z]+)-([a-z]+)=/g, (_, a, b) => `${a}${CamelCase(b)}=`))
.then(removeSVGElement)
.then(svg => svg.replace(/([a-z]+)-([a-z]+)=/g, (_, a, b) => `${a}${CamelCase(b)}=`))
return optimized;
}

Expand Down
1 change: 1 addition & 0 deletions bin/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const getAttrs = (style) => {
otherProps: '...otherProps'
}
const strokeAttrs = {
fill: 'none',
stroke: 'color',
strokeWidth: 2,
strokeLinecap: 'round',
Expand Down

0 comments on commit 67ae557

Please sign in to comment.