A lots of changes and new features have been introduced in the Generator System (npm search yeoman-generator
) lately. If you’re not watching the yeoman/generator, maybe you’ve been let down on the latest changes. Fear not, we documented every recent release in our changelog!
Along with the new year start, we’ve decided to build a todos list of the most important changes our official generators should implement. This will allow them to be clean, but also ready for the new upcoming feature; notably the capacity to compose multiples generators together!
You may not be an official generator maintainer, but we invite you to follow our lead and make sure you follow these guidelines. So, here it goes!
Generators should generate a .yo-rc.json
file
The .yo-rc.json
file allow you to save configuration, but is also the marker used to define a project root folder. This allow user from running yo
command from sub directory to work on their whole project.
It is also how composed generators will know what is the root of a project.
Simply add this line somewhere in your generator to generate the file at least once:
this.config.save();
Of course, if you’re using the config object to store datas, it’ll already be created. Read more on the config Storage in our API reference.
Use the new .extend()
method instead of util.inherit
Until recently, you’d extend the Base generator this way:
var BlogGenerator = (module.exports = function() {
generators.Base.apply(this, arguments);
// ...
});
util.inherits(BlogGenerator, generators.Base);
You can now do the same in a fashion similar to Backbone.js:
var BlogGenerator = (module.exports = generators.Base.extend({
/* prototype methods goes here */
}));
As you may know, our next big milestone is to allow generator to be composed with each other. This mean you’ll be able to use external generators inside your own, and allow user to build their app using multiple generators (like, I want to build an app with Sailsjs and Angular, with Bootstrap and support for Jenkins tests). Using the .extend
inheritance signature will make it easier to get your generator ready to integrate into the composable yeoman ecosystem.
Note that we extracted the inheritance logic into a small standalone NPM module. It’ll be easy to add such functionnality into your own projects without any overhead!
Remove use of deprecated test methods
In release 0.16.0
, we deprecated some tests methods and added some other. Deprecation are now logged to the console, so make sure you get rid of those!
Also, helpers assertions methods are now exposed on the yeoman.assert
namespace.
Update dependencies in the generated bower.json and package.json
As usual, update your deps. You may use david tool for that.
Make sure package.json peerDependencies
do not use tilde ~
versioning
NPM peerDependencies
are tricky to get right. As they’re installed in the global node_modules
folder, they’re often the cause of installation errors due to incompatible version required between differents packages. Please, be a good citizen and don’t make the issue worse by using restrictive version requirement.
So, make it a rule to always defines peerDependencies
version using a minimum range (>=
), or using any available version (*
).
{
"peerDependencies": {
// GOOD
"grunt-cli": ">= 0.1.0",
// GOOD
"gulp": "*",
// BAD - don't ever do this
"generator-karma": "~1.2.0",
"generator-commonjs": "1.2.0"
}
}
On that, good luck!
That’s all folks! Good luck and keep on building awesome generators.
If you’re a generator author, you really should click the watch
button on the Generator system repo - this way you’ll be kept up to date on our future plan and updates. Also make sure to check the [Composability]
issues, this is our next big milestone and we need your feedback!