Show Menu
Cheatography

Yeoman Generator Development (CoffeeScript) Cheat Sheet (DRAFT) by

A cheat sheet to creating yeoman based generator

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Start Up - Initialize your project

Create an empty node project
npm init .
Make the folder structure as below
<see structure below>
Add / register generator folders in packag­e.json
<see sample below>
Add yeoman­-ge­nerator deps
npm i --save yeoman­-ge­nerator
folder structure
genera­tor­-goofy
├───pa­cka­ge.json
└───ge­ner­ators/
 ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­├──­─app/
            └───index.js

packag­e.json
{
 ­ ­"­nam­e": "­gen­era­tor­-go­ofy­",
 ­ ­"­ver­sio­n": "­1.0.0",
 ­ ­"­fil­es": [
 ­ ­ ­ ­"­gen­era­tor­s/a­pp",

A Generator Class

Import required deps
generators = require 'yeoma­n-g­ene­rator'
Extend from genera­tor­s.Base
class GoofyGen extends genera­tor­s.Base
Ensure CTOR initia­lizes yeoman env
constr­uctor : () ->
    genera­tor­s.B­ase.apply this, arguments
Add whatever methods you need
...
Finally export the class
module.ex­ports = GoofyGen
Example

generators = require 'yeoma­n-g­ene­rator'

class GoofyGen extends genera­tor­s.Base
 ­ ­con­str­uctor : () ->
 ­ ­ ­ ­gen­era­tor­s.B­ase.apply this, arguments

 ­ ­ ­ @log 'Initi­alizing option...'

 ­ ­method1 : () ->
 ­ ­ ­ @log 'proce­ssi­ng...'

module.ex­ports = GoofyGen
 

Yeoman Run Priorities

initia­lizing
Your initia­liz­ation methods (checking current project state, getting configs, etc)
prompting
Where you prompt users for options (where you'd call this.p­rom­pt())
config­uring
Saving config­ura­tions and configure the project (creating .edito­rconfig files and other metadata files)
default
If the method name doesn't match a priority, it will be pushed to this group.
writing
Where you write the generator specific files (routes, contro­llers, etc)
conflicts
Where conflicts are handled (used intern­ally)
install
Where instal­lation are run (npm, bower)
end
Called last, cleanup, say good bye, etc
Developers get to control the execution flow and compos­abi­lity, yeoman implements a Groupe­d-queue based Run loop and priori­ties.

Priorities are defined in your code as special prototype method names. When present they execute it accord­ingly.

genera­tor­s.B­ase.ex­tend({
 ­ ­pri­ori­tyName: {
 ­ ­ ­ ­method: function () {},
 ­ ­ ­ ­met­hod2: function () {}
 ­ }
});