From 67ae55765266a7933cbbf9dcd5c476fc5f555edb Mon Sep 17 00:00:00 2001 From: leadream Date: Thu, 7 Nov 2019 20:38:38 +0800 Subject: [PATCH] fix CamelCase issue --- bin/build.js | 7 ++++--- bin/processSvg.js | 2 +- bin/template.js | 1 + 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/bin/build.js b/bin/build.js index a3a845025..4cb61cd05 100644 --- a/bin/build.js +++ b/bin/build.js @@ -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') { @@ -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: { diff --git a/bin/processSvg.js b/bin/processSvg.js index 44ae5f938..8ae7734f4 100644 --- a/bin/processSvg.js +++ b/bin/processSvg.js @@ -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; } diff --git a/bin/template.js b/bin/template.js index 3ed689762..ea0d21d37 100644 --- a/bin/template.js +++ b/bin/template.js @@ -10,6 +10,7 @@ const getAttrs = (style) => { otherProps: '...otherProps' } const strokeAttrs = { + fill: 'none', stroke: 'color', strokeWidth: 2, strokeLinecap: 'round',