Skip to content

Allow to provide custom index.js template#378

Merged
gregberge merged 4 commits into
gregberge:masterfrom
TrySound:custom-index-template
Jan 17, 2020
Merged

Allow to provide custom index.js template#378
gregberge merged 4 commits into
gregberge:masterfrom
TrySound:custom-index-template

Conversation

@TrySound

@TrySound TrySound commented Jan 7, 2020

Copy link
Copy Markdown
Contributor

New index.js generator does not cover my cases.

  1. need to add // @flow on top of the file
  2. need to use named export

Both can be easily solved with indexTemplate option.

function indexTemplate(files) {
  const exportEntries = files.map(file => {
    const basename = path.basename(file, path.extname(file))
    return `export { ${basename} } from './${basename}'`
  })
  return '// @flow\n' + exportEntries.join('\n')
}

New index.js generator does not cover my cases.

1. need to add `// @flow` on top of the file
2. need to use named export

Both can be easily solved with indexTemplate option.

```
function indexTemplate(files) {
  const exportEntries = files.map(file => {
    const basename = path.basename(file, path.extname(file))
    return `export { ${basename} } from './${basename}'`
  })
  return '// @flow\n' + exportEntries.join('\n')
}

```
@vercel

vercel Bot commented Jan 7, 2020

Copy link
Copy Markdown

This pull request is being automatically deployed with ZEIT Now (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://zeit.co/gregberge/svgr/5uys6bs0b
✅ Preview: https://svgr-git-fork-trysound-custom-index-template.gregberge.now.sh

@codecov

codecov Bot commented Jan 7, 2020

Copy link
Copy Markdown

Codecov Report

Merging #378 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #378   +/-   ##
=======================================
  Coverage   85.14%   85.14%           
=======================================
  Files          30       30           
  Lines         505      505           
  Branches      140      140           
=======================================
  Hits          430      430           
  Misses         62       62           
  Partials       13       13

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2c0863b...c016a6c. Read the comment docs.

@TrySound

TrySound commented Jan 9, 2020

Copy link
Copy Markdown
Contributor Author

Hi @gregberge. What do you think?

@gregberge gregberge left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good to me, could you please update the documentation?

Comment thread website/src/pages/docs/options.mdx Outdated

| Default | CLI Override | API Override |
| ------------------ | --------------------- | -------------------------- |
| [`basic template`](https://github.com/gregberge/svgr/blob/master/packages/cli/src/dirCommand.js) | Only available in API | indexTemplate: files => '' |

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should have the same API as the template option. I mean available in CLI and API.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added --index-template to cli

@TrySound

Copy link
Copy Markdown
Contributor Author

@gregberge Looks good now?

@gregberge gregberge merged commit f734dda into gregberge:master Jan 17, 2020
@TrySound TrySound deleted the custom-index-template branch January 17, 2020 13:12
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