Skip to content
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

Merged
merged 4 commits into from
Apr 5, 2017
Merged

Make it possible to pass data to templates #163

merged 4 commits into from
Apr 5, 2017

Conversation

kjarmicki
Copy link
Contributor

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.

@kjarmicki
Copy link
Contributor Author

Hm.. interesting, build failed on a file that I haven't touched. Not reproducable locally yet, but I'll keep trying 🤔

@dlmr dlmr added the feature label Feb 24, 2017
Copy link
Member

@dlmr dlmr left a 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.

@@ -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`
Copy link
Member

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'.

{
"data": {
"version": "1.0.2",
"recentChanges": fetch("https://some-changelog.org/recent")
Copy link
Member

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();
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point :)

@dlmr dlmr merged commit 836e97d into rocjs:master Apr 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants