diff --git a/app.js b/app.js index 3b92e43ccf09eee04cbc7b65b85fd726c058501b..607a7509993606edb272d3c065c207137976c71d 100644 --- a/app.js +++ b/app.js @@ -7,6 +7,7 @@ var exec = require('child_process').exec; var fs = require('fs'); var path = require('path'); var Zip = require('node-zip'); +var archiver = require('archiver'); var exphbs = require('express-handlebars'); var logger = require('morgan'); @@ -33,7 +34,7 @@ app.set('view engine', '.hbs'); //routes app.get('/', function(req, res){ -res.render('home', {downloadFiles: downloadNames}); +res.clearCookie(req.cookies.fileCookie).render('home', {downloadFiles: downloadNames}); }); @@ -41,22 +42,36 @@ app.post('/', function(req, res, next){ var checkedFiles = Object.keys(req.body); if(typeof checkedFiles !== 'undefined' && checkedFiles.length > 0){ - console.log('files were checked'); - //set cookie to pass checked files for download + //set cookie to pass checked files for download res.cookie('fileCookie', checkedFiles).render('download'); } else { - console.log('files were not checked'); res.render('home', {downloadFiles: downloadNames}); } }); app.get('/download', function(req, res){ -console.log("checkedFiles in /download", req.cookies.fileCookie); - // if (typeof req.body.backend !== 'undefined'){ - console.log("inside backend branch"); - exec('cd /home/jweg/git/explorviz-ui-backend && mvn compile war:war', (error, stdout, stderr) => { + +req.cookies.fileCookie.forEach((fileName) => { +downloadURL = downloadFiles[fileName]; + +var zip = new Zip(); +// create a file to stream archive data to. +var output = fs.createWriteStream(__dirname + 'explorviz-builds.zip'); + +var archive = archiver('zip', { + base64: false, + compression:'DEFLATE', + store: true // Sets the compression method to STORE. +}); + +archive.append(fs.readFileSync(path.join(__dirname, 'README.txt')), {name: 'README.txt'}); + +//----------------------------------------------------------------backend +if (fileName === 'explorviz-ui-backend'){ + + exec('git clone ' + downloadURL + ' ' + fileName + ' && cd ' + fileName + ' && mvn compile war:war ', (error, stdout, stderr) => { var response = 'There was an error during your build. ' + @@ -71,44 +86,98 @@ console.log("checkedFiles in /download", req.cookies.fileCookie); console.log(stdout); console.log(stderr); - var zip = new Zip(); + + archive.file(fileName + '/target/explorviz-ui-backend-1.0-SNAPSHOT.war', {name:'backend/explorviz-backend.war'}); + +//-------------------------------------------------------------------frontend + }); +} else if (fileName === 'explorviz-ui-frontend'){ +exec('git clone ' + downloadURL + ' ' + fileName + ' && cd '+ fileName + ' && npm install', (error, stdout, stderr) => { +console.log('downloadURL', downloadURL); +console.log('fileName', fileName); + 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('stdout', stdout); +console.log('stderr', stderr); + if (error) { + res.send(response); + return; + } - zip.folder("frontend"); - zip.folder("backend"); - zip.file('README.txt', fs.readFileSync(path.join(__dirname, 'README.txt'))); - zip.file('explorviz-backend.war', - fs.readFileSync('/home/jweg/git/explorviz-ui-backend/target/explorviz-ui-backend-1.0-SNAPSHOT.war')); +//Plugins to install? + req.cookies.fileCookie.forEach((pluginName) => { +if (pluginName === /explorviz-frontend-plugin-*/){ + exec('ember install'+ downloadFiles[pluginName], (error, stdout, stderr) => { + + var response = + 'There was an error during your build. ' + + 'Please contact "explorviz-developers-request@listserv.dfn.de" ' + + 'and add the following information: ' + error; - var options = {base64: false, compression:'DEFLATE'}; + if (error) { + res.send(response); + return; + } - fs.writeFile('explorviz-builds.zip', zip.generate(options), 'binary', function (error) { - - if(error) { +console.log(stdout); +console.log(stderr); + + }); + +}; +});//-----------------------------plugin-forEach + +//build everything you have +exec('ember build --environment production', (error, stdout, stderr) => { - var response = + 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('stdout', stdout); +console.log('stderr', stderr); + if (error) { + res.send(response); + return; + } + +console.log(stdout); +console.log(stderr); + - res.send(response); - return; + }); // ------------------------------------------ember build +}); +archive.directory('dist/', {name: 'frontend/dist'}); + +} - } else { +//create zip and download it + +// listen for all archive data to be written +output.on('close', function() { + console.log(archive.pointer() + ' total bytes'); + console.log('archiver has been finalized and the output file descriptor has closed.'); +}); + +// good practice to catch this error explicitly +archive.on('error', function(err) { + throw err; +}); + +archive.pipe(output); + archive.finalize(); + + + + res.download('explorviz-builds.zip'); - } + - }); - - }); -// } -// else if (typeof req.body.frontend !== 'undefined'){ -// console.log("inside frontend branch"); -// res.send(req.body.frontend); -// } else { -// console.log("inside else branch"); -// res.send("nix ausgewählt"); -// } + +}); });