From 1fe6f4ee2c47b668f51350bcf5f163083767c1f7 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Tue, 8 May 2018 09:02:46 -0400 Subject: [PATCH] more async --- lib/core/fs.js | 5 +++++ lib/pipeline/pipeline.js | 30 +++++++++++++++--------------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/lib/core/fs.js b/lib/core/fs.js index d8f8348f..81e8e725 100644 --- a/lib/core/fs.js +++ b/lib/core/fs.js @@ -11,6 +11,10 @@ function mkdirp() { return fs.mkdirp.apply(fs.mkdirp, arguments); } +function copy() { + return fs.copy.apply(fs.copy, arguments); +} + function copySync() { return fs.copySync.apply(fs.copySync, arguments); } @@ -77,6 +81,7 @@ function createWriteStream() { module.exports = { mkdirpSync, mkdirp, + copy, copySync, readFile, readFileSync, diff --git a/lib/pipeline/pipeline.js b/lib/pipeline/pipeline.js index 7df8e59e..2d16ea76 100644 --- a/lib/pipeline/pipeline.js +++ b/lib/pipeline/pipeline.js @@ -185,28 +185,28 @@ class Pipeline { targetDir = targetDir + '/'; } - contentFiles.map(function (file) { + async.each(contentFiles, function (file, mapCb) { let filename = file.filename.replace(file.basedir + '/', ''); self.log("writing file " + (self.buildDir + targetDir + filename).bold.dim); - fs.copySync(file.path, self.buildDir + targetDir + filename, {overwrite: true}); - }); - } else { - let content = contentFiles.map(function (file) { - if (file === undefined) { - return ""; - } - return file.content; - }).join("\n"); - - self.log("writing file " + (self.buildDir + targetFile).bold.dim); - fs.writeFileSync(self.buildDir + targetFile, content); + fs.copy(file.path, self.buildDir + targetDir + filename, {overwrite: true}, mapCb); + }, cb); + return; } - cb(); + + let content = contentFiles.map(function (file) { + if (file === undefined) { + return ""; + } + return file.content; + }).join("\n"); + + self.log("writing file ASYNC " + (self.buildDir + targetFile).bold.dim); + fs.writeFile(self.buildDir + targetFile, content, cb); } ); }, - function (_err, _results) { + function (_err) { callback(); }); });