https://github.com/generate/best-practices
Advice on creating effective generators and getting the most out of Generate.
https://github.com/generate/best-practices
Last synced: 3 months ago
JSON representation
Advice on creating effective generators and getting the most out of Generate.
- Host: GitHub
- URL: https://github.com/generate/best-practices
- Owner: generate
- Created: 2016-06-11T00:47:36.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-06-13T17:53:51.000Z (about 10 years ago)
- Last Synced: 2025-04-13T02:03:08.040Z (about 1 year ago)
- Size: 1000 Bytes
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Best Practices
This guide shows you how to get the most out of Generate!
- create awesome generators
- naming tasks
- naming generators
- micro-generators
## Naming tasks
**Prerequisites**
- Basic understanding of [tasks]()
- Basic understanding of [generators]()
- Basic understanding of [plugins]()
**Overview**
Using good naming practices ensures that your generator will not only be easier to use from the command line, but it will also be easier for other implementors to use your generator as a [sub-generator][] or [plugin][] in their own generators.
[task documentation](),
Aliases are also useful for preventing task-naming conflicts in cases where generators are used as plugins, since it's possible for multiple generators to have the same task names.
providing an alternative name in cases where a generator might be used as a plugin by another generator, _both generators have a task with the same name_.
```js
// --- one.js ---
module.exports = function(app) {
app.task('foo', function() {});
app.task('bar', function() {});
app.task('default', ['foo', 'bar']);
};
// --- two.js ---
module.exports = function(app) {
// use generator `one` as a plugin, which adds tasks from
// `one` to this generator
app.use(require('./one'));
// the following tasks will overwrite the tasks from generator `one`
app.task('foo', function() {});
app.task('bar', function() {});
app.task('default', ['foo', 'bar']);
};
```