diff --git a/app.js b/app.js index 8caedcc11eee3caa2f19736b0bf90d43da054c58..e43fc72f75a3396bb6f0004b7152eda2ce75d9d0 100644 --- a/app.js +++ b/app.js @@ -70,82 +70,78 @@ app.use(bodyParser.json()); const promiseArray = [] const checkedFiles = req.query.checkedFiles.split(','); - - backendChecked = checkedFiles.find(function(file){ - return file === 'explorviz-ui-backend'; - }); - if (backendChecked){ + backendChecked = checkedFiles.find(function(file){ + return file === 'explorviz-ui-backend'; + }); + + if (backendChecked){ - const fileName = backendChecked; + const fileName = backendChecked; - function backendAll(){ - return backendFunctions.backendClean(fileName).then(function(){ - return backendFunctions.backendPull(fileName).then(function(){ - return backendFunctions.backendInstallAddons(checkedFiles,downloadFiles).then(function(){ - return backendFunctions.backendBuild(fileName) + function backendAll(){ + return backendFunctions.backendClean(fileName).then(function(){ + return backendFunctions.backendPull(fileName).then(function(){ + return backendFunctions.backendInstallAddons(checkedFiles,downloadFiles).then(function(){ + return backendFunctions.backendBuild(fileName) + }) }) + }).catch(function(error){ + let response = + 'There was an error during your backend build. ' + + 'Please contact "explorviz-developers-request@listserv.dfn.de" ' + + 'and add the following information: ' + error; + res.send(response); + }) - }).catch(function(error){ - let response = - 'There was an error during your backend build. ' + - 'Please contact "explorviz-developers-request@listserv.dfn.de" ' + - 'and add the following information: ' + error; - res.send(response); - }) + } + promiseArray.push(backendAll()); - } - promiseArray.push(backendAll()); - console.log('promiseArray in backendChecked:', promiseArray); - finalizeZip(promiseArray); - - } - - frontendChecked = checkedFiles.find(function(file){ - return file === 'explorviz-ui-frontend'; - }); + } - if (frontendChecked){ - const fileName = frontendChecked; - const downloadURL = downloadFiles[frontendChecked]; + frontendChecked = checkedFiles.find(function(file){ + return file === 'explorviz-ui-frontend'; + }); - function frontendAll() { - return frontendFunctions.frontendClean(fileName).then(function(){ - return frontendFunctions.frontendPull(fileName).then(function(){ - return frontendFunctions.frontendInstallAddons(checkedFiles, downloadFiles).then(function(){ - return frontendFunctions.frontendBuild(fileName) + if (frontendChecked){ + const fileName = frontendChecked; + const downloadURL = downloadFiles[frontendChecked]; + + function frontendAll() { + return frontendFunctions.frontendClean(fileName).then(function(){ + return frontendFunctions.frontendPull(fileName).then(function(){ + return frontendFunctions.frontendInstallAddons(checkedFiles, downloadFiles).then(function(){ + return frontendFunctions.frontendBuild(fileName) + }) }) - }) - }).catch(function(error){ - let response = - 'There was an error during your frontend build. ' + - 'Please contact "explorviz-developers-request@listserv.dfn.de" ' + - 'and add the following information: ' + error; - res.send(response); + }).catch(function(error){ + let response = + 'There was an error during your frontend build. ' + + 'Please contact "explorviz-developers-request@listserv.dfn.de" ' + + 'and add the following information: ' + error; + res.send(response); - }) - } -//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. const zip = new JSZip(); zip.file("README.txt", "text for README"); +let finishedArray=[]; - -function streamFilesToZip(promiseArray){ +function streamFilesToZip(){ console.log('in streamFilesToZip'); return new Promise((resolve,reject)=> { - let finishedArray=[]; - 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){ }); } - function addBackendToZip(data){ return new Promise(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'){ const frontendStream = 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'); - resolve(); - } }) -}; +} + +function collectFilesToZip(finishedArray){ + console.log('in collectFilesToZip'); + console.log('finishedArray.length:', finishedArray.length); + console.log('promiseArray.length:', promiseArray.length); + return new Promise((resolve,reject)=> { + if(finishedArray.length === promiseArray.length){ + console.log('in resolve()'); + resolve(zip); + } + }) +} -function finalizeZip(promiseArray){ - - return streamFilesToZip(promiseArray).then(function(){ - return createZip() +function finalizeZip(){ + return streamFilesToZip().then(function(){ + return collectFilesToZip(finishedArray).then(function(zip){ + + return createZip(zip) + }) }).catch(function(error) {let response = 'There was an error during your build. ' + 'Please contact "explorviz-developers-request@listserv.dfn.de" ' + @@ -230,9 +240,8 @@ function finalizeZip(promiseArray){ } -function createZip(){ +function createZip(zip){ console.log('in createZip'); - return new Promise((resolve,reject) => { zip.generateNodeStream({type:'nodebuffer',streamFiles:true}).pipe(fs.createWriteStream('explorviz-builds.zip')).on('error', function(error){ console.log('error in createZip:', error); diff --git a/backendFunctions.js b/backendFunctions.js index aa223d60bf324600a0f52e973ed58cdf7500ccf7..85a9e9a0f622994c50790b37a7f88948401f48d2 100644 --- a/backendFunctions.js +++ b/backendFunctions.js @@ -51,7 +51,6 @@ function backendInstallAddons(checkedFiles,downloadFiles){ if(checkedPlugins.length !== 0 ){ checkedPlugins.forEach((pluginName) => { - exec('cd '+ pluginName + ' git pull ' + '&& rsync -av . ' + ' ../explorviz-ui-backend/plugins/net/explorviz/plugins/ ' + ' --exclude .git', (error, stdout, stderr) => { //'cd explorviz-ui-backend/plugins/net/explorviz/plugins/ ' + if (error) {