yo icon indicating copy to clipboard operation
yo copied to clipboard

Aliasing generators

Open stylesuxx opened this issue 10 years ago • 6 comments

Hey guys, I wrote a small generator to allow me aliasing generators locally in a project => generator-ho

So instead of for example running:

yo react-webpack-redux:component YourComponent

you can run it like so:

yo ho component YourComponent

The available commands are defined through a JSON file and may be listed by running:

yo ho --help

@SBoudrias contacted me via Twitter and asked if I would like to contribute this to the core, so here I am ;-) He also mentioned there was some discussion about this at some point - I could not find it though.

The generator is very simple and basically just calls composeWith to invoke the commands.

Let me know if and how you would like to see it implemented and I will submit a PR.

stylesuxx avatar Dec 23 '15 23:12 stylesuxx

So, I was thinking that when we call a generator in a folder, we could check the .yo-rc.json file, then

  1. If there's no default generator, assign a default generator
  2. If there's a default generator, then try running [default]:[cmd line input], if that fails, then run yo [cmd line input]

This would give that workflow:

# Creating new app
$ yo angular

# Then we default to angular, so no need for extra typing
$ yo controller  # This runs `yo angular:controller`

# And fallback if we run multiple generators
$ yo travis

SBoudrias avatar Dec 23 '15 23:12 SBoudrias

All right, sounds like a plan. I will fork away and poke around in the code a bit. As soon as I come up with something more or less useful I will update the issue.

stylesuxx avatar Dec 23 '15 23:12 stylesuxx

This is what I came up with so far.

When there is only one generator available in .yo-rc.json I just prepend it to the first argument and pass that to the run call. Not sure yet how we should handle multiple generators, if available - should I prompt the user to choose from an available generator?

stylesuxx avatar Dec 24 '15 01:12 stylesuxx

We'd try to run the concatenation of the args + the generator name, if that fail, we fallback to just the args. This way multiple generators are handled, but only the main one is aliased.

About the .yo-rc.json approach, we need a custom option for yo. Most of these files will have multiple generators configs inside, so right now the code is just selecting one randomly.

SBoudrias avatar Dec 24 '15 01:12 SBoudrias

Not randomly, it only prepends if there is exactly one generator found. That was why I was asking about how to handle multiple generators in the yo rc ;-)

stylesuxx avatar Dec 24 '15 01:12 stylesuxx

Are you asking what happens if the sub-generator has the same name as a globally installed generator? Which takes precedence?

eddiemonge avatar Feb 24 '16 00:02 eddiemonge