PairDrop/tasks/ensure-files.js
2017-02-05 17:53:21 -05:00

34 lines
603 B
JavaScript

var fs = require('fs');
/**
* @param {Array<string>} files
* @param {Function} cb
*/
function ensureFiles(files, cb) {
var missingFiles = files.reduce(function(prev, filePath) {
var fileFound = false;
try {
fileFound = fs.statSync(filePath).isFile();
} catch (e) { }
if (!fileFound) {
prev.push(filePath + ' Not Found');
}
return prev;
}, []);
if (missingFiles.length) {
var err = new Error('Missing Required Files\n' + missingFiles.join('\n'));
}
if (cb) {
cb(err);
} else if (err) {
throw err;
}
}
module.exports = ensureFiles;