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 bodyParser = require('body-parser');
var cookieParser = require('cookie-parser');
var exec = require('child_process').exec;
......@@ -23,7 +22,6 @@ app.use(bodyParser.urlencoded({
}));
app.use(bodyParser.json());
app.use(logger("short"));
app.use(cookieParser());
//set handlebars as view engine
......@@ -34,16 +32,15 @@ app.set('view engine', '.hbs');
//routes
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){
var checkedFiles = Object.keys(req.body);
const checkedFiles = Object.keys(req.body);
if(typeof checkedFiles !== 'undefined' && checkedFiles.length > 0){
//set cookie to pass checked files for download
res.cookie('fileCookie', checkedFiles).render('download');
res.render('download', {checkedFiles: checkedFiles});
}
else {
res.render('home', {downloadFiles: downloadNames});
......@@ -53,8 +50,7 @@ if(typeof checkedFiles !== 'undefined' && checkedFiles.length > 0){
app.get('/download', function(req, res){
req.cookies.fileCookie.forEach((fileName) => {
downloadURL = downloadFiles[fileName];
const checkedFiles = req.query.checkedFiles.split(',');
var zip = new Zip();
// create a file to stream archive data to.
......@@ -69,8 +65,13 @@ var archive = archiver('zip', {
archive.append(fs.readFileSync(path.join(__dirname, 'README.txt')), {name: 'README.txt'});
//----------------------------------------------------------------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) => {
var response =
......@@ -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'});
//-------------------------------------------------------------------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) => {
console.log('downloadURL', downloadURL);
console.log('fileName', fileName);
......@@ -108,8 +119,12 @@ console.log('stderr', stderr);
//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) => {
var response =
......@@ -127,8 +142,7 @@ console.log(stderr);
});
};
});//-----------------------------plugin-forEach
});
//build everything you have
exec('ember build --environment production', (error, stdout, stderr) => {
......@@ -174,10 +188,6 @@ archive.pipe(output);
res.download('explorviz-builds.zip');
});
});
......
......@@ -10,6 +10,7 @@
"license": "Apache-2.0",
"dependencies": {
"adm-zip": "^0.4.7",
"archiver": "^1.3.0",
"body-parser": "^1.17.1",
"child_process": "^1.0.2",
"cookie-parser": "^1.4.3",
......
<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.
Finish editing this message first!
Please register or to comment