From 23787e282df6cb7124274eadb73b9ef874e40996 Mon Sep 17 00:00:00 2001 From: Monstrofil Date: Sun, 13 Jun 2021 15:20:32 +0300 Subject: [PATCH] Add reqursive search for files --- bin/spritezero | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/bin/spritezero b/bin/spritezero index 3766992..fb4ac4d 100755 --- a/bin/spritezero +++ b/bin/spritezero @@ -10,16 +10,24 @@ var argv = require('minimist')(process.argv.slice(2), { boolean: ['retina', 'unique', 'h', 'help'] }); -function filepaths (dir) { - return fs.readdirSync(dir) - .filter(function (d) { - return !d.match(/^\./); - }) - .map(function (d) { - return path.join(dir, d); - }); +function filepaths(dir) { + var results = []; + var list = fs.readdirSync(dir); + list.forEach(function(file) { + file = dir + '/' + file; + var stat = fs.statSync(file); + if (stat && stat.isDirectory()) { + /* Recurse into a subdirectory */ + results = results.concat(filepaths(file)); + } else { + /* Is a file */ + results.push(file); + } + }); + return results; } + function showHelp () { console.log(multiline(function () { /* @@ -71,7 +79,6 @@ function sortById (a, b) { } var q = queue(16); - filepaths(input).forEach(function (file) { q.defer(loadFile, file); });