Why the _directory function is called four times in a yeoman.generators.Base subclass? -
here how extend yeoman generator base
class
module.exports = yeoman.generators.base.extend({ prompting: function () { var done = this.async(); // have yeoman greet user. this.log(yosay( 'welcome cool ' + chalk.red('generator-zeetings') + ' generator!' )); var prompts = [{ ... }]; this.prompt(prompts, function (props) { this.props = props; // ... done(); }.bind(this)); }, _directory: function (source, destination) { // simplified question var src = path.join(source, 'index.html'); var dest = path.join(destination, 'final.html'); console.log('copy ' + src + ' ' + dest); this.fs.copytpl( this.templatepath(src), this.destinationpath(dest), this.props ); }, prepareapp: function () { this._directory(this.templatepath(), this.destinationroot('app')); }, preparedata: function () { this._directory(this.templatepath(), this.destinationroot('data')); }, writing: function () { this.prepareapp(); this.preparedata(); }, });
i find reason helper function _directory
called 4 times.
i expected function called twice, 1 app
, other folder data
, writing
function.
it turns out if prepend _
appendapp
, appenddata
, generator behave expected.
what want understand are:
1) don't seem find behaviour documented on yeoman website. behaviour ('calling every public method in subclass') expected?
2) if expected behaviour, how can control order these public methods called?
refer documentation: http://yeoman.io/authoring/running-context.html
each function in yeoman-generator task. tasks run automatically , ordered based on priorities (priority defined function/object name).
functions names starting underscore considered private , won't runned.
Comments
Post a Comment