Skip to content

Commit

Permalink
Merge pull request #270 from stephenplusplus/conflicter
Browse files Browse the repository at this point in the history
base/run async conflicter resolved.
  • Loading branch information
passy committed Jun 4, 2013
2 parents 5c38867 + 202d29a commit 61bb176
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
25 changes: 15 additions & 10 deletions lib/actions/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var events = require('events');
var mkdirp = require('mkdirp');
var isBinaryFile = require('isbinaryfile');
var rimraf = require('rimraf');
var async = require('async');

var actions = module.exports;

Expand Down Expand Up @@ -216,23 +217,27 @@ actions.engine = function engine(body, data) {
// Returns the generator instance
actions.directory = function directory(source, destination) {
var root = path.join(this.sourceRoot(), source);
var list = this.expandFiles('**', { dot: true, cwd: root });
var files = this.expandFiles('**', { dot: true, cwd: root });
var self = this;

destination = destination || source;

// get the path relative to the template root, and copy to the relative destination
(function next(filepath) {
if (!filepath) {
self.emit('directory:end');
return;
}
var resolveFiles = function (filepath) {
return function (next) {
if (!filepath) {
self.emit('directory:end');
return next();
}

var dest = path.join(destination, filepath);
self.copy(path.join(root, filepath), dest);
var dest = path.join(destination, filepath);
self.copy(path.join(root, filepath), dest);

return next();
};
};

return next(list.shift());
})(list.shift());
async.parallel(files.map(resolveFiles));

return this;
};
Expand Down
19 changes: 11 additions & 8 deletions lib/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,23 +249,26 @@ Base.prototype.run = function run(args, cb) {
return next();
}

var done = function () {
self.conflicter.resolve(function (err) {
if (err) {
return self.emit('error', err);
}
});
next();
};

self.async = function () {
self.async.running = true;
return next;
return done;
};

self.emit(method);
self.emit('method', method);
self[method].apply(self, args);

conflicter.resolve(function (err) {
if (err) {
return self.emit('error', err);
}
});

if (!self.async.running) {
next();
done();
}
};
};
Expand Down

0 comments on commit 61bb176

Please sign in to comment.