Skip to content

Commit

Permalink
feat: support aliases for renamed icons (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
amje authored Oct 30, 2023
1 parent 562db07 commit 78bf5e5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
3 changes: 3 additions & 0 deletions scripts/aliases.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'layout-side-content-left': 'layout-side-content',
};
20 changes: 13 additions & 7 deletions scripts/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const figmaExport = require('@figma-export/core');
const svgo = require('svgo');
const {SVGS_DIR, ICON_NAME_REGEXP} = require('./constants');
const {cleanDir, getComponentName} = require('./utils');
const aliases = require('./aliases');

const FIGMA_TOKEN = process.env.FIGMA_TOKEN;
const FIGMA_FILE = process.env.FIGMA_FILE;
Expand Down Expand Up @@ -51,29 +52,34 @@ function createSvgBuilder(metadata) {
for (const icon of iconSet.children) {
const props = parsePropertiesString(icon.name);
const svg = iconsById[icon.id].svg;
let name = iconSet.name;
const name = iconSet.name;
let svgName = name;
let keywords = [];

if (!props.style) {
throw new Error(`Icon has no style: ${iconSet.name}`);
throw new Error(`Icon has no style: ${name}`);
}

if (props.style !== 'regular') {
name += `-${props.style}`;
svgName += `-${props.style}`;
}

if (props.keywords && props.keywords !== EMPTY_KEYWORDS_STRING) {
keywords = props.keywords.split(' ');
}

metadata.icons.push({
name: iconSet.name,
name,
style: props.style,
svgName: name,
componentName: getComponentName(name),
svgName,
componentName: getComponentName(svgName),
keywords,
});
await fs.writeFile(path.join(SVGS_DIR, `${name}.svg`), svg);
await fs.writeFile(path.join(SVGS_DIR, `${svgName}.svg`), svg);
}

if (aliases[iconSet.name]) {
iconSets.push({...iconSet, name: aliases[iconSet.name]});
}
}
};
Expand Down

0 comments on commit 78bf5e5

Please sign in to comment.