yo icon indicating copy to clipboard operation
yo copied to clipboard

Use generator.name if set in yoyo

Open sindresorhus opened this issue 12 years ago • 16 comments

Just uppercasing the first character doesn't look that good in some cases. Like with the H5BP generator.

Generators supports a name property: https://github.com/h5bp/generator-h5bp/blob/master/app/index.js#L39

Use that in yoyo if it exists.

Before: Run the H5bp generator After: Run the HTML5 Boilerplate generator

Maybe we should enforce generators to set a humanized name?

@stephenplusplus @passy

sindresorhus avatar Jul 05 '13 11:07 sindresorhus

Currently, the H5bp comes from:

// namespace 'h5bp:app', comes from the env.lookup results 
prettyName = namespace.replace(':app', '');
prettyName = prettyName.charAt(0).toUpperCase() + prettyName.slice(1);

This is to avoid reading any files, causing a delay. Can you think of a way we can get a generator's chosen name in a non-speed affecting manner?

stephenplusplus avatar Jul 05 '13 19:07 stephenplusplus

I looked into it, too. I don't believe there is an easy way to realize this at the moment without massive performance drawbacks.

passy avatar Jul 05 '13 21:07 passy

We could make it so nothing is loaded when the generator entrypoint is required, but rather only when it's initiated with a function. That way we could read useful generator info, and only activate it when we need to. ?

An other alternative is to abuse package.json? { "yo": { "name": "HTML5 Boilerplate" }} But I don't particularly like that.

sindresorhus avatar Jul 05 '13 22:07 sindresorhus

Agree. I dislike any abuse of package.json. Could we avoid that approach and experiment with Sindre's function initiation suggestion?

addyosmani avatar Jul 06 '13 21:07 addyosmani

How can we verify that nothing is loaded when the entry point is required? Or do you think of that as a convention?

passy avatar Jul 06 '13 22:07 passy

@passy convention.

sindresorhus avatar Jul 07 '13 09:07 sindresorhus

@SBoudrias any thoughts on this?

sindresorhus avatar Apr 05 '14 19:04 sindresorhus

That make perfect sense. I'd like Yeoman generators to export a main entry point with config and paths to sub generators.

The issue here would be to find a way that is backward compatible. And the answer is not that easy because a lot of generators currently set main to the *:app generator file.

Maybe we could create a config file. Let's say yeoman.js so we can require it require("generator-webapp/yeoman"). That way we'd avoid relying on the package main file.

SBoudrias avatar Apr 05 '14 19:04 SBoudrias

Maybe we could create a config file. Let's say yeoman.js so we can require it require("generator-webapp/yeoman"). That way we'd avoid relying on the package main file.

I rather we try to find a way to require main. That's the sane solution going forward. There might be something we can detect. At worst we could detect what generator version they're using before requiring.

sindresorhus avatar Apr 05 '14 19:04 sindresorhus

At worst we could detect what generator version they're using before requiring.

Yeah, I thought about that, but generators are consumed by yo who's version is controlled by the user, not the generator author...

But this might not be super important as it only mean new/updated generators wouldn't work with old versions of yo.

Still, I'm afraid using main might be error prone... Maybe a file named manifest.js or yo-manifest.js would make more sense? Using a manifest could even be a temporary solution for now, and eventually we move this file to simply being referenced by main.

SBoudrias avatar Apr 05 '14 19:04 SBoudrias

But this might not be super important as it only mean new/updated generators wouldn't work with old versions of yo.

Yeah, that's not a concern at all. It should be expected that people are running latest of yo. No reason not to.

Still, I'm afraid using main might be error prone... Maybe a file named manifest.js or yo-manifest.js would make more sense? Using a manifest could even be a temporary solution for now, and eventually we move this file to simply being referenced by main.

Error prone how?

I really prefer it if generators could be as close to an idiomatic node module as possible.

sindresorhus avatar Apr 05 '14 19:04 sindresorhus

Error prone in the way many generators references *:app in the main field. So, chances are some people gonna miss it and publish bugged versions on NPM.

That's why I feel using a manifest file first, then moving it to package.json main field, would be an easier transition.

I guess I could live with either solutions anyway.

SBoudrias avatar Apr 05 '14 19:04 SBoudrias

So, chances are some people gonna miss it and publish bugged versions on NPM.

Some people are going to miss something no matter what we do.

sindresorhus avatar Apr 05 '14 19:04 sindresorhus

Has there been any progress on this?

We have a generator for the Flow XO platform, called generator-flowxo, which is turned into Flowxo. Ideally we'd like this to read Flow XO.

fiznool avatar Oct 27 '15 14:10 fiznool

This is, IMO, even a more needed feature as scoped packages are becoming more prevelant. We have several internal generators in the form @scope/generator-web-ui-app that display in the menu as @scope/Web Ui App.

bradpearson avatar May 05 '17 01:05 bradpearson

Similar problem here, we have @lonelyplanet/generator-travel-agent and it shows up like this...

jcreamer898 avatar Dec 06 '17 15:12 jcreamer898