yeoman / yo

CLI tool for running Yeoman generators
http://yeoman.io
BSD 2-Clause "Simplified" License
3.85k stars 399 forks source link

`npm link` results in invalid generators #118

Closed alexgorbatchev closed 10 years ago

alexgorbatchev commented 10 years ago

I'm trying to create my first generator following tutorial, so I'm most likely doing something wrong... just can't tell what

$ yo generate
...

$ npm link .
/Users/alexgorbatchev/.nvm/v0.10.22/lib/node_modules/generator-express-app -> /Users/alexgorbatchev/generator-express-app

$ ls -la /Users/alexgorbatchev/.nvm/v0.10.22/lib/node_modules
...
lrwxr-xr-x   1 alexgorbatchev  staff   16 Dec 17 18:26 generator-express-app -> ../../../../generator-express-app
...

$ yo --help

Usage: yo GENERATOR [args] [options]

General options:
  -h, --help     # Print generator's options and usage
  -f, --force    # Overwrite files that already exist

Please choose a generator below.

Users
  Users:alexgorbatchev:generator-express-app:app

Generator
  generator:app
  generator:subgenerator

$ npm test

express-app creation
    1) "before each" hook

  0 passing (8ms)
  1 failing

  1) express-app creation "before each" hook:
     Uncaught Error: You don't seem to have a generator with the name express-app:app installed.
You can see available generators with npm search yeoman-generator and then install them with npm install [name].
To see the 1 registered generators run yo with the `--help` option.
    at Environment.create (/Users/alexgorbatchev/generator-express-app/node_modules/yeoman-generator/lib/env/index.js:312:7)
    at Object.helpers.createGenerator (/Users/alexgorbatchev/generator-express-app/node_modules/yeoman-generator/lib/test/helpers.js:238:23)
    at /Users/alexgorbatchev/generator-express-app/test/creation.spec.coffee:8:21, <js>:12:31
    at /Users/alexgorbatchev/generator-express-app/node_modules/yeoman-generator/lib/test/helpers.js:182:5
    at CB (/Users/alexgorbatchev/generator-express-app/node_modules/yeoman-generator/node_modules/rimraf/rimraf.js:42:5)
    at /Users/alexgorbatchev/generator-express-app/node_modules/yeoman-generator/node_modules/rimraf/rimraf.js:118:7
    at Object.oncomplete (fs.js:107:15) 

it seems that npm linked generator ends up under wrong name... using full path, instead of actual generator name

I have also tried installing from master and it doesn't seem to work at all.

$ npm install -g git+ssh://git@github.com:yeoman/yo.git git+ssh://git@github.com:yeoman/generator.git
...
$ yo --help
Usage: yo GENERATOR [args] [options]

General options:
  -h, --help     # Print generator's options and usage
  -f, --force    # Overwrite files that already exist

Please choose a generator below.
$

No visible generators...

posted originally in https://github.com/yeoman/yeoman/issues/1244

SBoudrias commented 10 years ago

Pretty sure this bug have been resolved in next release. To test it though you'd need to use a build of yo using yeoman-generator master branch.

Try to npm link your generator locally.

SBoudrias commented 10 years ago

Tested myself with lastest yeoman-generator and it works good for me. I added your case to the relevant method assertion list to make sure it is covered in the future too.

alexgorbatchev commented 10 years ago

@SBoudrias could you tell me how you are testing? Also, what are node/npm versions you have? I really want to get this to work :)

alexgorbatchev commented 10 years ago

I figured out what the problem is... The folder where your generator resides HAS to be named the same as your generator, eg generator-foo.

SBoudrias commented 10 years ago

Heum, can you represent your folder structure before and after? I really don't see what you mean from the log, ain't your generator named generator-express-app as the folder?

brandonculver commented 10 years ago

I had the same issue and can see why it is a little confusing. One would assume the base-folder holding the app really wouldn't have to follow a naming convention, considering the contents of the folder holds the real configuration of the generator. It does enforce a very clean, but rigid design that ultimately limits misunderstandings. My example resulted from me skimming the tutorial and mistakingly named my folder xxxxx-generator instead of generator-xxxxx.

SBoudrias commented 10 years ago

@brandonculver Yeoman needs to base itself on directory paths because we cannot require all available generators to get meta data from them. This would be way too long. So instead, we walk the NPM directories and look for packages matching generator-* pattern.

That's why the folder name matter; performance reason.

brandonculver commented 10 years ago

@SBoudrias Yeah it makes sense.

joelbandi commented 7 years ago

@alexgorbatchev I'm currently using the latest version v1.8.5 and i still happen to run into this problem. My generator is a called generator-ttestt and it resides in a folder called generator-ttestt. If it helps, my package.json is also is consistent in naming

SBoudrias commented 7 years ago

@joelbandi can you add more context. It fails during tests or when you type yo ttestt?

joelbandi commented 7 years ago

@SBoudrias my Yeoman-cli doesn't even recognize the generator. I followed the tutorial given here http://yeoman.io/authoring/ Here's what I tried:

  1. Directly used yo file/path/to/generator-testt/ and it works
  2. Used npm link. Verified that the symlink is created and is in the same folder as that of the yo binaries, but yo still doesnt recognize my generator
  3. Finally, I used the generator-generator to scaffold out a project and surprisingly yo is able to recognize the generator-ttestt after npm link
SBoudrias commented 7 years ago

@joelbandi any chance the file structure was wrong? yo file/path/to/generator-testt/ should be yo file/path/to/generator-testt/app (or yo file/path/to/generator-testt/sub-generator-name) for it to match the behavior of yo namespacing.

joelbandi commented 7 years ago

@SBoudrias I think my file structure was wrong. I placed my index.js which exports an instance of generator subclass in the root of my project instead of placing it in file/path/to/generator-testt/generator/app. When the guide used the name index.js I inferred it's going to be placed in the project root. Here in the line "In the generator's index.js file, here's how you extend the base generator:" under the "Extending generator" section.

dt-rush commented 5 years ago

@joelbandi i am another victim of this same ambiguity in the guide

SBoudrias commented 5 years ago

@dt-rush @joelbandi Could one of you send a PR to our documentation to disambiguate this line? I'll be happy to review and help merge quickly.

joelbandi commented 5 years ago

@SBoudrias Will be glad to send one out over this weekend!