Skip to content

Commit

Permalink
PLAT-40847: Add internal moonstone localization support to enact-dev,…
Browse files Browse the repository at this point in the history
… build, etc (#76)

* PLAT-40847: Add internal moonstone localization support to enact, enact-dev, build, etc.

* Fallback for when moonstone screentypes is undefined.

* Decouple @enact/i18n and @enact/moonstone from v8 snapshot and treat them as optional dependencies.
  • Loading branch information
JayCanuck authored and webOS101 committed May 30, 2017
1 parent 2d5b8a9 commit c8f9c36
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
13 changes: 12 additions & 1 deletion global-cli/modifiers/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ var
path = require('path'),
exists = require('path-exists').sync,
helper = require('./util/config-helper'),
SnapshotPlugin = require('./util/SnapshotPlugin');
SnapshotPlugin = require('./util/SnapshotPlugin'),
IgnorePlugin = require('webpack').IgnorePlugin;

module.exports = function(config, opts) {
if(!opts.framework) {
Expand All @@ -27,4 +28,14 @@ module.exports = function(config, opts) {
// Disabled temporarily until effectiveness is proven
// append: (opts.framework ? '\nenact_framework.load();\n' : undefined)
}));

var ssHelperDeps = [
'@enact/i18n',
'@enact/moonstone'
];
for(var i=0; i<ssHelperDeps.length; i++) {
if(!exists(path.join(process.cwd(), 'node_modules', ssHelperDeps[i]))) {
config.plugins.push(new IgnorePlugin(new RegExp(ssHelperDeps[i])));
}
}
};
2 changes: 1 addition & 1 deletion global-cli/modifiers/util/prerendered-startup.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

(function() {
// Initialize font scaling for resolution independence.
var screenTypes = %SCREENTYPES%;
var screenTypes = %SCREENTYPES% || [];
var defaultType = {name: 'standard', pxPerRem: 16, width: window.innerWidth, height: window.innerHeight, aspectRatioName: 'standard', base: true};
if(screenTypes.length===0) {
screenTypes.push(defaultType);
Expand Down
40 changes: 29 additions & 11 deletions global-cli/modifiers/util/snapshot-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
* launch-time issues when using code created in a snapshot blob.
*/

function handleException(e) {
// We allow 'Cannot find module' errors, which throw when the libraries are not used in the app.
// @enact/i18n and @enact/moonstone are considered optional dependencies.
if(!e.code || e.code!=='MODULE_NOT_FOUND') {
throw e;
}
}

global.updateEnvironment = function() {
// Update fbjs to have the correct execution environment for the active window.
var ExecutionEnvironment = require('fbjs/lib/ExecutionEnvironment');
Expand All @@ -16,17 +24,27 @@ global.updateEnvironment = function() {
ExecutionEnvironment.canUseViewport = canUseDOM && !!window.screen;
ExecutionEnvironment.isInWorker = !canUseDOM; // For now, this is true - might change in the future.

// Mark the iLib localestorage cache as needing re-validation.
var ilib = require('@enact/i18n/ilib/lib/ilib');
if (ilib._load) {
ilib._load._cacheValidated = false;
}
try {
// Mark the iLib localestorage cache as needing re-validation.
var ilib = require('@enact/i18n/ilib/lib/ilib');
if (ilib && ilib._load) {
ilib._load._cacheValidated = false;
}

// Clear the active resBundle and string cache.
var resBundle = require('@enact/i18n/src/resBundle');
resBundle.clearResBundle();
// Clear the active resBundle and string cache.
var resBundle = require('@enact/i18n/src/resBundle');
resBundle.clearResBundle();
try {
var moonstoneBundle = require('@enact/moonstone/internal/$L');
moonstoneBundle.clearResBundle();
} catch(e2) {
handleException(e2);
}

// Update the iLib/Enact locale to the active window's locale.
var locale = require('@enact/i18n/locale');
locale.updateLocale();
// Update the iLib/Enact locale to the active window's locale.
var locale = require('@enact/i18n/locale');
locale.updateLocale();
} catch(e1) {
handleException(e1);
}
};

0 comments on commit c8f9c36

Please sign in to comment.