From ecae1325a93486193a956501895969cfb1ad61b1 Mon Sep 17 00:00:00 2001 From: Jared Forsyth Date: Thu, 21 Nov 2013 08:49:14 -0700 Subject: [PATCH] fixes #278 and #280 --- lib/app.js | 9 +++++++++ main.js | 28 +++------------------------ package.json | 2 +- routes/api/config.js | 46 +++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 58 insertions(+), 27 deletions(-) diff --git a/lib/app.js b/lib/app.js index 6179b8c00..4a2438ce4 100644 --- a/lib/app.js +++ b/lib/app.js @@ -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') @@ -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');}); diff --git a/main.js b/main.js index 9923f2a9a..e8133cb44 100644 --- a/main.js +++ b/main.js @@ -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 @@ -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) { diff --git a/package.json b/package.json index 17412bda8..9dc53f474 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/routes/api/config.js b/routes/api/config.js index 438d66853..1b8f01199 100644 --- a/routes/api/config.js +++ b/routes/api/config.js @@ -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) { @@ -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]) + } +}