From bb7dbb8a3fe098e13870b54cbde018d977c6d947 Mon Sep 17 00:00:00 2001 From: liam4 Date: Sun, 4 Jun 2017 12:23:51 -0300 Subject: Sort local crawl --- src/crawl-local.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/crawl-local.js b/src/crawl-local.js index d9a9a70..cd213e0 100644 --- a/src/crawl-local.js +++ b/src/crawl-local.js @@ -10,8 +10,14 @@ const readDir = promisify(fs.readdir) const stat = promisify(fs.stat) function crawl(dirPath) { - return readDir(dirPath).then( - res => Promise.all(res.map(item => { + return readDir(dirPath).then(items => { + items.sort((a, b) => { + const aUp = a.toUpperCase() + const bUp = b.toUpperCase() + return (aUp < bUp) ? -1 : (aUp == bUp) ? 0 : 1 + }) + + return Promise.all(items.map(item => { const itemPath = path.join(dirPath, item) return stat(itemPath).then(stats => { @@ -25,8 +31,8 @@ function crawl(dirPath) { return track } }) - }) - )) + })) + }) } if (process.argv.length === 2) { -- cgit 1.3.0-6-gf8a5