Skip to content

Commit

Permalink
fixes #278 and #280
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredly committed Nov 21, 2013
1 parent 1530dbd commit ecae132
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 27 deletions.
9 changes: 9 additions & 0 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var Backchannel = require('./backchannel')
, api_collaborators = require('../routes/api/collaborators')
, api_jobs = require('../routes/api/jobs.js')
, api_repo = require('../routes/api/repo.js')
, api_config = require('../routes/api/config.js')
, api_session = require('../routes/api/session.js')

, auth = require('./auth')
Expand Down Expand Up @@ -149,6 +150,14 @@ var init = exports.init = function (config) {
res.render('about');
});

// Compiled plugin config assets
app.get('/javascripts/pages/plugin-config-compiled.js', api_config.server('config', 'js'))
app.get('/stylesheets/css/plugin-config-compiled.css', api_config.server('config', 'css'))
app.get('/javascripts/pages/account-plugins-compiled.js', api_config.server('account', 'js'))
app.get('/stylesheets/css/account-plugins-compiled.css', api_config.server('account', 'css'))
app.get('/javascripts/pages/plugin-status-compiled.js', api_config.server('status', 'js'))
app.get('/stylesheets/css/plugin-status-compiled.css', api_config.server('status', 'css'))

// Docs page (single page for moment)
app.get('/docs', function(req, res) {res.render('docs');});
app.get('/docs/getting_started', function(req, res) {res.render('docs/GettingStarted');});
Expand Down
28 changes: 3 additions & 25 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ var app = require('./lib/app')
, pluginTemplates = require('./lib/pluginTemplates')
, utils = require('./lib/utils')

, api_config = require('./routes/api/config')

, Job = models.Job
, Config = models.Config

Expand Down Expand Up @@ -179,31 +181,7 @@ function loadExtensions(loader, extdir, context, appInstance, cb) {
})
},
function (next) {
loader.initConfig(
path.join(__dirname, 'public/javascripts/pages/plugin-config-compiled.js'),
path.join(__dirname, 'public/stylesheets/css/plugin-config-compiled.css'),
function (err, configs) {
if (err) return next(err)
console.log('loaded config pages')
common.pluginConfigs = configs
loader.initUserConfig(
path.join(__dirname, 'public/javascripts/pages/account-plugins-compiled.js'),
path.join(__dirname, 'public/stylesheets/css/account-plugins-compiled.css'),
function (err, configs) {
if (err) return next(err)
console.log('loaded account config pages')
common.userConfigs = configs
loader.initStatusBlocks(
path.join(__dirname, 'public/javascripts/pages/plugin-status-compiled.js'),
path.join(__dirname, 'public/stylesheets/css/plugin-status-compiled.css'),
function (err, blocks) {
if (err) return next(err)
console.log('loaded plugin status blocks')
common.statusBlocks = blocks
next()
})
})
})
api_config.cacheConfig(loader, next)
}
], function (err) {
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"nomnom": "1.6.x",
"everypaas": "0.0.x",
"pw": "0.0.4",
"strider-extension-loader": "~0.4.0",
"strider-extension-loader": "git+https://github.com/Strider-CD/strider-extension-loader.git",
"strider-simple-runner": "~0.11.0",
"strider-env": "~0.4.0",
"strider-python": "~0.2.0",
Expand Down
46 changes: 45 additions & 1 deletion routes/api/config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@

var keypair = require('ssh-keypair')
, common = require('../../lib/common')

module.exports = {
keygen: keygen
keygen: keygen,
cacheConfig: cacheConfig,
server: server
}

function keygen(req, res) {
Expand All @@ -22,3 +25,44 @@ function keygen(req, res) {
})
}

var cache = {}

function cacheConfig(loader, next) {
var base = '../../public/'
loader.initConfig(function (err, jstext, csstext, configs) {
if (err) return next(err)
cache['config'] = {
js: jstext,
css: csstext
}
console.log('loaded config pages')
common.pluginConfigs = configs
loader.initUserConfig(function (err, jstext, csstext, configs) {
if (err) return next(err)
cache['account'] = {
js: jstext,
css: csstext
}
console.log('loaded account config pages')
common.userConfigs = configs
loader.initStatusBlocks(function (err, jstext, csstext, blocks) {
if (err) return next(err)
cache['status'] = {
js: jstext,
css: csstext
}
console.log('loaded plugin status blocks')
common.statusBlocks = blocks
next()
})
})
})
}

function server(name, which) {
return function (req, res) {
res.set('Content-type', 'text/' + (which === 'css' ? 'css' : 'javascript'))
if (!cache['config']) return res.send(500, 'looks like config was not compiled correctly')
res.send(cache[name][which])
}
}

0 comments on commit ecae132

Please sign in to comment.