Skip to content

feature: 858 Index template improvements#861

Merged
gregberge merged 1 commit into
gregberge:mainfrom
balsick:feature/858-index-template
May 9, 2023
Merged

feature: 858 Index template improvements#861
gregberge merged 1 commit into
gregberge:mainfrom
balsick:feature/858-index-template

Conversation

@balsick

@balsick balsick commented Apr 20, 2023

Copy link
Copy Markdown
Contributor

index-template now receives an array of objects containing both the created component path (path) and the original svg path (originalPath).
It is a response to issue #858.

Summary

As before-mentioned, it responds to issue #858, that is, allow index templates to know the original file handled's path.

Test plan

You can use this template. It should create an index.js file containing an object map containing the mapping between the original svg file name and the react component.

const path = require('path');

function defaultIndexTemplate(filePaths) {
  const entries = filePaths.map(({path: filePath, originalPath}) => {
    const originalFileName = path.basename(
      originalPath,
      path.extname(originalPath),
    );
    const basename = path.basename(filePath, path.extname(filePath));
    const exportName = /^\d/.test(basename) ? `Svg${basename}` : basename;
    const importLine = `import ${exportName} from './${basename}';`;
    const mapLine = `${
      /.*[.-].*/.test(originalFileName)
        ? `'${originalFileName}'`
        : originalFileName
    }: ${exportName}`;
    return [importLine, mapLine];
  });
  return `${entries.map(([e]) => e).join('\n')}
export const map = {
${entries.map(([, e]) => e).join(',\n')}
}
`;
}

module.exports = defaultIndexTemplate;

index-template now receives an array of objects containing both the created
component path (`path`) and the original svg path (`originalPath`)
@vercel

vercel Bot commented Apr 20, 2023

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
svgr ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 20, 2023 3:04pm

@codecov

codecov Bot commented Apr 24, 2023

Copy link
Copy Markdown

Codecov Report

Merging #861 (b8059fe) into main (428b0c7) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main     #861   +/-   ##
=======================================
  Coverage   92.82%   92.82%           
=======================================
  Files          32       32           
  Lines         753      753           
  Branches      250      250           
=======================================
  Hits          699      699           
  Misses         53       53           
  Partials        1        1           

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants