Yeoman special generator

I would like to create a custom generator with the latest version of yoman, but I have some difficulties. I searched for various documentation sources and examples (e.g. webapp and angular generators), but I still have a few questions.

  • What is the workflow for testing a generator? If I have one project that is the generator itself, do I continue to create new directories to run yo my-generator ?

  • Is the generator infrastructure altered by the beta version of yo 1.0? Have there been any violations?

  • How is a generator registered in the yo global binary?

Thanks.

+6
source share
2 answers

What is the workflow for testing a generator?

I will be working on this in the next couple of days for the angular generator. You can track my progress on Github . Unfortunately, there are not many examples yet due to the transition from one yeoman to using yo next to bower and yo . I assume that at the Generator.prototype.method level a certain level of unit testing will be carried out, as well as E2E testing, which includes writing bash scripts to run yo , npm , bower and grunt .

Is the generator infrastructure developed in beta 1.0 at all? Have there been any changes?

In my experience of porting the angular generator, I have not seen too many changes. There is a new, optional simplified API that may be useful.

How does a generator register with global binary yo ?

The answer right now is that it is not. You install / use generators in the project directory. I somehow worked due to an erroneous symbolic link, but this is not the recommended way to do this.

+6
source

This question is a few months old, but I think it is useful for those who find it now to find out, which has been much more explained in http://yeoman.io/generators.html

Question 1:

Testing your generators locally can be easily done. For example, if your generator is called "mtv-raps generator"

 $ cd ~/dev/generator-mtv-raps/ $ npm link 

Now if you do:

 $ cd ~/dev/mytest/ $ yo mtv-raps 

It will be created.

In addition, the test unit for your wet mocha generator is pretty simple. There is a built-in set of test assistants. The basics of what you need to test can be found in the generator-webapp tests https://github.com/yeoman/generator-webapp/blob/master/test/test.js

  • Verify that the generator may be required without breaking.
  • Mark your invitations with helpers.mockPrompt
  • Verify that all the files you want to create are created using helpers.assertFiles
  • Test that the values ​​you are mocking are inserted into the created files.

The number 4 is quite complex; an array of expected files can be passed a regular expression for validation. If you want to know more about test assistants, the source is the best place. https://github.com/yeoman/generator/blob/master/lib/test/helpers.js

Question 2: btford already answered

Question 3:

Generators are tied to yo , installing them globally (or binding them as described above) and using a naming convention. All generators start with "generator", then "-", then "name".

hence generator-mtv-raps is available through $ yo mtv-raps

+7
source

All Articles