-
-
Notifications
You must be signed in to change notification settings - Fork 298
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
Store user answers as defaults #579
Conversation
+1 but didn't we have |
+1 |
@blai The |
👍 |
We've talked about this before in the team. We would like to have a 'global' I agree that settings.json isn't the best name for the file. Where does it get stored? It looks like in the project directly. |
The intention of this PR is to configure the generator itself. The PR comes along with two features:
Settings store The settings store behaves like the config store but the store file is located in the root of the used generator eg. Prompt property store Like in the example below from @kwakayama you can see how to setup the prompt with the new |
@@ -108,6 +108,16 @@ describe('yeoman.generators.Base', function () { | |||
}); | |||
}); | |||
|
|||
describe('#rootGeneratorPath', function () { | |||
it('returns generator name', function () { |
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.
Why is this test here?
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.
Because this method was untested and i couldn't find any tests for it
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.
Then it should be in its own describe :)
Ok so, I'm pretty happy with all of this. My only concerns is that |
* @param {String} rootPath path where the settings.json is stored | ||
*/ | ||
|
||
Base.prototype._setSettingsStorage = function (rootPath) { |
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.
It'd be better (more explicit) if this function returned the Storage instance and if the settings
attribute was assigned inside the constructor method. (so a rename like _getSettingsStorage()
)
this.settings = this._getSettingsStorage();
I know that is not how the other is done, my bad. So if you can also fix the _setStorage
method, that'd be great.
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.
We will update both calls
I dont think Im happy with creating a file in a generator's folder. By |
It is true there's an issue with writing in the npm dir where we might not have write permissions without sudo. |
There's another issue we need to resolve before this feature can hit production. We need a built-in way for user to opt-out of the cache. I guess the best way will be to implement a standardized option like |
+1 to opt-out, maybe |
Oh, |
@eddiemonge yes, currently the settings file locations is the global installed location of the generator.
|
In fact, even if we wanted to, we cannot reuse I'd probably go with |
Why not just |
I would go with |
|
+1 for |
+1 for .yo-rc-global.json |
Tomorrow i will implement the opt-out argument |
Allright! Thanks for the awesome works. By the way, we need to release a couple of fixes and let the current version run a bit before we launch 0.18 with this new feature. Don't worry if it takes a week or two before merging in master. |
We are done from our side. It's your turn now 😉 |
🍻 Nice work |
@stefanbuck could you squash the commits down to one? |
thanks for the awesome work. very useful. |
@eddiemonge , what's wrong with the commits ? |
@kojiwakayama The issue is there's 19 commits and most of them are not relevant on their owns: http://yeoman.io/contributing/pull-request.html A little clean up sure wouldn't hurt. |
@SBoudrias, agreed, a little clean up makes sense. Squashing the history down to one doesn't. |
Well ideally the PR would only have one feature in it with one commit for that feature. That doesn't seem to be the case here so a few commits should be ok but one would be better so we could track the changes if needed. One commit is easier when using git bisect than 19. |
@eddiemonge @SBoudrias I've squashed the commits down to one as your prefer. |
@stefanbuck Can you fix the merge conflict? @SBoudrias @eddiemonge Anything left for this to be merged? |
break; | ||
|
||
default: | ||
// Fix one space answer to empty strigng |
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.
typo
Only other thing I would like to see is some documentation added about whats happening over at https://github.com/yeoman/yeoman.io/ |
@sindresorhus we're going to release a patch for 0.17, wait a bit then release this one on version 0.18 |
I think this is ready now. |
@eddiemonge Not sure... I'd like to land #617 - make a patch release and finish generator-generator on 0.17 before we start looking at 0.18 |
Update! Patch release for yeoman-generator went out and the new generator-generator went out too! This mean we should consider merging this early next week! And release 0.18 soon after. BTW, I'll take care of the merge because I want to review before that this patch doesn't break the existing Inquirer public API. |
Hey guys, sorry if it took that long. I realized reviewing this review again last week that it actually break the Inquirer public API as it don't allow That got me thinking and I believe we need to reworks this PR. The main point is that we really need to make the feature less intrusive. This could be done in two step:
Doing it this way, we're making sure we're not overwriting Inquirer behavior and we're just applying a thin layer on top of it. Another concern I have, how can we clear the global cache? What if a generator change a question? ATM I feel an answer is cached forever, should we bind the cache to the specific generator version? (Open questions) |
Mhh okay, so i will start reworking the PR in the next days. In regard to your convern with clearing the cache: this is a good point, we missed in the current version. You are right, at the moment the anwers will cached forever. Maybe yeoman cli should provide a command to clear the cache manually for a specifc generator. To resolve the problem with changing questions I’ve following approaches:
Personally i prefer the frist or the second approach because both are pretty simple and the generator developer doesn’t need to know anything about the answer cache. |
@sindresorhus why did you merged this PR? It's still in progress! Yesterday I've rejected all our changes to have a clean repo for the reimplementation. |
No idea what's happening, but I didn't. See the referenced commit is something completely different: 7a4ce2e |
Wow, weird Github bug... |
Hey @stefanbuck got an answer from Github staff, this is effectively a bug (the last commit pushed may have been corrupted during transfer or something like that and it broke Github). Can you just reopen a new PR? |
Yes I do but need time to do this. |
We added the ability to save user inputs as new default values.
To use this feature just set the
store
attribute totrue
.When the user enters his name (eg.:
octocat
), the generator will return the name as default answer next time.All prompt types of Inquirer are supported.
We use Yeoman's storage api to save the values.
The values will be stored in a
settings.json
which is located in the root of the generator.You can see a working example in the generator-node-gulp.