Skip to content

Commit

Permalink
WIP #212. Updated webgme config generation for routers.
Browse files Browse the repository at this point in the history
  • Loading branch information
brollb committed Dec 12, 2017
1 parent 2b9ef97 commit e93c432
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
10 changes: 8 additions & 2 deletions src/res/config.template.js.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,14 @@ var config = require('webgme/config/config.default'),

<%= printConfigPaths('visualization.panelPaths', visualizers.map(dirname)) %>

<%= routers.map(function(r) {
return 'config.rest.components[\'' + r[0] + '\'] = __dirname + \'/../' + r[1] + '\';';
<%= routers.map(function(router) {
return [
'config.rest[\'' + router.name + '\'] = {',
' src: __dirname + \'/../' + router.srcFile + '\',',
' mount: \'' + router.mount + '\',',
' options: {}',
'};'
].join('\n');
}).join('\n') %>

// Visualizer descriptors
Expand Down
9 changes: 4 additions & 5 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,10 @@ var updateWebGMEConfig = function(startPath) {
content.routers = [];
Object.keys(config).forEach(type => {
Object.keys(config[type].routers || {}).forEach(name => {
var router = config[type].routers[name],
src = router.src || router.path;

src = src.replace(/\/$/, '');
content.routers.push([router.mount, `${src}/${name}.js`]);
let router = config[type].routers[name];
router.name = name;
router.srcFile = `${router.src}/${name}.js`;
content.routers.push(router);
});
});

Expand Down
27 changes: 22 additions & 5 deletions test-src/router.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,31 @@ describe('Router tests', function() {
var cliConfig = require(`${PROJECT_DIR}/${CONFIG_NAME}`),
cliMountPt = cliConfig.components.routers[ROUTER_NAME].mount;

console.log('router:', cliConfig.components.routers[ROUTER_NAME]);
assert.equal(cliMountPt, mountPt);
});

it('should update the webgme config', function() {
var gmeConfig = require(`${PROJECT_DIR}/config/config.webgme.js`);

assert.notEqual(gmeConfig.rest.components[mountPt], undefined);
describe('webgme config', function() {
let routerConfig;
before(() => {
let gmeConfig = require(`${PROJECT_DIR}/config/config.webgme.js`);
routerConfig = gmeConfig.rest[ROUTER_NAME];
});

it('should update the webgme config', function() {
assert.notEqual(routerConfig, undefined);
});

it('should set src to .js file', function() {
assert(routerConfig.src.includes('.js'));
});

it('should set src to existing file', function() {
assert(exists(routerConfig.src));
});

it('should set mount point', function() {
assert.equal(routerConfig.mount, mountPt);
});
});
});

Expand Down

0 comments on commit e93c432

Please sign in to comment.