Show Menu

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
 ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­├──­─app/

 ­ ­"­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.B­ase
Ensure CTOR initia­lizes yeoman env
constr­uctor : () ->
    generators.Base.apply this, argume­nts
Add whatever methods you need
Finally export the class
modu­le.e­xp­orts = GoofyGen

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

Your initia­liz­ation methods (checking current project state, getting configs, etc)
Where you prompt users for options (where you'd call this.p­rom­pt())
Saving config­ura­tions and configure the project (creating .edito­rconfig files and other metadata files)
If the method name doesn't match a priority, it will be pushed to this group.
Where you write the generator specific files (routes, contro­llers, etc)
Where conflicts are handled (used intern­ally)
Where instal­lation are run (npm, bower)
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.

 ­ ­pri­ori­tyName: {
 ­ ­ ­ ­method: function () {},
 ­ ­ ­ ­met­hod2: function () {}
 ­ }

Help Us Go Positive!

We offset our carbon usage with Ecologi. Click the link below to help us!

We offset our carbon footprint via Ecologi