Allow to provide custom index.js template#378
Conversation
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')
}
```
|
This pull request is being automatically deployed with ZEIT Now (learn more). 🔍 Inspect: https://zeit.co/gregberge/svgr/5uys6bs0b |
Codecov Report
@@ 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 13Continue to review full report at Codecov.
|
|
Hi @gregberge. What do you think? |
gregberge
left a comment
There was a problem hiding this comment.
It looks good to me, could you please update the documentation?
|
|
||
| | 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 => '' | |
There was a problem hiding this comment.
It should have the same API as the template option. I mean available in CLI and API.
There was a problem hiding this comment.
Added --index-template to cli
|
@gregberge Looks good now? |
New index.js generator does not cover my cases.
// @flowon top of the fileBoth can be easily solved with indexTemplate option.