Skip to content

Instantly share code, notes, and snippets.

Created October 17, 2016 17:33
Show Gist options
  • Save anonymous/96332a3dc599c910bf289b9515eda7ea to your computer and use it in GitHub Desktop.
Save anonymous/96332a3dc599c910bf289b9515eda7ea to your computer and use it in GitHub Desktop.
const basename = require('basename');
//const glob = require('glob');
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.map( 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];
}
);
}
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