Skip to content

Commit

Permalink
Allow file writes in any run loop phases
Browse files Browse the repository at this point in the history
Fix #758
  • Loading branch information
SBoudrias committed Feb 15, 2015
1 parent eb229af commit 077577a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/base.js
Expand Up @@ -435,9 +435,14 @@ Base.prototype.run = function run(cb) {

methods.filter(methodIsValid).forEach(addInQueue);

this.env.runLoop.add('conflicts', this._writeFiles.bind(this), {
once: 'write memory fs to disk'
});
var writeFiles = function () {
this.env.runLoop.add('conflicts', this._writeFiles.bind(this), {
once: 'write memory fs to disk'
});
}.bind(this);

this.env.sharedFs.on('change', writeFiles);
writeFiles();

// Add the default conflicts handling
this.env.runLoop.add('conflicts', function (done) {
Expand Down
11 changes: 11 additions & 0 deletions test/base.js
Expand Up @@ -395,6 +395,17 @@ describe('generators.Base', function () {
};
this.testGen.run(done);
});

it('allows file writes in any priorities', function (done) {
this.TestGenerator.prototype.end = function () {
this.fs.write(this.destinationPath('foo.txt'), 'test');
};

this.testGen.run(function () {
assert(fs.existsSync(this.testGen.destinationPath('foo.txt')));
done();
}.bind(this));
});
});

describe('#_', function () {
Expand Down

0 comments on commit 077577a

Please sign in to comment.