Add hook to optimize module to add registration during dev startup

Registration of the core plugin translations during development start of
Kibana server. The translations include the welcome message and server error
startup message.
This commit is contained in:
Martin Hickey 2016-07-28 15:18:19 +01:00
parent 4957173794
commit 5f61475ad5

View file

@ -1,7 +1,23 @@
import fs from 'fs';
import FsOptimizer from './fs_optimizer';
import i18nPlugin from '../plugins/i18n/server/i18n/index';
import kibanaPackage from '../utils/package_json';
import Promise from 'bluebird';
const readdir = Promise.promisify(fs.readdir);
module.exports = async (kbnServer, server, config) => {
if (!config.get('optimize.enabled')) return;
server.log(
['info', 'i18n'],
`Registering core plugin translations. This may take a few minutes`
);
let start = Date.now();
await registerCoreTranslations();
let seconds = ((Date.now() - start) / 1000).toFixed(2);
server.log(['info', 'i18n'], `Registration of core plugin translations completed in ${seconds} seconds`);
// the lazy optimizer sets up two threads, one is the server listening
// on 5601 and the other is a server listening on 5602 that builds the
// bundles in a "middleware" style.
@ -51,4 +67,22 @@ module.exports = async (kbnServer, server, config) => {
const seconds = ((Date.now() - start) / 1000).toFixed(2);
server.log(['info', 'optimize'], `Optimization of ${bundles.desc()} complete in ${seconds} seconds`);
};
function registerCoreTranslations()
{
const rootDir = kibanaPackage.__dirname;
//Add translation dirs for the core plugins here
const corePluginTranslationDirs = [rootDir + '/src/ui/i18n'];
return Promise.map(corePluginTranslationDirs, (dir) => {
readdir(dir).then((dirListing) => {
Promise.map(dirListing, (listing) => {
const fullFilePath = dir + '/' + listing;
i18nPlugin.registerTranslations(fullFilePath);
});
});
});
}