From d0d54ebe4660db408454358fa96045b0c642b452 Mon Sep 17 00:00:00 2001 From: jweg <jweg@informatik.uni-kiel.de> Date: Tue, 13 Jun 2017 10:18:15 +0200 Subject: [PATCH] work in progress: queryParams introduced and structure changing --- app.js | 50 +++++++++++++++++++++++++++------------------- package.json | 1 + views/download.hbs | 5 ++++- 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/app.js b/app.js index 607a750..f5031ad 100644 --- a/app.js +++ b/app.js @@ -1,6 +1,5 @@ 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'); - - - -}); }); diff --git a/package.json b/package.json index 9167364..4bb0303 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/views/download.hbs b/views/download.hbs index d84a315..1bfd4ce 100644 --- a/views/download.hbs +++ b/views/download.hbs @@ -1,2 +1,5 @@ <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> -- GitLab