Skip to content

Commit

Permalink
Merge pull request #152 from FIWARE-TMForum/develop
Browse files Browse the repository at this point in the history
Merge develop for version 6.4.0
  • Loading branch information
fdelavega authored Dec 14, 2017
2 parents b96044e + c55cb98 commit 808f4bf
Show file tree
Hide file tree
Showing 139 changed files with 7,098 additions and 2,774 deletions.
119 changes: 119 additions & 0 deletions collect_static.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/* Copyright (c) 2017 CoNWeT Lab., Universidad Politécnica de Madrid
*
* This file belongs to the business-ecosystem-logic-proxy of the
* Business API Ecosystem
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

const config = require('./config');
const compressor = require('node-minify');
const fs = require('fs');
const mergedirs = require('merge-dirs');
const path = require('path');

const staticPath = './static';

const debug = !(process.env.NODE_ENV == 'production');

const deleteContents = function (path) {
fs.readdirSync(path).forEach((file) => {
let curPath = path + "/" + file;

if (fs.lstatSync(curPath).isDirectory()) { // recurse
deleteDir(curPath);
} else { // delete file
fs.unlinkSync(curPath);
}
});
};

const deleteDir = function (path) {
deleteContents(path);
fs.rmdirSync(path);
};

const loadTheme = function () {
// Check if the provided theme exists
if (!fs.existsSync('./themes/' + config.theme)) {
console.log('The configured theme ' + config.theme + ' has not been provided');
process.exit(1);
}

console.log('Loading Theme ' + config.theme);

// Merge default files with theme ones
mergedirs.default('./themes/' + config.theme, './static', 'overwrite');

console.log('Theme loaded');
};

const minimizejs = function () {
let files = [];
let output = staticPath + '/public/resources/core/js/bae.min.js';

let compileJs = (jsFile) => {
if (jsFile.indexOf('.js') != -1) {
files.push(jsFile);
console.log('Including ' + jsFile);
}
};

let compileFiles = (d) => fs.statSync(d).isDirectory() ? fs.readdirSync(d).map(f => compileFiles(path.join(d, f))) : compileJs(d);
compileFiles(staticPath + '/public/resources/core/js');

console.log('Generating ' + output);
compressor.minify({
compressor: 'gcc',
input: files,
output: output,
callback: function (err, min) {
files.forEach((f) => {
fs.unlinkSync(f);
});
fs.rmdirSync(staticPath + '/public/resources/core/js/controllers');
fs.rmdirSync(staticPath + '/public/resources/core/js/directives');
fs.rmdirSync(staticPath + '/public/resources/core/js/services');
fs.rmdirSync(staticPath + '/public/resources/core/js/routes');
}
});
};

// Check if a theme has been provided or the system is in production
if (!config.theme && debug) {
console.log('The default theme is configured and debug mode is active, nothing to do');
process.exit(1);
}

// Delete prev static files
if(fs.existsSync(staticPath)) {
deleteContents(staticPath);
} else {
fs.mkdirSync(staticPath);
}

// Copy default theme files
mergedirs.default('./views', './static/views', 'overwrite');
mergedirs.default('./public', './static/public', 'overwrite');

if (config.theme) {
// If a theme has been provided merge it with default files
loadTheme();
}

if (!debug) {
// If the system is in production compile jades and minimize js files
minimizejs();
console.log('JavaScript files minimized');
}
16 changes: 14 additions & 2 deletions config.js.template
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
var config = {};

// Version of the software
config.version = {
version: '6.4.0',
releaseDate: '',
gitHash: '',
doc: 'https://fiware-tmforum.github.io/Business-API-Ecosystem/',
userDoc: 'http://business-api-ecosystem.readthedocs.io/en/v6.4.0'
};

// The PORT used by
config.port = 80;
config.host = 'localhost';

// Set this var to undefined if you don't want the server to listen on HTTPS
config.https = {
Expand All @@ -18,6 +28,7 @@ config.portalPrefix = '';
config.logInPath = '/login';
config.logOutPath = '/logOut';
config.sessionSecret = 'keyboard cat';
config.theme = '';

// OAuth2 configuration
config.oauth2 = {
Expand All @@ -28,9 +39,10 @@ config.oauth2 = {
'roles': {
'admin': 'provider',
'customer': 'customer',
'seller': 'seller'
'seller': 'seller',
'orgAdmin': 'orgAdmin'
}
}
};

// Customer Role Required to buy items
config.customerRoleRequired = false;
Expand Down
29 changes: 26 additions & 3 deletions controllers/management.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2016 CoNWeT Lab., Universidad Politécnica de Madrid
/* Copyright (c) 2016 - 2017 CoNWeT Lab., Universidad Politécnica de Madrid
*
* This file belongs to the business-ecosystem-logic-proxy of the
* Business API Ecosystem
Expand All @@ -16,6 +16,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
const config = require('../config');

var management = (function() {

Expand All @@ -28,10 +29,32 @@ var management = (function() {
res.end();
};

var getVersion = function(req, res) {
var uptime = process.uptime();
var days = Math.floor(uptime / 86400);
var hours = Math.floor((uptime - (days * 86400)) / 3600);
var minutes = Math.floor((uptime - (days * 86400) - (hours * 3600)) / 60);
var seconds = Math.floor(uptime - (days * 86400) - (hours * 3600) - (minutes * 60));

var upMsg = days + ' d, ' + hours + ' h, ' + minutes + ' m, ' + seconds + ' s';

res.statusCode = 200;
res.json({
version: config.version.version,
release_date: config.version.releaseDate,
uptime: upMsg,
git_hash: config.version.gitHash,
doc: config.version.doc,
user_doc: config.version.userDoc
});
res.end();
};

return {
getCount: getCount
getCount: getCount,
getVersion: getVersion
};

})();

exports.management = management;
exports.management = management;
Loading

0 comments on commit 808f4bf

Please sign in to comment.