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

work in progress: try to get archiver running

parent f026c909
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,7 @@ var exec = require('child_process').exec; ...@@ -7,6 +7,7 @@ var exec = require('child_process').exec;
var fs = require('fs'); var fs = require('fs');
var path = require('path'); var path = require('path');
var Zip = require('node-zip'); var Zip = require('node-zip');
var archiver = require('archiver');
var exphbs = require('express-handlebars'); var exphbs = require('express-handlebars');
var logger = require('morgan'); var logger = require('morgan');
...@@ -33,7 +34,7 @@ app.set('view engine', '.hbs'); ...@@ -33,7 +34,7 @@ app.set('view engine', '.hbs');
//routes //routes
app.get('/', function(req, res){ 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){ ...@@ -41,22 +42,36 @@ app.post('/', function(req, res, next){
var checkedFiles = Object.keys(req.body); var checkedFiles = Object.keys(req.body);
if(typeof checkedFiles !== 'undefined' && checkedFiles.length > 0){ 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'); res.cookie('fileCookie', checkedFiles).render('download');
} }
else { else {
console.log('files were not checked');
res.render('home', {downloadFiles: downloadNames}); res.render('home', {downloadFiles: downloadNames});
} }
}); });
app.get('/download', function(req, res){ app.get('/download', function(req, res){
console.log("checkedFiles in /download", req.cookies.fileCookie);
// if (typeof req.body.backend !== 'undefined'){ req.cookies.fileCookie.forEach((fileName) => {
console.log("inside backend branch"); downloadURL = downloadFiles[fileName];
exec('cd /home/jweg/git/explorviz-ui-backend && mvn compile war:war', (error, stdout, stderr) => {
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 = var response =
'There was an error during your build. ' + 'There was an error during your build. ' +
...@@ -71,44 +86,98 @@ console.log("checkedFiles in /download", req.cookies.fileCookie); ...@@ -71,44 +86,98 @@ console.log("checkedFiles in /download", req.cookies.fileCookie);
console.log(stdout); console.log(stdout);
console.log(stderr); console.log(stderr);
var zip = new Zip();
zip.folder("frontend"); archive.file(fileName + '/target/explorviz-ui-backend-1.0-SNAPSHOT.war', {name:'backend/explorviz-backend.war'});
zip.folder("backend");
//-------------------------------------------------------------------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.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'));
var options = {base64: false, compression:'DEFLATE'}; //Plugins to install?
req.cookies.fileCookie.forEach((pluginName) => {
if (pluginName === /explorviz-frontend-plugin-*/){
exec('ember install'+ downloadFiles[pluginName], (error, stdout, stderr) => {
fs.writeFile('explorviz-builds.zip', zip.generate(options), 'binary', function (error) { var response =
'There was an error during your build. ' +
'Please contact "explorviz-developers-request@listserv.dfn.de" ' +
'and add the following information: ' + error;
if (error) { if (error) {
res.send(response);
return;
}
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. ' + 'There was an error during your build. ' +
'Please contact "explorviz-developers-request@listserv.dfn.de" ' + 'Please contact "explorviz-developers-request@listserv.dfn.de" ' +
'and add the following information: ' + error; 'and add the following information: ' + error;
console.log('stdout', stdout);
console.log('stderr', stderr);
if (error) {
res.send(response); res.send(response);
return; return;
}
console.log(stdout);
console.log(stderr);
}); // ------------------------------------------ember build
});
archive.directory('dist/', {name: 'frontend/dist'});
} else {
res.download('explorviz-builds.zip');
} }
//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");
// }
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment