From 5aedc697b7bba9e80a97ab86913b61ce662563a8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gr=C3=A9goire=20Aubert?= Date: Wed, 28 Nov 2018 09:48:16 +0100 Subject: [PATCH] Add parameter to get extension's l10n bundle in dev mode --- server/sonar-web/scripts/start.js | 3 +- server/sonar-web/scripts/utils/getMessages.js | 44 ++++++++++++------- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/server/sonar-web/scripts/start.js b/server/sonar-web/scripts/start.js index 871d5e7dbfd..a4abf2bc241 100644 --- a/server/sonar-web/scripts/start.js +++ b/server/sonar-web/scripts/start.js @@ -40,6 +40,7 @@ const proxy = process.env.PROXY || 'http://localhost:9000'; // Force start script to proxy l10n request to the server (can be useful when working with plugins/extensions) const l10nCompiledFlag = process.argv.findIndex(val => val === 'l10nCompiled') >= 0; +const l10nExtensions = process.argv.findIndex(val => val === 'l10nExtensions') >= 0; const compiler = setupCompiler(host, port, protocol); runDevServer(compiler, host, port, protocol); @@ -87,7 +88,7 @@ function runDevServer(compiler, host, port, protocol) { app.use(errorOverlayMiddleware()); if (!l10nCompiledFlag) { app.get('/api/l10n/index', (req, res) => { - getMessages() + getMessages(l10nExtensions) .then(messages => res.json({ effectiveLocale: 'en', messages })) .catch(() => res.status(500)); }); diff --git a/server/sonar-web/scripts/utils/getMessages.js b/server/sonar-web/scripts/utils/getMessages.js index 340011b17d7..bec93f115c1 100644 --- a/server/sonar-web/scripts/utils/getMessages.js +++ b/server/sonar-web/scripts/utils/getMessages.js @@ -23,23 +23,35 @@ const { promisify } = require('util'); const readFileAsync = promisify(fs.readFile); -const filename = path.resolve( - __dirname, - '../../../../sonar-core/src/main/resources/org/sonar/l10n/core.properties' -); +const filename = '../../../../sonar-core/src/main/resources/org/sonar/l10n/core.properties'; -function getMessages() { - return readFileAsync(filename, 'utf-8').then(content => { - const messages = {}; - const lines = content.split('\n'); - lines.forEach(line => { - const parts = line.split('='); - if (parts.length > 1) { - messages[parts[0]] = parts.slice(1).join('='); - } - }); - return messages; - }); +const extensionsFilenames = [ + '../../../../private/core-extension-billing/src/main/resources/org/sonar/l10n/billing.properties', + '../../../../private/core-extension-governance/src/main/resources/org/sonar/l10n/governance.properties', + '../../../../private/core-extension-license/src/main/resources/org/sonar/l10n/license.properties' +]; + +function getFileMessage(filename) { + return readFileAsync(path.resolve(__dirname, filename), 'utf-8').then( + content => { + const messages = {}; + const lines = content.split('\n'); + lines.forEach(line => { + const parts = line.split('='); + if (parts.length > 1) { + messages[parts[0]] = parts.slice(1).join('='); + } + }); + return messages; + }, + () => ({}) + ); +} + +function getMessages(l10nExtensions) { + return Promise.all( + [filename, ...extensionsFilenames].map(filename => getFileMessage(filename)) + ).then(filesMessages => filesMessages.reduce((acc, messages) => ({ ...acc, ...messages }), {})); } module.exports = getMessages; -- 2.39.5