diff options
author | liam4 <towerofnix@gmail.com> | 2017-06-04 12:23:51 -0300 |
---|---|---|
committer | liam4 <towerofnix@gmail.com> | 2017-06-04 12:23:51 -0300 |
commit | bb7dbb8a3fe098e13870b54cbde018d977c6d947 (patch) | |
tree | 541f0b2527fdc45e681f0625e63bc2e20eff14d0 /src | |
parent | 9fcf30b57a7a8f0fc86f1187d2cad72e8eaaa37e (diff) |
Sort local crawl
Diffstat (limited to 'src')
-rw-r--r-- | src/crawl-local.js | 14 |
1 files changed, 10 insertions, 4 deletions
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) { |