//frontend was selected and the next step (streaming to zip) has to wait until the frontend is built
promiseArray.push(frontendAll());
finalizeZip(promiseArray);
})
}
promiseArray.push(frontendAll());
};
};
finalizeZip();
//TODO put all zip-things in zipFunctions.js;
//problem: createZip has to know the res from /download-route and if just the other functions will be exported, the zip has to be passed to createZip with resolve()
// create a file to stream archive data to.
constzip=newJSZip();
zip.file("README.txt","text for README");
letfinishedArray=[];
functionstreamFilesToZip(promiseArray){
functionstreamFilesToZip(){
console.log('in streamFilesToZip');
returnnewPromise((resolve,reject)=>{
letfinishedArray=[];
console.log('promiseArray in streamFilesToZip before Promise.all:',promiseArray);
Promise.all(promiseArray).then(files=>{
console.log('in Promise.all, files:',files);
...
...
@@ -165,10 +161,11 @@ function streamFilesToZip(promiseArray){
});
}
functionaddBackendToZip(data){
returnnewPromise(function(resolve,reject){
zip.file(file.zipFileName,data);
console.log('zip in addBackendToZip:',zip);
console.log('finishedArray in backend:',finishedArray);
resolve();
})
}
...
...
@@ -178,14 +175,11 @@ function streamFilesToZip(promiseArray){
backendContent.then(function(data){
addBackendToZip(data).then(function(){
resolve(finishedArray.push('backend finished'));
})
})
}
if(file.zipFileName==='frontend'){
constfrontendStream=fsReaddir(file.path)
...
...
@@ -198,29 +192,45 @@ function streamFilesToZip(promiseArray){
}
}).on('finish',function(){
console.log('zip in frontend:',zip);
resolve(finishedArray.push('frontend finished'));
console.log('finishedArray in frontend:',finishedArray);
})
}
})
})
if(finishedArray.length===files.length){
console.log('before resolve() in streamFilesToZip');