Skip to content

Commit

Permalink
GPII-3550: Load messageBundlesCompiler from new compileMessageBundles…
Browse files Browse the repository at this point in the history
… script
  • Loading branch information
javihernandez committed Nov 28, 2018
1 parent 6fdec74 commit a1e0709
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 35 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"scripts": {
"start": "electron .",
"dev": "electron . ./configs app.dev",
"build": "electron ./messageBundlesCompiler.js",
"build": "electron ./scripts/compileMessageBundles.js",
"pretest": "npm run pretest:clean && npm run build && npm run pretest:instrument",
"pretest:clean": "node node_modules/rimraf/bin.js coverage instrumented reports build && node ./node_modules/mkdirp/bin/cmd.js coverage instrumented reports",
"pretest:instrument": "node tests/lib/instrumentSource.js",
Expand Down
57 changes: 57 additions & 0 deletions scripts/compileMessageBundles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* The message bundles compiler script.
*
* This script compiles a mega message bundle which contains
* all messages for all available locales.
* Copyright 2018 Raising the Floor - International
*
* Licensed under the New BSD license. You may not use this file except in
* compliance with this License.
* The research leading to these results has received funding from the European Union's
* Seventh Framework Programme (FP7/2007-2013) under grant agreement no. 289016.
* You may obtain a copy of the License at
* https://github.com/GPII/universal/blob/master/LICENSE.txt
*/

"use strict";

var fluid = require("infusion");
var gpii = fluid.registerNamespace("gpii");

var fs = require("fs");
var path = require("path");
var shell = require("shelljs");

require("./shared/messageBundlesCompiler.js");

/**
* This function generates the messages bundle and writes into a given file.
* @param {String[]} messageDirs - An array of the directories from which messages
* files are to be retrieved.
* @param {String} resultFilePath - The file where the bundles are going to be written.
*/
gpii.app.compileMessageBundles = function (messageDirs, resultFilePath) {
require("gpii-windows");

// This is a noop when the folder already exists
shell.mkdir("-p", path.dirname(resultFilePath));

var compileMessageBundles = gpii.app.messageBundlesCompiler.compileMessageBundles;
var compiledMessageBundles = compileMessageBundles(messageDirs, "en", {"json": JSON, "json5": require("json5")});

fs.writeFileSync(resultFilePath, JSON.stringify(compiledMessageBundles, null, 4));
fluid.log("Message bundle successfully written to ", resultFilePath);

// We have to manually exit the electron process
process.exit();
};

/**
* This is the entry point to the script. Any configuration must be indicated below.
*/
gpii.app.compileMessageBundles(
// List of dirs to look for message bundles
["./messageBundles", "%gpii-user-errors/bundles"],
// The resulting bundle file path
"./build/gpii-app-messageBundles.json"
);
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ fluid.registerNamespace("gpii.app.messageBundlesCompiler");

var fs = require("fs");
var path = require("path");
var shell = require("shelljs");

var DEFAULT_PARSER = {"json": JSON};


/**
* Represents a single messages bundle, containing label names and messages for them.
*
Expand Down Expand Up @@ -248,34 +246,4 @@ gpii.app.messageBundlesCompiler.compileMessageBundles = function (bundlesDirs, d
return compiledMessageBundle;
};

/**
* This function generates the messages bundle and writes into a given file.
* @param {String[]} messageDirs - An array of the directories from which messages
* files are to be retrieved.
* @param {String} resultFilePath - The file where the bundles are going to be written.
*/
gpii.app.compileMessageBundles = function (messageDirs, resultFilePath) {
require("gpii-windows");

// This is a noop when the folder already exists
shell.mkdir("-p", path.dirname(resultFilePath));

var compileMessageBundles = gpii.app.messageBundlesCompiler.compileMessageBundles;
var compiledMessageBundles = compileMessageBundles(messageDirs, "en", {"json": JSON, "json5": require("json5")});

fs.writeFileSync(resultFilePath, JSON.stringify(compiledMessageBundles, null, 4));
fluid.log("Message bundle successfully written to ", resultFilePath);

// We have to manually exit the electron process
process.exit();
};

/**
* This is the entry point to the script. Any configuration must be indicated below.
*/
gpii.app.compileMessageBundles(
// List of dirs to look for message bundles
["./messageBundles", "%gpii-user-errors/bundles"],
// The resulting bundle file path
"./build/gpii-app-messageBundles.json"
);
module.exports.compileMessageBundles = gpii.app.messageBundlesCompiler.compileMessageBundles;
2 changes: 1 addition & 1 deletion tests/MessageBundlesCompilerTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var gpii = fluid.registerNamespace("gpii");

var jqUnit = fluid.require("node-jqunit", require, "jqUnit");

require("../messageBundlesCompiler.js");
require("../scripts/shared/messageBundlesCompiler.js");

fluid.registerNamespace("gpii.tests.messageBundles.testDefs");

Expand Down

0 comments on commit a1e0709

Please sign in to comment.