Skip to content

Commit

Permalink
Replace 'iconPrefix' with 'getIconId' (output-components-as-svgstore)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomontalbano committed Jan 28, 2020
1 parent 8391b82 commit b46db83
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion packages/output-components-as-svg/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ module.exports = ({
}) => {
return async (pages) => {
pages.forEach(({ name: pageName, components }) => {
components.forEach(({ svg, figmaExport }) => {
components.forEach(({ name: componentName, svg, figmaExport }) => {
const options = {
pageName,
componentName,
...figmaExport,
};
const filePath = makeDir.sync(path.resolve(output, getDirname(options)));
Expand Down
12 changes: 9 additions & 3 deletions packages/output-components-as-svgstore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@ const svgstore = require('svgstore');

module.exports = ({
output,
iconPrefix = '',
getIconId = (options) => `${options.pageName}/${options.componentName}`,
options = {},
}) => {
makeDir.sync(output);
return async (pages) => {
pages.forEach(({ name: pageName, components }) => {
const sprites = svgstore(options);

components.forEach(({ name: componentName, svg }) => {
sprites.add(`${iconPrefix}${pageName}/${componentName}`, svg);
components.forEach(({ name: componentName, svg, figmaExport }) => {
const opts = {
pageName,
componentName,
...figmaExport,
};

sprites.add(getIconId(opts), svg);
});

const filePath = path.resolve(output, `${pageName}.svg`);
Expand Down
1 change: 1 addition & 0 deletions packages/output-components-as-svgstore/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ describe('outputter as svgstore', () => {

expect(writeFileSync).to.be.calledOnce;
expect(writeFileSync).to.be.calledWithMatch('output/page1.svg');
expect(writeFileSync.getCall(0).args[1].toString()).to.be.contain('id="page1/Figma-Logo"');
});
});
2 changes: 1 addition & 1 deletion packages/website/.figmaexportrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = {

require('../output-components-as-svgstore')({
output: './output/svgstore-monochrome',
iconPrefix: '[unfilled] ',
getIconId: (options) => `[unfilled] ${options.pageName}/${options.componentName}`,
options: {
cleanSymbols: ['fill']
}
Expand Down

0 comments on commit b46db83

Please sign in to comment.