diff --git a/lib/core/fs.js b/lib/core/fs.js index 73f8231a..d8f8348f 100644 --- a/lib/core/fs.js +++ b/lib/core/fs.js @@ -53,6 +53,10 @@ function existsSync() { return fs.existsSync.apply(fs.existsSync, arguments); } +function access() { + return fs.access.apply(fs.access, arguments); +} + function removeSync() { return fs.removeSync.apply(fs.removeSync, arguments); } @@ -81,6 +85,7 @@ module.exports = { writeFileSync, readJSONSync, writeJSONSync, + access, existsSync, removeSync, embarkPath, diff --git a/lib/pipeline/pipeline.js b/lib/pipeline/pipeline.js index 56748945..7df8e59e 100644 --- a/lib/pipeline/pipeline.js +++ b/lib/pipeline/pipeline.js @@ -129,20 +129,39 @@ class Pipeline { function changeCwdBack(next) { process.chdir(realCwd); next(); + }, + + function checkFile(next) { + fs.access('./.embark/' + file.filename, (err) => { + if (err) { + self.log("couldn't find file: " + file.filename); + return next("couldn't find file: " + file.filename); + } + next(); + }); + }, + + function readFile(next) { + fs.readFile('./.embark/' + file.filename, (err, data) => { + if (err) { + return next(err); + } + next(null, data.toString()); + }); + }, + + function runPluginsOnContent(fileContent, next) { + self.runPlugins(file, fileContent, next); } - ], function(err, _result) { + ], function(err, contentFile) { if (err) { process.chdir(realCwd); self.log(err); return fileCb(err); } - if (!fs.existsSync('./.embark/' + file.filename)) { - self.log("couldn't find file: " + file.filename); - return fileCb("couldn't find file: " + file.filename); - } - let fileContent = fs.readFileSync('./.embark/' + file.filename).toString(); - self.runPlugins(file, fileContent, fileCb); + + fileCb(null, contentFile); }); } else { file.content(function(fileContent) {