Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joepie91/06ba1b51759728b8eaa5633b3cf8479c to your computer and use it in GitHub Desktop.
Save joepie91/06ba1b51759728b8eaa5633b3cf8479c to your computer and use it in GitHub Desktop.
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