Skip to content
Browse files

added build-i18n.js, which makes a big JSON blob of all bundles.

  • Loading branch information...
1 parent 79c179a commit b72d314273b9ffcac0b0301e9db7c97bf6eb8f9e @toolness committed
Showing with 45 additions and 2 deletions.
  1. +25 −0 build-i18n.js
  2. +18 −1 js/slowparse-errors/html-to-i18n-bundle.js
  3. +2 −1 package.json
View
25 build-i18n.js
@@ -0,0 +1,25 @@
+var NLS_PATHS = [
+ 'fc/nls',
+ 'slowparse-errors/nls'
+];
+
+var fs = require('fs');
+var requirejs = require('requirejs');
+var requireConfig = require('./js/require-config');
+var bundles = {};
+
+requirejs.config(requireConfig);
+
+NLS_PATHS.forEach(function(path) {
+ fs.readdirSync(__dirname + '/js/' + path).forEach(function(filename) {
+ var match = filename.match(/^(.*)\.js$/);
+ if (match) {
+ var moduleName = path + '/' + match[1];
+ var bundle = requirejs('i18n!' + moduleName);
+
+ bundles[moduleName] = bundle;
+ }
+ });
+});
+
+console.log(bundles);
View
19 js/slowparse-errors/html-to-i18n-bundle.js
@@ -1,7 +1,24 @@
define(function() {
+ function getDocument() {
+ if (typeof(document) == "undefined") {
+ // We're being run in node, so make a document using jsdom.
+ var jsdom = require("jsdom").jsdom;
+ var doc = jsdom('<html></html>', null, {
+ features: {
+ FetchExternalResources: false,
+ ProcessExternalResources: false,
+ MutationEvents: false,
+ QuerySelector: true
+ }
+ });
+ return doc;
+ }
+ return document;
+ }
+
return function htmlToI18nBundle(html) {
var result = {};
- var div = document.createElement('div');
+ var div = getDocument().createElement('div');
div.innerHTML = html;
[].slice.call(div.querySelectorAll('.error-msg')).forEach(function(el) {
View
3 package.json
@@ -5,7 +5,8 @@
"description": "requirejs optimization script",
"main": "build-require.js",
"dependencies": {
- "requirejs": "~2.x"
+ "requirejs": "~2.x",
+ "jsdom": "0.2.19"
},
"scripts": {
"start": "node build-require.js"

0 comments on commit b72d314

Please sign in to comment.
Something went wrong with that request. Please try again.