-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make it possible to pass data to templates #163
Conversation
Hm.. interesting, build failed on a file that I haven't touched. Not reproducable locally yet, but I'll keep trying 🤔 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR and sorry for being slow on getting back to this.
I like the change, just some small comments on ways we can make it a little better.
docs/Templates.md
Outdated
@@ -161,6 +161,19 @@ The `prompts` property follows [Inquirer.js](https://github.com/SBoudrias/Inquir | |||
|
|||
`name` and `author` are a bit special and will automatically default to the directory name and, if available, the name from the git config. | |||
|
|||
#### `data` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This section should be below ##### 'when'
.
docs/Templates.md
Outdated
{ | ||
"data": { | ||
"version": "1.0.2", | ||
"recentChanges": fetch("https://some-changelog.org/recent") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given how the code is structured this example should be:
"recentChanges": () => fetch("https://some-changelog.org/recent")
/* eslint-disable no-param-reassign */ | ||
if (typeof dataProvider === 'function') { | ||
try { | ||
metadata[key] = await dataProvider(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about passing in the metadata
here, into dataProvider()
?
Then we could get access to the answers that the user has answered.
// Provide metadata
await dataProvider(metadata);
// Later we can use it
"recentChanges": (answers) => fetch("https://some-changelog.org/recent")
If we do this change we should also add a comment about it in the documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point :)
This PR adds ability to pass additional data to templates that cannot or should not be obtained with questions.
My particular case is: I have a template inside of a module and I'd like to get that module's version from
package.json
.