javascript - Yeoman composeWith only calling constructor in subgenerator -
i'm trying use composewith
, call subgenerator within same generator package. yet reason, constructor of called generator invoked.
my generator-package generator-test
looks this:
package.json generators -- app -- index.js -- base -- index.js
my main generator in app
looks this:
'use strict'; var yeoman = require('yeoman-generator'); var yosay = require('yosay'); module.exports = yeoman.generators.base.extend({ constructor: function () { console.log('constructing app'); yeoman.generators.base.apply(this, arguments); }, initializing: function() { console.log('initializing app'); var done = this.async(); this.composewith('test:base',{ options: { } }) .on('end', function() { done(); }); } });
my subgenerator in base
:
'use strict'; var yeoman = require('yeoman-generator'); module.exports = yeoman.generators.base.extend({ constructor: function () { console.log('constructed base'); yeoman.generators.base.apply(this, arguments); }, initializing: function() { console.log('initialized base'); } });
this should generate 4 console outputs, yet getting first three:
constructing app initializing app constructed base
initialized base
never displayed. why? misunderstanding concept of composewith
?
or there way solve this?
this doesn't work because cannot wait end on composed generator.
calling this.async()
pausing run loop until callback called. in case, it's never going called because sub generator won't start running until callback called (but callback wait sub generator run). basically, you're dead locking node process.
composition in yeoman must independent. important generators stay decoupled. enforce this, yeoman-generator
don't offer flow control composition other run loop priorities.
you'll need rethink code , decouple generators.
Comments
Post a Comment