Skip to content
yeomanPublic

About

Rails-inspired generator system that provides scaffolding for your apps

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1.3k stars

Watchers

39 watching

Forks

Latest commit

 

History

1,951 Commits

Folders and files

Generator npm Integration Build Coverage Status Gitter

Rails-inspired generator system that provides scaffolding for your apps

Getting Started

If you're interested in writing your own Yeoman generator we recommend reading the official getting started guide. The guide covers all the basics you need to get started.

A generator can be as complex as you want it to be. It can simply copy a bunch of boilerplate files, or it can be more advanced asking the user's preferences to scaffold a tailor made project. This decision is up to you.

The fastest way to get started is to use generator-generator, a Yeoman generator to generate a Yeoman generator.

After reading the getting started guide, you might want to read the code source or visit our API documentation for a list of all methods available.

API documentation for v4.x.

Features

Features configure the behavior of a generator. They are given to the constructor, or declared by the class with customFeatures:

import Generator from 'yeoman-generator';

export default class extends Generator {
  constructor(args, options) {
    super(args, options, { unique: 'namespace' });
  }
}

The default features of every generator of a package can be declared in its package.json, under yeoman.features, without a parent class shared by the generators of the package:

{
  "name": "generator-foo",
  "yeoman": {
    "features": { "unique": "namespace", "disableLodashProperty": true }
  }
}

The package.json is read with the getPackageJson() of the generator meta, given by the environment, so these defaults apply to generators instantiated by an environment from a package. Each feature given to the constructor or to setFeatures() overrides the same feature of customFeatures, which overrides the same feature of yeoman.features. customFeatures, a field of the class, is set after the constructor, so the features the constructor reads (unique, disableInGeneratorOptionsSupport, customPriorities) are overridden only by the features given to the constructor. Only features with JSON values can be declared in the package.json, and uniqueBy, which identifies a generator, is ignored there.

yeoman-environment gives the meta with getPackageJson() to the generators since 6.2.0. An older environment does not, and the generators run without the features of the package.json. A package using yeoman.features should require that version in engines.

Environment version

A package can declare the range of yeoman-environment versions its generators support in engines['yeoman-environment'] of its package.json:

{
  "name": "generator-foo",
  "engines": {
    "node": ">=20",
    "yeoman-environment": ">=6.2.0"
  }
}

The range overrides the minimum version of yeoman-environment that yeoman-generator requires: every generator of the package checks the running environment against it when it is created, as checkEnvironmentVersion() does, and throws when it does not satisfy it (prereleases included), or warns with the ignoreVersionCheck or skipCheckEnv option. A version alone is a minimum version, not an exact one: "6.2.0" is ">=6.2.0". The package.json is read with the getPackageJson() of the generator meta or, with an environment which does not give it, looked up from the generator file; a generator without a file, like a class composed directly, is not checked against a range. npm checks only node and npm of engines, so the range does not change the install.

checkEnvironmentVersion() accepts a range as well as a minimum version.

The environment is usually the one of yo, not of the package: yo depends on yeoman-environment with a caret range (yo 7 with ^6.0.1), so the version running is the one installed with yo, and reinstalling yo updates it within that range only. The range should accept a version that a published yo installs: >=6.2.0 asks the users of an older yo 7 to reinstall it, while a range above the versions any yo installs, like >=8.0.0 today, fails for every user of yo.

Debugging

See the debugging guide.

Contributing

We love contributors! See our contribution guideline to get started.

Sponsors

Love Yeoman work and community? Help us keep it alive by donating funds to cover project expenses!
[Become a sponsor]

License

BSD license Copyright (c) Google

About

Rails-inspired generator system that provides scaffolding for your apps

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1.3k stars

Watchers

39 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages