node.js - yeoman can't edit XML file that was created by other sub generator -
i'm trying make changes xml file in 1 sub generator created one.
my main generator prompting , determines subgenerators should used. simplyfied looks this:
var maingenerator = module.exports = yeoman.generators.base.extend({ writing: function () { this.composewith('design:setup', {}); if (this.option.get('someoption')) { this.composewith('design:extend', {}); } } });
the setup generator adds files used in every variation of design. example project config.xml
var setupgenerator = module.exports = yeoman.generators.base.extend({ default: function () { // ^ default: makes sure vssetup run before writing action // of other sub generators this.fs.copy( this.templatepath( 'project/_config.xml' ), this.destinationpath( 'project/config.xml' ) ); });
now, depending on settings user chose in prompts, different sub generators executed. when every add new folder destination, has updated in config.xml created setup generator.
var xml2js = require('xml2js'); var maingenerator = module.exports = yeoman.generators.base.extend({ writing: function () { var xmlparser = new xml2js.parser(); this.fs.read( 'project/config.xml', function (err, data) { console.log('read file'); console.dir(err); console.dir(data); xmlparser.parsestring(data, function (err, result) { console.log('parsed xml: ' + 'project/config.xml' ); console.dir(result); console.dir(err); }); }); } });
there no output @ fs read. no error, no nothing. ideas i'm doing wrong here?
because there different combinations of extending generators want have each generator register folders needs rather having unmaintainable hell of if else
statements in original xml file.
i haven't found documentation on events being emitted file system, or composewith
function, can hook end
event , read file then.
this.composewith('design:extend', {}) .on('end', function () { console.log(this.fs.read('path/to/file')); // file manipulation here });
it's not best way go modifying file after committed disk, , not in in memory editor, @ least place start.
Comments
Post a Comment