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

work in progress: queryParams introduced and structure changing

parent abc7ae3d
No related branches found
No related tags found
No related merge requests found
var express = require('express'); var express = require('express');
var bodyParser = require('body-parser'); var bodyParser = require('body-parser');
var cookieParser = require('cookie-parser');
var exec = require('child_process').exec; var exec = require('child_process').exec;
...@@ -23,7 +22,6 @@ app.use(bodyParser.urlencoded({ ...@@ -23,7 +22,6 @@ app.use(bodyParser.urlencoded({
})); }));
app.use(bodyParser.json()); app.use(bodyParser.json());
app.use(logger("short")); app.use(logger("short"));
app.use(cookieParser());
//set handlebars as view engine //set handlebars as view engine
...@@ -34,16 +32,15 @@ app.set('view engine', '.hbs'); ...@@ -34,16 +32,15 @@ app.set('view engine', '.hbs');
//routes //routes
app.get('/', function(req, res){ app.get('/', function(req, res){
res.clearCookie(req.cookies.fileCookie).render('home', {downloadFiles: downloadNames}); res.render('home', {downloadFiles: downloadNames});
}); });
app.post('/', function(req, res, next){ app.post('/', function(req, res, next){
var checkedFiles = Object.keys(req.body); const checkedFiles = Object.keys(req.body);
if(typeof checkedFiles !== 'undefined' && checkedFiles.length > 0){ if(typeof checkedFiles !== 'undefined' && checkedFiles.length > 0){
//set cookie to pass checked files for download res.render('download', {checkedFiles: checkedFiles});
res.cookie('fileCookie', checkedFiles).render('download');
} }
else { else {
res.render('home', {downloadFiles: downloadNames}); res.render('home', {downloadFiles: downloadNames});
...@@ -53,8 +50,7 @@ if(typeof checkedFiles !== 'undefined' && checkedFiles.length > 0){ ...@@ -53,8 +50,7 @@ if(typeof checkedFiles !== 'undefined' && checkedFiles.length > 0){
app.get('/download', function(req, res){ app.get('/download', function(req, res){
req.cookies.fileCookie.forEach((fileName) => { const checkedFiles = req.query.checkedFiles.split(',');
downloadURL = downloadFiles[fileName];
var zip = new Zip(); var zip = new Zip();
// create a file to stream archive data to. // create a file to stream archive data to.
...@@ -69,8 +65,13 @@ var archive = archiver('zip', { ...@@ -69,8 +65,13 @@ var archive = archiver('zip', {
archive.append(fs.readFileSync(path.join(__dirname, 'README.txt')), {name: 'README.txt'}); archive.append(fs.readFileSync(path.join(__dirname, 'README.txt')), {name: 'README.txt'});
//----------------------------------------------------------------backend //----------------------------------------------------------------backend
if (fileName === 'explorviz-ui-backend'){ backendChecked = checkedFiles.find(function(file){
return file === 'explorviz-ui-backend';
});
if (backendChecked){
const fileName = backendChecked;
const downloadURL = downloadFiles[backendChecked];
exec('git clone ' + downloadURL + ' ' + fileName + ' && cd ' + fileName + ' && mvn compile war:war ', (error, stdout, stderr) => { exec('git clone ' + downloadURL + ' ' + fileName + ' && cd ' + fileName + ' && mvn compile war:war ', (error, stdout, stderr) => {
var response = var response =
...@@ -89,9 +90,19 @@ if (fileName === 'explorviz-ui-backend'){ ...@@ -89,9 +90,19 @@ if (fileName === 'explorviz-ui-backend'){
archive.file(fileName + '/target/explorviz-ui-backend-1.0-SNAPSHOT.war', {name:'backend/explorviz-backend.war'}); archive.file(fileName + '/target/explorviz-ui-backend-1.0-SNAPSHOT.war', {name:'backend/explorviz-backend.war'});
//-------------------------------------------------------------------frontend
}); });
} else if (fileName === 'explorviz-ui-frontend'){ }
//--------------------------------------------------------------------------------frontend
frontendChecked = checkedFiles.find(function(file){
return file === 'explorviz-ui-frontend';
});
if (frontendChecked){
const fileName = frontendChecked;
const downloadURL = downloadFiles[frontendChecked];
exec('git clone ' + downloadURL + ' ' + fileName + ' && cd '+ fileName + ' && npm install', (error, stdout, stderr) => { exec('git clone ' + downloadURL + ' ' + fileName + ' && cd '+ fileName + ' && npm install', (error, stdout, stderr) => {
console.log('downloadURL', downloadURL); console.log('downloadURL', downloadURL);
console.log('fileName', fileName); console.log('fileName', fileName);
...@@ -108,8 +119,12 @@ console.log('stderr', stderr); ...@@ -108,8 +119,12 @@ console.log('stderr', stderr);
//Plugins to install? //Plugins to install?
req.cookies.fileCookie.forEach((pluginName) => {
if (pluginName === /explorviz-frontend-plugin-*/){ checkedPlugins = checkedFiles.filter(function(file){
});
checkedPlugins.forEach((pluginName) => {
exec('ember install'+ downloadFiles[pluginName], (error, stdout, stderr) => { exec('ember install'+ downloadFiles[pluginName], (error, stdout, stderr) => {
var response = var response =
...@@ -127,8 +142,7 @@ console.log(stderr); ...@@ -127,8 +142,7 @@ console.log(stderr);
}); });
}; });
});//-----------------------------plugin-forEach
//build everything you have //build everything you have
exec('ember build --environment production', (error, stdout, stderr) => { exec('ember build --environment production', (error, stdout, stderr) => {
...@@ -175,10 +189,6 @@ archive.pipe(output); ...@@ -175,10 +189,6 @@ archive.pipe(output);
res.download('explorviz-builds.zip'); res.download('explorviz-builds.zip');
});
}); });
app.listen(8080); app.listen(8080);
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {
"adm-zip": "^0.4.7", "adm-zip": "^0.4.7",
"archiver": "^1.3.0",
"body-parser": "^1.17.1", "body-parser": "^1.17.1",
"child_process": "^1.0.2", "child_process": "^1.0.2",
"cookie-parser": "^1.4.3", "cookie-parser": "^1.4.3",
......
<div class="container">Your download is being prepared. This may take a moment. Do not close the window.</div> <div class="container">Your download is being prepared. This may take a moment. Do not close the window.</div>
<script> location.href="/download" </script> {{#each checkedFiles as |file|}}
{{/each}}
<script> location.href="/download?checkedFiles={{checkedFiles}}" </script>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment