Skip to content

Commit

Permalink
Fix duplicated ids (#36)
Browse files Browse the repository at this point in the history
* feat: UFixes generated icons having duplicated ids

* Revert "feat: UFixes generated icons having duplicated ids (#35)"

This reverts commit 44999a8.

* feat: Fixes generated icons having duplicated ids
  • Loading branch information
amir-zahedi authored Aug 30, 2024
1 parent 44999a8 commit de9cef4
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 143 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"react-dom": "^17.0.1",
"rimraf": "^3.0.2",
"semantic-release": "^17.4.2",
"svgo": "^3.3.2",
"svgo": "^1.3.2",
"typescript": "~4.1.5"
},
"peerDependencies": {
Expand Down
32 changes: 24 additions & 8 deletions scripts/build.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { join, basename, relative } = require('path');
const dedent = require('dedent');
const globby = require('globby');
const svgo = require('svgo');
const SVGO = require('svgo');
const { dim, yellow, red, green } = require('kleur');
const { default: svgr } = require('@svgr/core');
const { pascalCase } = require('change-case');
Expand All @@ -12,6 +12,27 @@ const ROOT = join(__dirname, '..');

const destinationDir = join(ROOT, 'lib');

const svgo = new SVGO({
multipass: true,
plugins: [
{ minifyStyles: true },
{ sortAttrs: true },
{ mergePaths: true },
{ convertColors: true },
{ removeViewBox: false },
{
inlineStyles: {
onlyMatchedOnce: false,
},
},
{ convertStyleToAttrs: true },
{
removeAttrs: {
attrs: ['baseProfile'],
},
},
],
});

const svgrConfig = {
svgProps: { fill: 'currentColor', focusable: 'false' },
Expand Down Expand Up @@ -43,11 +64,7 @@ let hasError = false;
const library = await Promise.all(
iconsLibrary.map(async (iconPath) => {
const raw = await readFile(iconPath, 'utf8');
const optimizedSvg = (await svgo.optimize(raw, {
path: iconPath,
multipass: true,
cleanupIds: false,
})).data;
const optimizedSvg = (await svgo.optimize(raw)).data;

const iconName = `${pascalCase(basename(iconPath, '.svg'))}Icon`;
const outputFileName = join(destinationDir, `${iconName}.tsx`);
Expand Down Expand Up @@ -86,8 +103,7 @@ let hasError = false;
// Process files
const componentContents = (await svgr(optimizedSvg, svgrConfig, {
componentName: iconName,
}))
.replace(/id="([\dA-Za-z])"/g, (_, id) => `id="${id}-${iconName}"`)
})).replace(/id="([\dA-Za-z])"/g, (_, id) => `id="${id}-${iconName}"`)
.replace(/url\(#([\dA-Za-z]+)\)/g, (_, id) => `url(#${id}-${iconName})`);

// Create files
Expand Down
Loading

0 comments on commit de9cef4

Please sign in to comment.