Skip to content
Snippets Groups Projects
Commit 07391b69 authored by Josefine Wegert's avatar Josefine Wegert
Browse files

work in progress: adding promises for building zip

parent 2dd19a80
No related branches found
No related tags found
No related merge requests found
...@@ -66,10 +66,10 @@ if(typeof checkedFiles !== 'undefined' && checkedFiles.length > 0){ ...@@ -66,10 +66,10 @@ if(typeof checkedFiles !== 'undefined' && checkedFiles.length > 0){
app.get('/download', function(req, res){ app.get('/download', function(req, res){
const promiseArray = []
const checkedFiles = req.query.checkedFiles.split(','); const checkedFiles = req.query.checkedFiles.split(',');
var zip = new JSZip(); const zip = new JSZip();
// create a file to stream archive data to. // create a file to stream archive data to.
zip.file("README.txt", "text for README"); zip.file("README.txt", "text for README");
...@@ -86,25 +86,28 @@ if (backendChecked){ ...@@ -86,25 +86,28 @@ if (backendChecked){
const fileName = backendChecked; const fileName = backendChecked;
const downloadURL = downloadFiles[backendChecked]; const downloadURL = downloadFiles[backendChecked];
const backendPromise = new Promise((resolve, reject)=> {
exec('git pull ' + ' && cd ' + fileName + ' && mvn compile war:war ', (error, stdout, stderr) => { exec('git pull ' + ' && cd ' + fileName + ' && mvn compile war:war ', (error, stdout, stderr) => {
addBackend(); //addBackend();
var response =
'There was an error during your build. ' +
'Please contact "explorviz-developers-request@listserv.dfn.de" ' +
'and add the following information: ' + error;
console.log('error in exec', error);
if (error) { if (error) {
res.send(response); reject(error);
// res.send(response); beim promise.all
return; return;
} }
console.log(stdout); console.log(stdout);
console.log(stderr); console.log(stderr);
}); //.then(addBackend()), würde auch gehen (npm packet: exec-then), aber hilft nicht dabei, zu wissen, wann zip gebaut werden darf resolve({fileName:"backend.war", path:"explorviz-ui-backend/target/explorviz-ui-backend-1.0-SNAPSHOT.war"});
});
})
promiseArray.push(backendPromise);
console.log('promiseArray:',promiseArray);
} }
//--------------------------------------------------------------------------------frontend //--------------------------------------------------------------------------------frontend
...@@ -133,7 +136,7 @@ installAddons(); ...@@ -133,7 +136,7 @@ installAddons();
}; };
function installAddons(){ function installAddons(){
console.log('in installAddons()');
checkedPlugins = checkedFiles.filter(function(file){ checkedPlugins = checkedFiles.filter(function(file){
return /\bexplorviz-frontend-plugin-\w*/.exec(file); return /\bexplorviz-frontend-plugin-\w*/.exec(file);
}); });
...@@ -188,14 +191,14 @@ console.log(stderr); ...@@ -188,14 +191,14 @@ console.log(stderr);
}; // ------------------------------------------ember build }; // ------------------------------------------ember build
function addBackend(){ // function addBackend(){
// read a file as a stream and add it to a zip // // read a file as a stream and add it to a zip
console.log('addBackend()'); // console.log('addBackend()');
const backendStream = fs.createReadStream("explorviz-ui-backend/target/explorviz-ui-backend-1.0-SNAPSHOT.war"); // const backendStream = fs.createReadStream("explorviz-ui-backend/target/explorviz-ui-backend-1.0-SNAPSHOT.war");
zip.file("backend.war", backendStream); // zip.file("backend.war", backendStream);
backendFinished = true; // backendFinished = true;
createZip(); // createZip();
}; // };
function addFrontend(){ function addFrontend(){
console.log("in addFrontend"); console.log("in addFrontend");
...@@ -218,49 +221,48 @@ var stream = fsReaddir('./explorviz-ui-frontend/dist/') ...@@ -218,49 +221,48 @@ var stream = fsReaddir('./explorviz-ui-frontend/dist/')
function createZip(){ Promise.all(promiseArray).then(files => {
console.log('frontendFinished', frontendFinished); //if (files.fileName === "backend.war"){
console.log('backendFinished', backendFinished);
//if(frontendFinished){ console.log('files.path' ,files.path);
// if (frontendChecked){ console.log('files.fileName', files.fileName);
// if (backendChecked){
// if(frontendFinished && backendFinished){ backendStream = fs.createReadStream(files.path);
// console.log('both'); zip.file(files.fileName, backendStream);
//create zip and download it
zip.generateNodeStream({type:'nodebuffer',streamFiles:true}).pipe(fs.createWriteStream('explorviz-builds.zip')).on('finish', function () { zip.generateNodeStream({type:'nodebuffer',streamFiles:true}).pipe(fs.createWriteStream('explorviz-builds.zip')).on('finish', function () {
// JSZip generates a readable stream with a "end" event, console.log('explorviz-builds.zip written.');
// but is piped here in a writable stream which emits a "finish" event.
console.log("explorviz-builds.zip written.");
res.download('explorviz-builds.zip'); res.download('explorviz-builds.zip');
}); });
//} }).catch(function(error) {let response =
'There was an error during your build. ' +
'Please contact "explorviz-developers-request@listserv.dfn.de" ' +
'and add the following information: ' + error;
res.send(response);
})
};
// } else if (frontendFinished) {//!backendChecked
// console.log('frontend only');
// zip.generateNodeStream({type:'nodebuffer',streamFiles:true}).pipe(fs.createWriteStream('explorviz-builds.zip')).on('finish', function () {
// // JSZip generates a readable stream with a "end" event,
// // but is piped here in a writable stream which emits a "finish" event.
// console.log("explorviz-builds.zip frontend only written.");
// res.download('explorviz-builds.zip');
// });}
// function createZip(){
// console.log('frontendFinished', frontendFinished);
// console.log('backendFinished', backendFinished);
// } else if (backendChecked){//!frontendChecked
// if (backendFinished){
// console.log('backend only');
// //create zip and download it // //create zip and download it
// zip.generateNodeStream({type:'nodebuffer',streamFiles:true}).pipe(fs.createWriteStream('explorviz-builds.zip')).on('finish', function () { // zip.generateNodeStream({type:'nodebuffer',streamFiles:true}).pipe(fs.createWriteStream('explorviz-builds.zip')).on('finish', function () {
// // JSZip generates a readable stream with a "end" event, // // JSZip generates a readable stream with a "end" event,
// // but is piped here in a writable stream which emits a "finish" event. // // but is piped here in a writable stream which emits a "finish" event.
// console.log("explorviz-builds.zip backend only written."); // console.log("explorviz-builds.zip written.");
// res.download('explorviz-builds.zip'); // res.download('explorviz-builds.zip');
// }); // });
// }
// }
// } // };
}); });
app.listen(8080); app.listen(3000);
console.log("Downloader started on port 8080."); console.log("Downloader started on port 3000.");
\ No newline at end of file \ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment