mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 10:20:08 +00:00
migrated dir walker to new glob...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
246f00e5b1
commit
cf048fb3cf
@ -57,8 +57,8 @@ function(path, make){
|
|||||||
'error',
|
'error',
|
||||||
],
|
],
|
||||||
glob.glob(path))*/
|
glob.glob(path))*/
|
||||||
glob.glob(path)
|
glob.globStream(path)
|
||||||
.on('match', function(path){
|
.on('data', function(path){
|
||||||
fs.stat(path, function(err, stat){
|
fs.stat(path, function(err, stat){
|
||||||
if(err){
|
if(err){
|
||||||
make(fullpath ? path : path.split(/[\\\/]/).pop(), null, true)
|
make(fullpath ? path : path.split(/[\\\/]/).pop(), null, true)
|
||||||
@ -134,18 +134,12 @@ function(path, make){
|
|||||||
var _countDirFiles = function(path, file, elem){
|
var _countDirFiles = function(path, file, elem){
|
||||||
if(that.options.fileCountPattern){
|
if(that.options.fileCountPattern){
|
||||||
var i = 0
|
var i = 0
|
||||||
glob(path +'/'+ file +'/'+ that.options.fileCountPattern)
|
glob.globStream(path +'/'+ file +'/'+ that.options.fileCountPattern)
|
||||||
/*
|
.on('data', function(){
|
||||||
.on('match', function(){
|
i += 1 })
|
||||||
i += 1
|
.on('end', function(){
|
||||||
elem.attr('count', '('+ i +')')
|
i > 0
|
||||||
})
|
&& elem.attr('count', i) }) }
|
||||||
*/
|
|
||||||
.on('end', function(lst){
|
|
||||||
i += 1
|
|
||||||
elem.attr('count', lst.length)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return elem }
|
return elem }
|
||||||
|
|
||||||
return new Promise(function(resolve, reject){
|
return new Promise(function(resolve, reject){
|
||||||
@ -154,8 +148,7 @@ function(path, make){
|
|||||||
// XXX
|
// XXX
|
||||||
if(err){
|
if(err){
|
||||||
reject(err)
|
reject(err)
|
||||||
return
|
return }
|
||||||
}
|
|
||||||
var res = []
|
var res = []
|
||||||
|
|
||||||
if(that.options.dotDirs){
|
if(that.options.dotDirs){
|
||||||
@ -168,8 +161,7 @@ function(path, make){
|
|||||||
_countDirFiles(path, './',
|
_countDirFiles(path, './',
|
||||||
make(fullpath ? path + './' : './'))
|
make(fullpath ? path + './' : './'))
|
||||||
_countDirFiles(path, '../',
|
_countDirFiles(path, '../',
|
||||||
make(fullpath ? path + '../' : '../'))
|
make(fullpath ? path + '../' : '../')) }
|
||||||
}
|
|
||||||
|
|
||||||
// XXX split out the making stage after the stat stage to
|
// XXX split out the making stage after the stat stage to
|
||||||
// be able to sort suff correctly...
|
// be able to sort suff correctly...
|
||||||
@ -179,16 +171,14 @@ function(path, make){
|
|||||||
.catch(function(err){
|
.catch(function(err){
|
||||||
make(fullpath
|
make(fullpath
|
||||||
? path +'/'+ file
|
? path +'/'+ file
|
||||||
: file, null, true)
|
: file, null, true) })
|
||||||
})
|
|
||||||
.then(function(res){
|
.then(function(res){
|
||||||
// can't read stat... (XXX ???)
|
// can't read stat... (XXX ???)
|
||||||
if(res == null){
|
if(res == null){
|
||||||
make(fullpath
|
make(fullpath
|
||||||
? path +'/'+ file
|
? path +'/'+ file
|
||||||
: file, null, true)
|
: file, null, true)
|
||||||
return
|
return }
|
||||||
}
|
|
||||||
|
|
||||||
var dir = res.isDirectory()
|
var dir = res.isDirectory()
|
||||||
var elem = res
|
var elem = res
|
||||||
@ -207,8 +197,7 @@ function(path, make){
|
|||||||
// NOTE: we do not care how long it will take
|
// NOTE: we do not care how long it will take
|
||||||
// so we'll not wait...
|
// so we'll not wait...
|
||||||
res && dir && elem
|
res && dir && elem
|
||||||
&& _countDirFiles(path, file, elem)
|
&& _countDirFiles(path, file, elem) })
|
||||||
})
|
|
||||||
// NOTE: we are not using promise.all(..) here because it
|
// NOTE: we are not using promise.all(..) here because it
|
||||||
// triggers BEFORE the first make(..) is called...
|
// triggers BEFORE the first make(..) is called...
|
||||||
// ...not sure I fully understand why...
|
// ...not sure I fully understand why...
|
||||||
@ -219,14 +208,7 @@ function(path, make){
|
|||||||
// or by-design though...
|
// or by-design though...
|
||||||
res.push(file)
|
res.push(file)
|
||||||
if(res.length == files.length){
|
if(res.length == files.length){
|
||||||
resolve()
|
resolve() } }) }) }) }) } }
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE: this should work from a chrome app and does not require anything
|
// NOTE: this should work from a chrome app and does not require anything
|
||||||
// but fs access...
|
// but fs access...
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user