Reputation: 1
Hello so i'm trying to execute 3 things in order.
Generating and zipping the images is working fine, but when I go to email them, the zip file hasn't been populated so it's just sending an empty zip. Any tips here?
rowData().then(res => {
let functionArray;
if(client == 'TCS'){
functionArray = TCSFunctionArray;
} else{
console.log('Please enter a valid client name');
}
let images = [];
//generating all the images
for(let i = 0; i < res.length; i++){
for(let j = 0; j < functionArray.length; j++){
images.push(nodeHtmlToImage({
output: `${PATH}/row_${i+2}_${functionArray[j].name}.png`,
html: functionArray[j](res[i]).html,
puppeteerArgs: {defaultViewport: {height: functionArray[j](res[i]).height,
width: functionArray[j](res[i]).width,
deviceScaleFactor: 2}, args: ["--no-sandbox"]}
}))
}
}
return Promise.all(images);
}).then(() => {
zipBanners(PATH, dest)
}).then(() => {
emailBanners(dest)
})
function zipBanners(sourceFolder, dest){
tar.c(
{
gzip: true
},
[sourceFolder]
).pipe(fs.createWriteStream(dest));
}
Upvotes: 0
Views: 29
Reputation: 1266
If your zipBanners returns a promise, make sure you return it for your third then
call:
return zipBanners(PATH, dest)
Otherwise, you're just saying to start running the zipBanners function and then immediately go to the emailing part of your promise chain even though zip file hasn't been populated yet.
Upvotes: 1