Testing yeoman generator locally

2020-06-01 07:50发布

I'm creating a yeoman generator for my web projects.

But I wonder how I can try and test my changes before publishing it?

Since I have installed it once, it will not run my local development version, instead it runs my installed version.

Any suggestions on how can test-run my local development version?

2条回答
孤傲高冷的网名
2楼-- · 2020-06-01 08:30

If by "running locally" you mean the ability to test your generator and its flow you can simply do this.

  1. In your project directory folder run npm link. If this passes in flying colors, go to step 2.
  2. Open a terminal and cd into the folder you wish to initiate a project.
  3. Run yo generator-theNameOfYourGenerator. This will run your generator.
查看更多
孤傲高冷的网名
3楼-- · 2020-06-01 08:38

I finally found some information on how to accomplish this:

if you wish to develop on the generators code base, and debug locally, a common way to do so is to rely on npm link

  1. git clone the generators repo locally
  2. cd into that repository and run npm link. It'll install required dependencies and install the package globally, using a symbolic link to your local version.
  3. If you want to install sub generators, you need to do so in the context of a yeoman-generator package linked earlier. Cd into the sub generators package you have cloned locally and run npm link.
  4. We now have everything linked and known on the system, we now need to link the sub-generator repo into the parent one, yeoman-generator cloned and linked in step 1 & 2.

https://github.com/yeoman/generator/wiki/Testing-generators

EDIT:

Updated link for info: https://yeoman.io/authoring/index.html

查看更多
登录 后发表回答