mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-24 14:43:08 +03:00
69d3a1460d
issue #1365 - added /*jslint unparam:true*/ to functions where absolutely necessary - added /*jslint unparam:true*/ to functions in which keeping parameter list added clarity to the underlying api, even when those parameters are not currently used - removed unused parameters in a few places
69 lines
2.0 KiB
JavaScript
69 lines
2.0 KiB
JavaScript
var when = require('when'),
|
|
keys = require('when/keys'),
|
|
fs = require('fs'),
|
|
path = require('path'),
|
|
extend = function (obj, source) {
|
|
var key;
|
|
for (key in source) {
|
|
if (source.hasOwnProperty(key)) {
|
|
obj[key] = source[key];
|
|
}
|
|
}
|
|
return obj;
|
|
},
|
|
readDir = function (dir, options, depth) {
|
|
depth = depth || 0;
|
|
|
|
options = extend({
|
|
index: true
|
|
}, options);
|
|
|
|
if (depth > 1) {
|
|
return null;
|
|
}
|
|
|
|
var subtree = {},
|
|
treeDeferred = when.defer(),
|
|
treePromise = treeDeferred.promise;
|
|
|
|
fs.readdir(dir, function (error, files) {
|
|
if (error) {
|
|
return treeDeferred.reject(error);
|
|
}
|
|
|
|
files = files || [];
|
|
|
|
files.forEach(function (file) {
|
|
var fileDeferred = when.defer(),
|
|
filePromise = fileDeferred.promise,
|
|
ext = path.extname(file),
|
|
name = path.basename(file, ext),
|
|
fpath = path.join(dir, file);
|
|
subtree[name] = filePromise;
|
|
fs.lstat(fpath, function (error, result) {
|
|
/*jslint unparam:true*/
|
|
if (result.isDirectory()) {
|
|
fileDeferred.resolve(readDir(fpath, options, depth + 1));
|
|
} else {
|
|
fileDeferred.resolve(fpath);
|
|
}
|
|
});
|
|
});
|
|
|
|
return keys.all(subtree).then(function (theFiles) {
|
|
return treeDeferred.resolve(theFiles);
|
|
});
|
|
});
|
|
|
|
return when(treePromise).then(function (prom) {
|
|
return prom;
|
|
});
|
|
},
|
|
readAll = function (dir, options, depth) {
|
|
return when(readDir(dir, options, depth)).then(function (paths) {
|
|
return paths;
|
|
});
|
|
};
|
|
|
|
module.exports = readAll;
|