diff --git a/app.js b/app.js index 170539a379ec55cdb371fac1076785c0afb04f0d..1fdccbbecfbfff2d19b0b5c59e379208ea52682f 100644 --- a/app.js +++ b/app.js @@ -9,8 +9,7 @@ const fsReaddir = require('fs-readdir'); const JSZip = require('jszip'); const exphbs = require('express-handlebars'); -// global.jQuery = require('jquery'); -// const bootstrap = require('bootstrap'); + //initializer const initGitRepos = require('./initializers/gitRepos.js'); //load names of available download files @@ -29,17 +28,16 @@ app.use(bodyParser.urlencoded({ })); app.use(bodyParser.json()); - //set handlebars as view engine - app.engine('.hbs', exphbs({extname: '.hbs'})); - app.set('view engine', '.hbs'); +//set handlebars as view engine +app.engine('.hbs', exphbs({extname: '.hbs'})); +app.set('view engine', '.hbs'); //TODO add spinner for telling user to wait until initialization is done - //initGitRepos.initialize(downloadFiles); - //routes app.get('/', function(req, res){ + //initGitRepos.initialize(downloadFiles); res.render('home', {downloadFiles: downloadNames}); }); @@ -57,7 +55,7 @@ app.use(bodyParser.json()); app.get('/download', function(req, res, next){ - //holds promises for backend and/or frontend + //holds promises for backend and/or frontend for synchronizing const promiseArray = [] const checkedFiles = req.query.checkedFiles.split(','); @@ -69,63 +67,63 @@ app.use(bodyParser.json()); frontendChecked = checkedFiles.find(function(file){ return file === 'explorviz-ui-frontend'; }); +//the user is not allowed to check plugins without having checked frontend or backend +if(!(backendChecked || frontendChecked)){ + res.render('home', {downloadFiles: downloadNames}); +} - if(!(backendChecked || frontendChecked)){ - res.render('home', {downloadFiles: downloadNames}); - } - - if (backendChecked){ - - const fileName = backendChecked; +if (backendChecked){ - function backendAll(){ - return backendFunctions.backendClean(fileName).then(function(){ - return backendFunctions.backendPull(fileName).then(function(){ - return backendFunctions.backendInstallAddons(checkedFiles,downloadFiles).then(function(){ - return backendFunctions.backendBuild(fileName) - }) - }) - }).catch(function(error){ - let response = - 'There was an error during your backend build. ' + - 'Please contact "explorviz-developers-request@listserv.dfn.de" ' + - 'and add the following information: ' + error; - res.send(response); + const fileName = backendChecked; + function backendAll(){ + return backendFunctions.backendClean(fileName).then(function(){ + return backendFunctions.backendPull(fileName).then(function(){ + return backendFunctions.backendInstallAddons(checkedFiles,downloadFiles).then(function(){ + return backendFunctions.backendBuild(fileName) }) + }) + }).catch(function(error){ + let response = + 'There was an error during your backend build. ' + + 'Please contact "explorviz-developers-request@listserv.dfn.de" ' + + 'and add the following information: ' + error; + res.send(response); - } - promiseArray.push(backendAll()); + }) - } + } + promiseArray.push(backendAll()); - +} - if (frontendChecked){ - const fileName = frontendChecked; - const downloadURL = downloadFiles[frontendChecked]; - function frontendAll() { - return frontendFunctions.frontendClean(fileName).then(function(){ - return frontendFunctions.frontendPull(fileName).then(function(){ - return frontendFunctions.frontendInstallAddons(fileName, checkedFiles, downloadFiles).then(function(){ - return frontendFunctions.frontendBuild(fileName) - }) - }) - }).catch(function(error){ - let response = - 'There was an error during your frontend build. ' + - 'Please contact "explorviz-developers-request@listserv.dfn.de" ' + - 'and add the following information: ' + error; - res.send(response); +if (frontendChecked){ + const fileName = frontendChecked; + const downloadURL = downloadFiles[frontendChecked]; + + function frontendAll() { + return frontendFunctions.frontendClean(fileName).then(function(){ + return frontendFunctions.frontendPull(fileName).then(function(){ + return frontendFunctions.frontendInstallAddons(fileName, checkedFiles, downloadFiles).then(function(){ + return frontendFunctions.frontendBuild(fileName) }) - } - promiseArray.push(frontendAll()); + }) + }).catch(function(error){ + let response = + 'There was an error during your frontend build. ' + + 'Please contact "explorviz-developers-request@listserv.dfn.de" ' + + 'and add the following information: ' + error; + res.send(response); + + }) + } + promiseArray.push(frontendAll()); - }; +}; - finalizeZip(); +finalizeZip(); function finalizeZip(){ @@ -146,8 +144,15 @@ function createZip(zip){ console.log('error in createZip:', error); }).on('finish', function () { console.log('explorviz-builds.zip written.'); - res.download('explorviz-builds.zip'); - //how to redirect to home page? + res.download('explorviz-builds.zip', function(error){ + if(error){ + let response = + 'There was an error during your build. ' + + 'Please contact "explorviz-developers-request@listserv.dfn.de" ' + + 'and add the following information: ' + error; + res.send(response); + } + }); }); }) @@ -159,5 +164,6 @@ function createZip(zip){ }); -app.listen(3000); -console.log("Downloader started on port 3000."); \ No newline at end of file + + app.listen(3000); + console.log("Downloader started on port 3000."); \ No newline at end of file diff --git a/initializers/gitRepos.js b/initializers/gitRepos.js index d69b7cd8139064b97bd0d2f1b8cf07ff31cb968b..cc0f89b76306df5d353e457450b79f96b8eb52bb 100644 --- a/initializers/gitRepos.js +++ b/initializers/gitRepos.js @@ -89,12 +89,6 @@ var exec = require('child_process').exec; }; - -// module.exports = { -// initBackend, -// initBackendPlugins, -// initFrontend -// } module.exports = { initialize } \ No newline at end of file diff --git a/package.json b/package.json index 1ae2bde79eaa7083fe2c1a60a27cd49f12126ced..ec98e9a223a817e51515451f06d597de267eb080 100644 --- a/package.json +++ b/package.json @@ -10,15 +10,12 @@ "license": "Apache-2.0", "dependencies": { "body-parser": "^1.17.1", - "bootstrap": "^3.3.7", "child_process": "^1.0.2", "express": "^4.15.2", "express-handlebars": "^3.0.0", "fs": "0.0.1-security", "fs-readdir": "0.0.3", - "jquery": "^3.2.1", "jszip": "^3.1.3", - "node-zip": "^1.1.1", "path": "^0.12.7", "spinkit": "^1.2.5" },