Forked from anonymous/gist:96332a3dc599c910bf289b9515eda7ea
Last active
October 17, 2016 17:41
-
-
Save joepie91/06ba1b51759728b8eaa5633b3cf8479c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const basename = require('basename'); | |
const Promise = require('bluebird'); | |
const globAsync = Promise.promisify(require('glob')); | |
const dir = 'a'; | |
function galleryListPromise() { | |
return Promise.try( () => { | |
return globAsync("gallery/*/", {}) | |
}).then((dirs) => { | |
const realdirs = {}; | |
dirs.forEach((x) => { | |
realdirs[basename(x)] = 1 | |
}); | |
return realdirs; | |
}); | |
} | |
function imageListPromise(galleryList) { | |
return Promise.try(() => { | |
if (galleryList[dir] === 1) { | |
return globAsync(`gallery/${dir}/*jpg`, {}); | |
} else { | |
return []; | |
} | |
}).then((imagelist) => { | |
return [galleryList, imagelist]; | |
}); | |
} | |
Promise.try(() => { | |
return galleryListPromise(); | |
}).then((galleryList) => { | |
return imageListPromise(galleryList); | |
}).then((imageList) => { | |
console.log(imageList); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment