mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Replace registering of translations at plugin install time to the plugin init phase
This change follows review comments in: https://github.com/elastic/kibana/issues/6515#issuecomment-236237218
This commit is contained in:
parent
9fbe6d5fcd
commit
32d5034d9c
11 changed files with 78 additions and 114 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -24,6 +24,7 @@ target
|
|||
.eslintcache
|
||||
/plugins/
|
||||
data
|
||||
installedPlugins
|
||||
disabledPlugins
|
||||
webpackstats.json
|
||||
config/*
|
||||
|
|
|
@ -1,13 +1,18 @@
|
|||
import Promise from 'bluebird';
|
||||
import { mkdirp as mkdirpNode } from 'mkdirp';
|
||||
import manageUuid from './server/lib/manage_uuid';
|
||||
import fs from 'fs';
|
||||
import i18nPlugin from '../../plugins/i18n/server/i18n/index';
|
||||
import ingest from './server/routes/api/ingest';
|
||||
import kibanaPackage from '../../utils/package_json';
|
||||
import Promise from 'bluebird';
|
||||
import search from './server/routes/api/search';
|
||||
import settings from './server/routes/api/settings';
|
||||
import scripts from './server/routes/api/scripts';
|
||||
import * as systemApi from './server/lib/system_api';
|
||||
|
||||
const mkdirp = Promise.promisify(mkdirpNode);
|
||||
const readdir = Promise.promisify(fs.readdir);
|
||||
|
||||
module.exports = function (kibana) {
|
||||
const kbnBaseUrl = '/app/kibana';
|
||||
|
@ -113,9 +118,26 @@ module.exports = function (kibana) {
|
|||
search(server);
|
||||
settings(server);
|
||||
scripts(server);
|
||||
|
||||
server.expose('systemApi', systemApi);
|
||||
registerCoreTranslations();
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,23 +1,7 @@
|
|||
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.
|
||||
|
@ -35,11 +19,13 @@ module.exports = async (kbnServer, server, config) => {
|
|||
server.exposeStaticDir('/bundles/{path*}', bundles.env.workingDir);
|
||||
await bundles.writeEntryFiles();
|
||||
|
||||
// in prod, only bundle when someing is missing or invalid
|
||||
const invalidBundles = config.get('optimize.useBundleCache') ? await bundles.getInvalidBundles() : bundles;
|
||||
// in prod, only bundle what looks invalid or missing
|
||||
if (config.get('optimize.useBundleCache')) {
|
||||
bundles = await bundles.getInvalidBundles();
|
||||
}
|
||||
|
||||
// we might not have any work to do
|
||||
if (!invalidBundles.getIds().length) {
|
||||
if (!bundles.getIds().length) {
|
||||
server.log(
|
||||
['debug', 'optimize'],
|
||||
`All bundles are cached and ready to go!`
|
||||
|
@ -62,27 +48,15 @@ module.exports = async (kbnServer, server, config) => {
|
|||
`Optimizing and caching ${bundles.desc()}. This may take a few minutes`
|
||||
);
|
||||
|
||||
<<<<<<< HEAD
|
||||
const start = Date.now();
|
||||
await optimizer.run();
|
||||
const seconds = ((Date.now() - start) / 1000).toFixed(2);
|
||||
=======
|
||||
let start = Date.now();
|
||||
await optimizer.run();
|
||||
let seconds = ((Date.now() - start) / 1000).toFixed(2);
|
||||
>>>>>>> Replace registering of translations at plugin install time to the plugin init phase
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"test_plugin_1-NO_SSL": "Dont run the DE dev server using HTTPS",
|
||||
"test_plugin_1-DEV": "Run the DE server with development mode defaults"
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"test_plugin_1-NO_SSL": "Dont run the dev server using HTTPS",
|
||||
"test_plugin_1-DEV": "Run the server with development mode defaults",
|
||||
"test_plugin_1-NO_RUN_SERVER": "Dont run the dev server",
|
||||
"test_plugin_1-HOME": "Run along home now!"
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"test_plugin_2-XXXXXX": "This is XXXXXX string",
|
||||
"test_plugin_2-YYYY_PPPP": "This is YYYY_PPPP string",
|
||||
"test_plugin_2-FFFFFFFFFFFF": "This is FFFFFFFFFFFF string",
|
||||
"test_plugin_2-ZZZ": "This is ZZZ string"
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
import expect from 'expect.js';
|
||||
import fs from 'fs';
|
||||
import fse from 'fs-extra';
|
||||
import i18n from '../i18n/i18n';
|
||||
import path from 'path';
|
||||
|
@ -10,6 +11,7 @@ const DATA_PATH = __dirname + PATH_SEPARATOR + 'fixtures';
|
|||
const TRANSLATION_BACKUP_PATH = DATA_PATH + '/translations_backup';
|
||||
|
||||
const translationStorePath = i18n.getTranslationStoragePath();
|
||||
const stat = Promise.promisify(fs.stat);
|
||||
|
||||
describe('Test registering translations for test_plugin_1', function () {
|
||||
const pluginName = 'test_plugin_1';
|
||||
|
@ -205,18 +207,22 @@ function checkRegisteredLanguages(expectedLanguages, done) {
|
|||
|
||||
function backupTranslations(done) {
|
||||
const translationStorePath = i18n.getTranslationStoragePath();
|
||||
fse.copy(translationStorePath, TRANSLATION_BACKUP_PATH, function (err) {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
done();
|
||||
return;
|
||||
}
|
||||
fse.emptyDir(translationStorePath, function (err) {
|
||||
return stat(translationStorePath).then((stats) => {
|
||||
fse.copy(translationStorePath, TRANSLATION_BACKUP_PATH, function (err) {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
done();
|
||||
return;
|
||||
}
|
||||
done();
|
||||
fse.emptyDir(translationStorePath, function (err) {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
}
|
||||
done();
|
||||
});
|
||||
});
|
||||
}).catch(function (e) {
|
||||
done();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -228,18 +234,22 @@ function restoreTranslations(done) {
|
|||
done();
|
||||
return;
|
||||
}
|
||||
fse.copy(TRANSLATION_BACKUP_PATH, translationStorePath, function (err) {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
done();
|
||||
return;
|
||||
}
|
||||
fse.remove(TRANSLATION_BACKUP_PATH, function (err) {
|
||||
return stat(TRANSLATION_BACKUP_PATH).then((stats) => {
|
||||
fse.copy(TRANSLATION_BACKUP_PATH, translationStorePath, function (err) {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
done();
|
||||
return;
|
||||
}
|
||||
done();
|
||||
fse.remove(TRANSLATION_BACKUP_PATH, function (err) {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
}
|
||||
done();
|
||||
});
|
||||
});
|
||||
}).catch(function (e) {
|
||||
done();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
{
|
||||
"CORE-WELCOME_MESSAGE": "is loading. Give me a moment here. I'm loading a whole bunch of code. Don't worry, all this good stuff will be cached up for next time!",
|
||||
"CORE-WELCOME_ERROR": "Kibana did not load properly. Check the server output for more information."
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
import fs from 'fs';
|
||||
import fse from 'fs-extra';
|
||||
import i18nPlugin from '../../src/plugins/i18n/server/i18n/index';
|
||||
import Promise from 'bluebird';
|
||||
|
||||
module.exports = function (grunt) {
|
||||
grunt.registerTask('_build:copy_translations', function () {
|
||||
const rootDir = grunt.config.get('root');
|
||||
const buildTranslationsDir = rootDir + '/build/kibana/fixtures/translations';
|
||||
const translationStoreDir = rootDir + '/fixtures/translations';
|
||||
|
||||
this.requires('_build:register_translations');
|
||||
|
||||
grunt.file.mkdir(buildTranslationsDir);
|
||||
|
||||
let done = this.async();
|
||||
let result = true;
|
||||
fse.copy(translationStoreDir, buildTranslationsDir, function (err) {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
result = false;
|
||||
}
|
||||
done(result);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
@ -10,9 +10,7 @@ module.exports = function (grunt) {
|
|||
'copy:devSource',
|
||||
'babel:build',
|
||||
'_build:babelOptions',
|
||||
'_build:plugins',
|
||||
'_build:data',
|
||||
'_build:register_translations',
|
||||
'_build:installedPlugins',
|
||||
'_build:packageJson',
|
||||
'_build:readme',
|
||||
'_build:babelCache',
|
||||
|
@ -23,7 +21,6 @@ module.exports = function (grunt) {
|
|||
'stop:optimizeBuild',
|
||||
'_build:versionedLinks',
|
||||
'_build:osShellScripts',
|
||||
'_build:copy_translations',
|
||||
grunt.option('skip-archives') ? [] : ['_build:archives'],
|
||||
grunt.option('skip-os-packages') ? [] : [
|
||||
'_build:pleaseRun',
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
import fs from 'fs';
|
||||
import i18nPlugin from '../../src/plugins/i18n/server/i18n/index';
|
||||
import Promise from 'bluebird';
|
||||
|
||||
const readdir = Promise.promisify(fs.readdir);
|
||||
|
||||
module.exports = function (grunt) {
|
||||
grunt.registerTask('_build:register_translations', function () {
|
||||
const rootDir = grunt.config.get('root');
|
||||
|
||||
//Add translation dirs for the core plugins here
|
||||
const corePluginTranslationDirs = [rootDir + '/src/ui/i18n'];
|
||||
|
||||
Promise.map(corePluginTranslationDirs, (dir) => {
|
||||
readdir(dir).then((dirListing) => {
|
||||
Promise.map(dirListing, (listing) => {
|
||||
const fullFilePath = dir + '/' + listing;
|
||||
i18nPlugin.registerTranslations(fullFilePath);
|
||||
});
|
||||
});
|
||||
}).nodeify(this.async());
|
||||
});
|
||||
|
||||
};
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue