Skip to content

Commit

Permalink
Change defaults for getDirname and getBasename (output-components-as-…
Browse files Browse the repository at this point in the history
…svg)
  • Loading branch information
marcomontalbano committed Jan 27, 2020
1 parent b084462 commit 8391b82
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 21 deletions.
4 changes: 2 additions & 2 deletions packages/output-components-as-svg/index.js
Expand Up @@ -4,8 +4,8 @@ const makeDir = require('make-dir');

module.exports = ({
output,
getDirname = (options) => options.dirname,
getBasename = (options) => `${options.pageName}-${options.basename}.svg`,
getDirname = (options) => `${options.pageName}${path.sep}${options.dirname}`,
getBasename = (options) => `${options.basename}.svg`,
}) => {
return async (pages) => {
pages.forEach(({ name: pageName, components }) => {
Expand Down
16 changes: 8 additions & 8 deletions packages/output-components-as-svg/index.test.js
Expand Up @@ -24,8 +24,8 @@ describe('outputter as svg', () => {
})(pages);

expect(writeFileSync).to.be.calledTwice;
expect(writeFileSync.firstCall).to.be.calledWithMatch('output/page1-Figma-Logo.svg');
expect(writeFileSync.secondCall).to.be.calledWithMatch('output/page1-Search.svg');
expect(writeFileSync.firstCall).to.be.calledWithMatch('output/page1/Figma-Logo.svg');
expect(writeFileSync.secondCall).to.be.calledWithMatch('output/page1/Search.svg');
});

it('should create folder if component names contain slashes', async () => {
Expand All @@ -38,7 +38,7 @@ describe('outputter as svg', () => {
})(pages);

expect(writeFileSync).to.be.calledOnce;
expect(writeFileSync.firstCall).to.be.calledWithMatch('output/icon/fakePage-eye.svg');
expect(writeFileSync.firstCall).to.be.calledWithMatch('output/fakePage/icon/eye.svg');
});

describe('options', () => {
Expand All @@ -50,24 +50,24 @@ describe('outputter as svg', () => {

await outputter({
output: 'output',
getBasename: (options) => `${options.basename}.svg`,
getBasename: (options) => `${options.pageName}-${options.basename}.svg`,
})(pages);

expect(writeFileSync).to.be.calledOnce;
expect(writeFileSync.firstCall).to.be.calledWithMatch('output/icon/eye.svg');
expect(writeFileSync.firstCall).to.be.calledWithMatch('output/fakePage/icon/fakePage-eye.svg');
});

it('should be able to customize "dirname"', async () => {
const writeFileSync = sinon.stub(fs, 'writeFileSync');

await outputter({
output: 'output',
getBasename: (options) => `${options.basename}.svg`,
getDirname: (options) => `${options.pageName}/${options.dirname}`,
getBasename: (options) => `${options.pageName}-${options.basename}.svg`,
getDirname: (options) => `${options.dirname}`,
})(pages);

expect(writeFileSync).to.be.calledOnce;
expect(writeFileSync.firstCall).to.be.calledWithMatch('output/fakePage/icon/eye.svg');
expect(writeFileSync.firstCall).to.be.calledWithMatch('output/icon/fakePage-eye.svg');
});
});
});
3 changes: 2 additions & 1 deletion packages/output-components-as-svgstore/README.md
Expand Up @@ -10,7 +10,8 @@ This is a sample of the output:
$ tree output/
# output/
# ├── icons.svg
# └── monochrome.svg
# ├── monochrome.svg
# └── unit-test.svg
```

Probably you already know what <a target="_blank" rel="noopener noreferrer" href="https://css-tricks.com/css-sprites/">CSS Sprites</a> are, basically you can combine multiple images into a single image file and use it on a website.
Expand Down
2 changes: 1 addition & 1 deletion packages/output-components-as-svgstore/index.js
Expand Up @@ -14,7 +14,7 @@ module.exports = ({
const sprites = svgstore(options);

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

const filePath = path.resolve(output, `${pageName}.svg`);
Expand Down
2 changes: 1 addition & 1 deletion packages/website/.figmaexportrc.js
Expand Up @@ -36,7 +36,7 @@ module.exports = {

require('../output-components-as-svgstore')({
output: './output/svgstore-monochrome',
iconPrefix: 'unfilled-',
iconPrefix: '[unfilled] ',
options: {
cleanSymbols: ['fill']
}
Expand Down
Expand Up @@ -41,12 +41,12 @@ const SvgAsSvgstoreComponent = () => (
<Fragment>
<div className="svgstore" dangerouslySetInnerHTML={{ __html: figmaMonochrome }} />
<div className="svgstore" dangerouslySetInnerHTML={{ __html: figmaIcons }} />
<svg className="icon"><use href="#icons-figma-export" /></svg>
<svg className="icon"><use href="#icons-figma-logo" /></svg>
<svg className="icon"><use href="#monochrome-figma-red" /></svg>
<svg className="icon"><use href="#monochrome-figma-purple" /></svg>
<svg className="icon"><use href="#monochrome-figma-blue" /></svg>
<svg className="icon"><use href="#monochrome-figma-green" /></svg>
<svg className="icon"><use href="#icons/figma-export" /></svg>
<svg className="icon"><use href="#icons/figma-logo" /></svg>
<svg className="icon"><use href="#monochrome/figma-red" /></svg>
<svg className="icon"><use href="#monochrome/figma-purple" /></svg>
<svg className="icon"><use href="#monochrome/figma-blue" /></svg>
<svg className="icon"><use href="#monochrome/figma-green" /></svg>
</Fragment>
</CodeBlock>
);
Expand Down
Expand Up @@ -41,8 +41,8 @@ const SvgAsSvgstoreMonochromeComponent = () => (
<CodeBlock {...props}>
<Fragment>
<div className="svgstore" dangerouslySetInnerHTML={{ __html: figmaIcons }} />
<svg className="icon"><use href="#unfilled-icons-figma-export" /></svg>
<svg className="icon"><use href="#unfilled-icons-figma-logo" /></svg>
<svg className="icon"><use href="#[unfilled] icons/figma-export" /></svg>
<svg className="icon"><use href="#[unfilled] icons/figma-logo" /></svg>
</Fragment>
</CodeBlock>
);
Expand Down

0 comments on commit 8391b82

Please sign in to comment.