Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support aliases for renamed icons #35

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading