-
Notifications
You must be signed in to change notification settings - Fork 0
Using yeoman in non cli environment
In generator v0.15 a new abstraction layer has been introduced to allow IDE, code editor and the like to easily integrate yeoman: the Adapter
.
It's the object responsible for handling all the interaction with the user, if you want to provide a different interaction model from the classical command line, you have to write your own Adapter
.
It provides the question-answer functionality (for instance, when you start yo
, a set of possible actions is prompted to the user).
It's signature and behavior follows these of SBoudrias/Inquirer.js.
When a generators call this.prompt
, the decision is delegated to the adapter
Called internally when a conflict is encountered and the user decide to provide a diff between the old and the new file (string
s passed as aguments).
It's both a function and an object intended for generic output. See lib/util/log.js for the complete list of methods to provide.
If none provided, the environment instantiates a new TerminalAdapter
, used internally to provide console-based I/O;
##Usage Example
If you want to run yeoman
programmatically, you'll have to first add yeoman-generator
(>=0.15) to your package.json
. You can then pass your Adapter
implementation to the factory:
var myAwesomeAdapter = require('./myAdapter');
var generatorFactory = require('yeoman-generator');
//Create a new Environment object which will use your adapter
var env = generatorFactory(null /* default arg */, null /* default opt */, myAwesomeAdapter);
//...
//register/lookup generators
//...
//run the angular generator
env.run('angular', opt);