diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/models/fs.js | 18 | ||||
-rw-r--r-- | lib/parse/listAssets.js | 25 |
2 files changed, 24 insertions, 19 deletions
diff --git a/lib/models/fs.js b/lib/models/fs.js index 12aee53..20c13ef 100644 --- a/lib/models/fs.js +++ b/lib/models/fs.js @@ -198,23 +198,29 @@ FS.prototype.listFiles = function(dirname) { /** List all files in a directory - @param {String} dirname + @param {String} dirName + @param {Function(dirName)} filterFn: call it for each file/directory to test if it should stop iterating @return {Promise<List<String>>} */ -FS.prototype.listAllFiles = function(folder) { +FS.prototype.listAllFiles = function(dirName, filterFn) { var that = this; - folder = folder || '.'; + dirName = dirName || '.'; - return this.readDir(folder) + return this.readDir(dirName) .then(function(files) { return Promise.reduce(files, function(out, file) { var isDirectory = pathIsFolder(file); + var newDirName = path.join(dirName, file); + + if (filterFn && filterFn(newDirName) === false) { + return out; + } if (!isDirectory) { - return out.push(path.join(folder, file)); + return out.push(newDirName); } - return that.listAllFiles(path.join(folder, file)) + return that.listAllFiles(newDirName, filterFn) .then(function(inner) { return out.concat(inner); }); diff --git a/lib/parse/listAssets.js b/lib/parse/listAssets.js index b2e141c..d83d8fd 100644 --- a/lib/parse/listAssets.js +++ b/lib/parse/listAssets.js @@ -23,21 +23,20 @@ function listAssets(book, pages) { var config = book.getConfig(); var configFile = config.getFile().getPath(); + function filterFile(file) { + return !( + file === summaryFile || + file === glossaryFile || + file === langsFile || + file === configFile || + book.isContentFileIgnored(file) || + pages.has(file) + ); + } + return timing.measure( 'parse.listAssets', - fs.listAllFiles() - .then(function(files) { - return files.filterNot(function(file) { - return ( - file === summaryFile || - file === glossaryFile || - file === langsFile || - file === configFile || - book.isContentFileIgnored(file) || - pages.has(file) - ); - }); - }) + fs.listAllFiles('.', filterFile) ); } |