initial optimize attempt

This commit is contained in:
Spencer Alger 2015-06-30 09:18:17 -07:00
parent 615f4c972a
commit 935bb5e945
16 changed files with 44 additions and 84 deletions

View file

@ -0,0 +1,12 @@
module.exports = function (kibana) {
return new kibana.Plugin({
exports: {
app: {
title: 'Sense',
description: 'like cURL, but for elasticsearch and helpfull',
icon: 'plugins/sense/icon.png',
main: 'plugins/sense/sense'
}
}
});
};

View file

@ -0,0 +1,4 @@
{
"name": "sense",
"version": "1.0.0"
}

View file

@ -0,0 +1,3 @@
{
"extends": "../../../../.jshintrc.browser"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 305 KiB

View file

@ -0,0 +1,11 @@
define(function (require) {
require('routes')
.when('/', {
template: '<h1>sense</h1>'
})
.otherwise({
redirectTo: '/'
});
});

View file

@ -21,7 +21,8 @@ function KbnServer(settings) {
require('./http'),
require('./ui'),
require('./status'),
require('./plugins')
require('./plugins'),
require('./optimize')
));
}

View file

View file

@ -9,7 +9,7 @@ module.exports = function (kbnServer, server, config) {
var Promise = require('bluebird');
var apps = kbnServer.uiExports.apps;
var uiDir = require('../../ui/lib/uiDir');
var uiDir = require('../ui/assetsDir');
var glob = _.wrap(Promise.promisify(require('glob')), function (gb, dir) {
return gb('**/*', {
cwd: dir,

View file

View file

View file

@ -0,0 +1 @@
module.exports = require('../utils/fromRoot')('src/ui');

View file

@ -1,20 +0,0 @@
var join = require('path').join;
var exists = require('fs').existsSync;
var relative = require('path').relative;
module.exports = function (start, within) {
var dir = start;
var bowerPath = join(dir, 'bower_components');
while (!exists(bowerPath)) {
var prev = dir;
dir = join(dir, '..');
bowerPath = join(dir, 'bower_components');
if (dir === prev || relative(within, dir).slice(0, 2) === '..') {
throw new Error('unable to find bower_components');
}
}
return bowerPath;
};

View file

@ -4,14 +4,14 @@ var basename = require('path').basename;
var readdir = require('fs').readdirSync;
var stat = require('fs').statSync;
var exists = require('fs').existsSync;
var uiDir = require('./uiDir');
var assetsDir = require('../assetsDir');
function hidden(name) {
return name[0] !== '.' && name[0] !== '_';
}
function scan(type) {
var dir = join(uiDir, type);
var dir = join(assetsDir, type);
return readdir(dir)
.filter(hidden)

View file

@ -1 +0,0 @@
module.exports = require('../../utils/fromRoot')('src/ui');

View file

@ -1,28 +1,14 @@
module.exports = function (kbnServer, server, config) {
var Boom = require('boom');
var findBowerComponents = require('./lib/findBowerComponents');
var uiDir = require('./lib/uiDir');
var assetsDir = require('./assetsDir');
var join = require('path').join;
var stat = require('fs').statSync;
// provide access to an app's public directories
server.exposeStaticDir('/app/{id}/{path*}', function pickDir(req) {
var id = req.params.id;
var app = server.getApps()[id];
if (!app) return Boom.notFound('Unkown app ' + id);
return app.publicDir || Boom.notFound(id + ' does not server public files');
});
// expose the first bower_components directory found within kibana's rootDir starting
// in this directory and moving out
server.exposeStaticDir('/bower_components/{path*}', findBowerComponents(__dirname, kbnServer.rootDir));
// expose our public files at the server root explicitly, rather than with a catch all route
require('fs')
.readdirSync(uiDir)
.readdirSync(assetsDir)
.forEach(function (name) {
var path = join(uiDir, name);
var path = join(assetsDir, name);
if (stat(path).isDirectory()) {
server.exposeStaticDir('/' + name + '/{path*}', path);

View file

@ -1,4 +1,4 @@
- var j = function (o) { return JSON.stringify(o, null, 2); }
- var j = function (o) { return JSON.stringify(o); }
doctype html
html(lang='en')
@ -21,44 +21,7 @@ html(lang='en')
var showCacheMessage = location.href.indexOf('?embed') < 0 && location.href.indexOf('&embed') < 0;
if (!showCacheMessage) document.getElementById('cache-message').style.display = 'none';
script(src='/bower_components/requirejs/require.js#{cacheBust}')
script(src='/require.config.js#{cacheBust}')
script.
(function () {
var payload = !{ j(kibanaPayload) };
var use = !{ j(app.getModules()) };
require.config({ urlArgs: !{ j(cacheBust) } });
require(['modules', 'chrome'], function (modules, chrome) {
chrome.consumePayload(payload);
var kibana = modules.get('kibana', use.angular);
kibana
.constant('kbnVersion', payload.version)
.constant('buildNum', payload.buildNumber)
.constant('kbnIndex', payload.kbnIndex)
.constant('esShardTimeout', payload.esShardTimeout)
.constant('esUrl', (function () {
var a = document.createElement('a');
a.href = '/elasticsearch';
return a.href;
}()))
.constant('commitSha', payload.buildSha)
.constant('cacheBust', payload.cacheBust)
.constant('minimumElasticsearchVersion', '2.0.0')
.constant('sessionId', Date.now());
// tell the modules util to add all discovered modules as a requirement in kibana
modules.link(kibana);
// load our main module and bootstrap
require(['jquery'].concat(use.main, use.require), function ($) {
angular
.bootstrap(document, ['kibana'])
.invoke(function () {
$(document.body).children(':not(style-compile)').show();
});
});
});
}());
script(
src='/bundles/#{app.id}.js'
payload=j(kibanaPayload)
)