From 202d29aa88dacab7f7ed9da71c288874696ba6b4 Mon Sep 17 00:00:00 2001 From: Stephen Sawchuk Date: Tue, 4 Jun 2013 17:59:32 -0400 Subject: [PATCH] base/run async conflicter resolved. --- lib/actions/actions.js | 25 +++++++++++++++---------- lib/base.js | 19 +++++++++++-------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/lib/actions/actions.js b/lib/actions/actions.js index 152fe50f..c80fa4a1 100644 --- a/lib/actions/actions.js +++ b/lib/actions/actions.js @@ -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; @@ -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; }; diff --git a/lib/base.js b/lib/base.js index 30b23938..a25392cc 100644 --- a/lib/base.js +++ b/lib/base.js @@ -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(); } }; };