Register Yeoman Generator non-cli - node.js

I want to run a Yeoman generator without the cli (yo). I see the instructions in the Yeoman documentation about how to run a generator without the CLI environment.
If I run yo mygenerator:mysubgenerator it works (it's installed globally), but using env.run('mygenerator:mysubgenerator') from node does not work. It says that the generator is not installed.
I think this has to do with the //register/lookup generators step in the documentation above, but they don't include how to do this at all. How can I register my globally-installed generator?

There's a complete documentation here: http://yeoman.io/authoring/integrating-yeoman.html
The basic idea is you need to lookup installed generators before you can run them:
env.lookup(function () {
env.run('angular');
});

Why don't you try on this way:
env.register(require.resolve('generator-mygenerator'), 'mygenerator:mysubgenerator');

Related

create nodejs cli select/options menu

How do you create an arrow-key menu list?
I'm looking for something like after entering in eslint init or create-react-app <project>? (see images below)
ESlint
yeoman
Searching around to find ways to create a CLI, I found NodeJS to be an option followed by a few tools: Commander.js, Vorpal, and/or create-new-cli.
If I am on the right track, how can I create a CLI arrow-key select menu?
I believe yeoman is using inquirer. Source: yo's dependencies.
I've also seen prompts which has a similar arrow selection feature and other cli ui/ux features. See the demos about halfway down the page.
Note: I've never actually used either, I'm just in the same research phase.
looks like 'inquirer' (npm i inquirer)
also for progress bars and such you should look at clui (npm i clui)
for parsing commands most use commander (npm commander) or the open cli framework (npm i oclif) - you can also look at yargs (very similar to commander, npm i yargs)
inquirer and clui work very well with both command parsers.
Have fun.

Debug jhipster modules

I have created a jhipster module (yeoman generator) following steps from [1] and I would have loved to be able to debug the node.js code from the generator at the moment when it is being used in a jhipster app. I found tool at [2] but it acts as if the code from the generator does not get to be run.
Detailed explanation:
I have created the jhipster module generator-jhipster-entity-replacer.
I created a project jhipster-test-proj in whom I invoke
the generator.
yo jhipster-entity-replacer
This is the moment where I would like to see that my breakpoints from generator-jhipster-entity-replacer node.js code are toggled, but nothing happens.
May someone help me with detailed explanation?
I might have been a little blury in explanations due to the fact that I have moreover a stronger Java background then Javascript related one. If someone can help me, but needs more information, please ask.
[1] https://jhipster.github.io/modules/creating-a-module/
[2] https://github.com/node-inspector/node-inspector
Update:
I' ve managed to debug with the command from Pierre Besson's link:
node --debug <path to yo cli.js> <generator> [arguments]
in my case:
node --debug C:\Users\PowerUser\AppData\Local\Yarn\config\global\node_modules\yo\lib\cli.js jhipster-entity-replacer
Even though, I do not recommend this approach. It is a command line debugger with a limited set of instructions, but is still a doable thing.
What i recommend, is this one, a DevTools version for node.js:
https://github.com/node-inspector/node-inspector
I've ran it with the command:
node-debug C:\Users\PowerUser\AppData\Local\Yarn\config\global\node_modules\yo\lib\cli.js jhipster-entity-replacer
Note:
I had to manually delete .yo-rc.json from my generator because otherwise it would not have worked (i had an error like "Just found a .yo-rc.json in a parent directory.", and then it would stop).
when running yo <generator
behind, it is actually running node <path-to-cli.js> <generator> [this is why debugging with node inspector with that command is ok]

How to create a yeoman generator without yo prefix?

I am creating a command line generator for improve productive with nodejs server development, The most widely used generator is yeoman, so I choice it for creating command line tool, But there is problem that how to use generator without yo prefix?
yo tuols
But I wanna use tuols command without yo prefix
tuols
How to do that?
This is explained in the Yeoman documentation http://yeoman.io/authoring/integrating-yeoman.html

Yeoman generator composeWith

I am building a generator which uses another sub-generator, using composeWith.
I installed my generator using npm install -g generator-my-generator. When running the generator complains that I do not have my sub-generator installed.
My problem is that I don't want to install the sub-generator globally. I tried using it as a dependency / peerDependency (as suggested here), but it did not help.
Is it possible?
You need to provide the path in composeWith third argument:
this.composeWith('generator:name', {}, {
local: require.resolve('generator-foo/generators/name')
});
require.resolve is usually your best bet, but some generators (like generator-node) provide all the paths inside the main module so you don't have to know the package structure.

Yeoman hangs on line 72 of events.js, won't let me do anything

First of all, I'm running this on Windows 8.
So When I install yeoman with npm install -g yo, it seems to work fine.
Then, when I type in the command yo, I get the usual response of:
[?] What would you like to do? (Use arrow keys)
Run the Famous generator (0.2.10)
Update your generators
Install a generator
Find some help
Get me out of here!
But then when I click on, for example,
Update your Generators
I get the following:
Its the exact same error every time, and it's preventing me from using any yeoman generators, which is making it impossible then to use the new Famo.us engine.
So far, I've tried uninstalling and reinstalling Node, Yeoman, and everything in between. I've also tried it in various command prompts, including the standard Windows Command Prompt, Git Bash, NodeJS commandPrompt, and cygwin.
Does anyone know how I can fix this?
One avenue of action I've been thinking about is trying to find this events.js (or whatever other file this error is originating from) and trying to build from there.
Also, this person # Yeoman gifsicle error (and others) seems to be having similar issues, but the fixes mentioned in that question don't seem to be working for me.
Thanks!

Resources