async some functions

This commit is contained in:
Jonathan Rainville 2018-05-08 08:54:10 -04:00
parent e85d8b1ae5
commit 1d5f015aaa
2 changed files with 31 additions and 7 deletions

View File

@ -53,6 +53,10 @@ function existsSync() {
return fs.existsSync.apply(fs.existsSync, arguments); return fs.existsSync.apply(fs.existsSync, arguments);
} }
function access() {
return fs.access.apply(fs.access, arguments);
}
function removeSync() { function removeSync() {
return fs.removeSync.apply(fs.removeSync, arguments); return fs.removeSync.apply(fs.removeSync, arguments);
} }
@ -81,6 +85,7 @@ module.exports = {
writeFileSync, writeFileSync,
readJSONSync, readJSONSync,
writeJSONSync, writeJSONSync,
access,
existsSync, existsSync,
removeSync, removeSync,
embarkPath, embarkPath,

View File

@ -129,20 +129,39 @@ class Pipeline {
function changeCwdBack(next) { function changeCwdBack(next) {
process.chdir(realCwd); process.chdir(realCwd);
next(); 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) { if (err) {
process.chdir(realCwd); process.chdir(realCwd);
self.log(err); self.log(err);
return fileCb(err); return fileCb(err);
} }
if (!fs.existsSync('./.embark/' + file.filename)) {
self.log("couldn't find file: " + file.filename); fileCb(null, contentFile);
return fileCb("couldn't find file: " + file.filename);
}
let fileContent = fs.readFileSync('./.embark/' + file.filename).toString();
self.runPlugins(file, fileContent, fileCb);
}); });
} else { } else {
file.content(function(fileContent) { file.content(function(fileContent) {