Commit 67ae5576 authored by leadream's avatar leadream

fix CamelCase issue

parent c8a580fd
......@@ -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: {
......
......@@ -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;
}
......
......@@ -10,6 +10,7 @@ const getAttrs = (style) => {
otherProps: '...otherProps'
}
const strokeAttrs = {
fill: 'none',
stroke: 'color',
strokeWidth: 2,
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