Packages
Sharing generators cross-projects and cross-teams can be done simply by copying or any custom tooling your teams come up with that perfectly fits your workflow.
The hygen-add
tool offers a streamlined way to do this by introducing Packages. Packages are a compiled set of generators which are published as a node module that you can install and share with others.
Popular Packages
- hygen-cra (create-react-app) - generate a full set of component, storybook and test for your Create React App project.
Installing a Package
First, you need to install the hygen-add
tool, it's one of the tools in the hygen
toolbelt.
Now pick a published module on npm
and install it. For a module called hygen-acme-generators
, run this, without the prefix hygen-
:
This installs the acme-generators
package with the embedded yarn
so it's versioned and locked, and adds the generators to your current project. Technically, it will copy the generators to your local _templates
directory, because copying is more resilient and robust rather than referencing something that can change unexpectedly.
Once that's done, you can remove acme-generators
using yarn
, or leave it if you'd like to sync your templates once in a while.
Installing from Github
hygen-add
supports installing from Github, in the same way yarn
supports it because it uses yarn
under the hood. It will try to infer the package name from the Github repo URL.
Running this:
Will install the package acme-generators
. The package name acme-generators
was parsed out of the Github URL.
If for some reason your Github URL doesn't reveal anything about the package name, you can manually specify the package name (remember: the package name is the name
property in the package project's package.json
file).
Name Clashes
If you want to install a react
package from both acme
and awesome
, you can prefix one of those, or both, to avoid name clashes: