Commit 67ae5576 authored by leadream's avatar leadream

fix CamelCase issue

parent c8a580fd
...@@ -44,10 +44,11 @@ const generateIndex = () => { ...@@ -44,10 +44,11 @@ const generateIndex = () => {
} }
// generate attributes code // generate attributes code
const attrsToString = (attrs) => { const attrsToString = (attrs, style) => {
console.log(style)
return Object.keys(attrs).map((key) => { return Object.keys(attrs).map((key) => {
// should distinguish fill or stroke // 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] + '}'; return key + '={' + attrs[key] + '}';
} }
if (key === 'otherProps') { if (key === 'otherProps') {
...@@ -66,7 +67,7 @@ const generateIconCode = async ({name}) => { ...@@ -66,7 +67,7 @@ const generateIconCode = async ({name}) => {
const code = fs.readFileSync(location) const code = fs.readFileSync(location)
const svgCode = await processSvg(code) const svgCode = await processSvg(code)
const ComponentName = names.componentName 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({ const component = format({
text: element, text: element,
eslintConfig: { eslintConfig: {
......
...@@ -50,8 +50,8 @@ async function processSvg(svg) { ...@@ -50,8 +50,8 @@ async function processSvg(svg) {
// remove semicolon inserted by prettier // remove semicolon inserted by prettier
// because prettier thinks it's formatting JSX not HTML // because prettier thinks it's formatting JSX not HTML
.then(svg => svg.replace(/;/g, '')) .then(svg => svg.replace(/;/g, ''))
.then(svg => svg.replace(/([a-z]+)-([a-z]+)=/g, (_, a, b) => `${a}${CamelCase(b)}=`))
.then(removeSVGElement) .then(removeSVGElement)
.then(svg => svg.replace(/([a-z]+)-([a-z]+)=/g, (_, a, b) => `${a}${CamelCase(b)}=`))
return optimized; return optimized;
} }
......
...@@ -10,6 +10,7 @@ const getAttrs = (style) => { ...@@ -10,6 +10,7 @@ const getAttrs = (style) => {
otherProps: '...otherProps' otherProps: '...otherProps'
} }
const strokeAttrs = { const strokeAttrs = {
fill: 'none',
stroke: 'color', stroke: 'color',
strokeWidth: 2, strokeWidth: 2,
strokeLinecap: 'round', strokeLinecap: 'round',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment