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

Learning from grunt-init #199

Closed
passy opened this issue Mar 28, 2013 · 11 comments
Closed

Learning from grunt-init #199

passy opened this issue Mar 28, 2013 · 11 comments

Comments

@passy
Copy link
Member

passy commented Mar 28, 2013

After spending some quality time with grunt-init I found some features I would like to see in Yeoman, too. I talked to Addy today about their prompt implementation and we were wondering if it could make sense to re-use the code from grunt-init in parts: https://github.com/gruntjs/grunt-init/tree/master/tasks/lib

Features I like

It's prettier (solved)

Screenshot from 2013-03-28 23:09:16

They use some color and make it easier to spot which parts of the messages are the default values. This would be very easy to implement.

Predefined Variables

Those are usable throughout the generator, not only in the prompt, which is also helpful for templates. grunt-init tries to figure out what the Github URL is, if the current directory has a origin remote that points to Github and saves it in git_repo. It also pre-populates a git_user variable, which contains the git config --get github.user name or falls back to $USERNAME. This also works for the project name, version number, github homepage and some other options.

What I don't like about the implementation is that they're completely implicit and by using a certain variable name to store the prompt results, you get some magic default values. I would prefer to have an additional option in the prompt hash to specify one of the predefined values. That would also allow to catch typos there and fail with an error.

License File Generator

Another small but useful thing, that would fit nicely into the wiring module. If you specify one or multiple licenses, it automatically puts the files into the generated directory, including the correct year and author.

Recursive Copying

If I'm not mistaken, there is no integrated way to copy a whole directory recursively. This could be useful.
I was mistaken, there is this.directory().

Feedback

What do you think of those features? Do you think they would be useful? Does it make sense to try and re-use some of their code?

// @sindresorhus @addyosmani @kevva @btford

@addyosmani
Copy link
Member

I'm +1 on all of those but feel we should discuss predefined variables a little more. When I reviewed the templates this felt like a sort of best practice pattern that grunt was advocating across all of their generator templates. We could certainly use these for our grunt templates, but then the broader question becomes, is this such a good idea that it should be documented? I think the rest of the items here are fairly sane :)

@passy
Copy link
Member Author

passy commented Mar 29, 2013

That's a good way to put it. I think those predefined variables or magic defaults help a lot to reduce boilerplate code and create a more unified experience among different generators, because you will see the same behavior in all of them.

I would imagine something like this:

var prompts = [{
    name: 'githubUser',
    message: 'Your Github Username:',
    magicDefault: 'githubUser' // But please let's find a better name first! ;)
}];

This would cause a lookup for the githubUser helper before the prompt is displayed which could look up the value in the git config and provide it as default if it's found.

@addyosmani
Copy link
Member

It does look like it would save time. As long as it's an opt-in feature and not the default way generators need to be written at a broader level, +1 on us implementing this.

@sindresorhus
Copy link
Member

I agree with all this. A little wary about the magic default, but it's probably ok if we do it in a explicit way.

Also, ref directory copy, what about actions#directory? https://github.com/yeoman/generator/wiki/base#actionsdirectory

@thanpolas
Copy link

Re predefined variables there's a thread going on on #190, everything boils down to having a persistent storage api provided by yeoman so the generator will learn how to adapt to the user's habits.

passy added a commit to passy/generator that referenced this issue Apr 12, 2013
/ref yeoman#199

This changes the prompt API slightly and adds the following features:

    - `grunt-init` style coloring
    - `default` can be a function (in preperation of "magic defaults")
    - if `default` is a boolean, it will display a 'y/n' prompt with proper
      validation
    - validations occurs after a value is entered and not after the whole wizard
      completed
passy added a commit to passy/generator that referenced this issue Apr 13, 2013
/ref yeoman#199

This changes the prompt API slightly and adds the following features:

    - `grunt-init` style coloring
    - `default` can be a function (in preperation of "magic defaults")
    - if `default` is a boolean, it will display a 'y/n' prompt with proper
      validation
    - validations occurs after a value is entered and not after the whole wizard
      completed
passy added a commit that referenced this issue Apr 23, 2013
/ref #199

This changes the prompt API slightly and adds the following features:

    - `grunt-init` style coloring
    - `default` can be a function (in preperation of "magic defaults")
    - if `default` is a boolean, it will display a 'y/n' prompt with proper
      validation
    - validations occurs after a value is entered and not after the whole wizard
      completed
@passy
Copy link
Member Author

passy commented Apr 23, 2013

We have a prettier prompt now with better validation options. Next step: predefined / magic variables, provisional parameter name: infer.

@passy passy mentioned this issue May 30, 2013
6 tasks
@SBoudrias
Copy link
Member

About fetching git info, checkout https://github.com/shama/grunt-prompts/blob/master/lib/git.js

@sindresorhus
Copy link
Member

@passy is this done? if not could you split the remaining into multiple more focused issues?

@jpdevries
Copy link

Just because it is on the topic of learning from grunt-init, I am porting something from grunt-init and am stumped on how to get multiple files to be processed as template like with .template(). AFAIK In grunt-init, everything in your root folder is processed but in yeoman generator you have to specify files individually. Is there a way to process an entire directory or array of files with something like globbing?

@addyosmani
Copy link
Member

There's probably a more efficient way, but you could just get the list of
current files in cwd at the depth you require and iterate over them using
.template(). That said, it may be useful for us to support a convenience
method for doing this.

On Friday, November 22, 2013, JP DeVries wrote:

Just because it is on the topic of learning from grunt-init, I am porting
something from grunt-init and am stumped on how to get multiple files to be
processed as template like with .template(). AFAIK In grunt-init,
everything in your root folder is processed but in yeoman generator you
have to specify files individually. Is there a way to process an entire
directory or array of files with something like globbing?


Reply to this email directly or view it on GitHubhttps://github.com//issues/199#issuecomment-29053282
.

Addy Osmani
Phone: +44 7771 334170

@jpdevries
Copy link

Support for that would be great! I'll see what I can do in the meantime


Sent from my jPad

On Fri, Nov 22, 2013 at 1:26 AM, Addy Osmani notifications@github.com
wrote:

There's probably a more efficient way, but you could just get the list of
current files in cwd at the depth you require and iterate over them using
.template(). That said, it may be useful for us to support a convenience
method for doing this.
On Friday, November 22, 2013, JP DeVries wrote:

Just because it is on the topic of learning from grunt-init, I am porting
something from grunt-init and am stumped on how to get multiple files to be
processed as template like with .template(). AFAIK In grunt-init,
everything in your root folder is processed but in yeoman generator you
have to specify files individually. Is there a way to process an entire
directory or array of files with something like globbing?


Reply to this email directly or view it on GitHubhttps://github.com//issues/199#issuecomment-29053282
.

Addy Osmani

Phone: +44 7771 334170

Reply to this email directly or view it on GitHub:
#199 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants