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

How can i get the Author's name? #190

Closed
thanpolas opened this issue Mar 17, 2013 · 24 comments
Closed

How can i get the Author's name? #190

thanpolas opened this issue Mar 17, 2013 · 24 comments

Comments

@thanpolas
Copy link

How can i get the Author's name?

Is there a persistent storage API for such preferences information? (fullname, github, website, license, etc)

@sindresorhus
Copy link
Member

Your question is very unclear.

@thanpolas
Copy link
Author

grunt-init prompt

in grunt-init all these prompt questions were pre-filled, not entered. I answered them once and they are stored for every consecutive project.

@thanpolas
Copy link
Author

@sindresorhus ?

@sindresorhus
Copy link
Member

I'm still not sure what you're asking? We don't yet have a generator replacement for the grunt-init scaffolders, but we're working on it.

@thanpolas
Copy link
Author

for e.g., the README.md template of a generator:

## License
Copyright (c) <%= (new Date).toString().split(' ')[1] %> ME PRETTY

How can i use the author's name instead of ME PRETTY ?

@sindresorhus
Copy link
Member

Right, ok, so we don't yet have good docs on the generators.

Everything attached to the generator object will be available for templating: https://github.com/yeoman/generator-webapp/blob/master/app/index.js#L31

If you want to prompt for Author name, you just prompt, then in the callback you assign it to the generator object: https://github.com/yeoman/generator-webapp/blob/master/app/index.js#L74

@thanpolas
Copy link
Author

oh neat, this.pkg could work... Do you have any abstraction layer in the works?

E.g. the author prop can be a string or an object:

  "author": "Author Name"

an object:

  "author": {
    "name": "Author Name",
    "email": "email@mail.com",
    "url": "http://github.com"
  }

... or it could be missing entirely, or the array not contain the name prop...

Is there a persistent storage API on yeoman?

@thanpolas
Copy link
Author

@sindresorhus i take it back, package.json will not work, it is part of the templates thus has no values.

The only solution i see is persistent storage.

@sindresorhus
Copy link
Member

Do you have any abstraction layer in the works?

Abstraction layer like?

The only solution i see is persistent storage.

Just prompt for it and then save it using any node module for that purpose. Don't forget it's all just Node, which means you have 20.000+ modules at your disposal. I would recommend configstore for persistent storage.

@thanpolas
Copy link
Author

I'd feel much more confident if the generator provided an API for that.

Stories:

  • As a user i want to enter my name once and only once when using yeoman's generators. The same applies for any other data.
  • As a developer i don't want to have a custom persistent storage stack and maintain it, i want to focus on my generator.
  • As a developer i want to have a standardized API to consume when i want identity information.
    • i.e. If i want the user's name there should be a specific structured data source providing it: yo.user.getName();
    • i.e. yo.user.getLicensePref() === 'MIT'

@sindresorhus
Copy link
Member

As a user i want to enter my name once and only once when using yeoman's generators. The same applies for any other data.

I like the idea of the prompt system remembering what you choose last and defaults to that. This is something that should indeed be built-in. A complete API for persistent storage, I'm not so sure. Any other use cases for persistence other than the above case?

As a developer i want to have a standardized API to consume when i want identity information.

Prompts are very generator specific and I don't see that working out. But I do agree that the current prompt system is a bit convoluted. We need to think of a more generic way to accomplish this.

@thanpolas
Copy link
Author

Any other use cases for persistence other than the above case?

no, my motivation is having structured data to fill in the templates, name, github repo, website, etc...

re prompt system, there should also be the ability, when a generator is included, to have it's prompt questions filled programmatically.

@sindresorhus
Copy link
Member

when a generator is included, to have it's prompt questions filled programmatically.

Makes sense

@thanpolas
Copy link
Author

I am sorry, i have to revise

Any other use cases for persistence other than the above case?

no, my motivation is having structured data to fill in the templates, name, github repo, website, etc...

New answer: yes, i want to store the values that i have prompted the user for each consecutive launch of the generator. The value that i prompt the user can be custom and not related to the data struct that will be provided.

@mehcode
Copy link

mehcode commented Mar 21, 2013

To elaborate a bit more concretely on a use case for persistent storage. Take sub-generators for example, I'd like the end users experience to be yo chaplin, answer lots of questions like brunch or grunt / haml, handlebars, etc. / sass, less, stylus, etc. / javascript, coffeescript, etc., then run yo chaplin:model and not re-ask any questions except for what is pertinent for that sub-generator (ie. the name of the model).

In the case of https://github.com/yeoman/generator-backbone the end user shouldn't have to run yo backbone:model --coffee each time if they initialized with yo backbone:app --coffee.

@thanpolas
Copy link
Author

following up on @mehcode's comment, it would make sense to have a storage scope, global and local

  • global Custom persistent configuration that applies to all generator invocations
  • local Custom persistent configuration that applies to a specific, already generated source (i.e. the yo chaplin:model inside an already generated source).

Not sure if local would entail a local file in the generated source eventually... Could create issues in the long-term with * orphaned* local configs that do not exist in the HD any more...

@jonschlinkert
Copy link

👍 love this concept. @mehcode's use case is very similar to what I was hoping to achieve when generating templates and components for assemble

@robwierzbowski
Copy link

@thanpolas If you want a default on first install and are confident that the user has git installed, you can try what I'm doing in generator-jekyllrb and query values from their .gitconfig.

I'm using the shelljs node library for running synchronous shell commands.

  // Get user info from .gitconfig if available
  this.gitInfo = {
    name: shelljs.exec('git config user.name', {silent: true}).output.replace(/\n/g, ''),
    email: shelljs.exec('git config user.email', {silent: true}).output.replace(/\n/g, ''),
    github: shelljs.exec('git config github.user', {silent: true}).output.replace(/\n/g, ''),
  };

@SBoudrias
Copy link
Member

A release will soon include the generator#Storage functionnality. (Check #320)

That'll allow you to keep track of the user settings. I also implemented this functionnality on Generator-BBB as a demo: https://github.com/backbone-boilerplate/generator-bbb/compare/yeoman-wip

@sindresorhus
Copy link
Member

Soon === Now. 0.13.0 ;)

@passy
Copy link
Member

passy commented Aug 7, 2013

\o/

@SBoudrias
Copy link
Member

This issue seems resolved with the storage and the new git data helpers. I'll close, feel free to reopen or open a new issue if anything is still missing.

@addyosmani
Copy link
Member

Thanks Simon. Appreciate you housekeeping!

@jaseemabid
Copy link

@mehcode Good if we can also remember preferences like --requirejs

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

No branches or pull requests

9 participants