Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ generated-instructions*.json
checkstyle.xml
loopback-boot-*.tgz
/test/sandbox/
intl/*
!intl/en/*
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
var PluginBase = require('./lib/plugin-base');
var Bootstrapper = require('./lib/bootstrapper').Bootstrapper;
var addInstructionsToBrowserify = require('./lib/bundler');
var SG = require('strong-globalize');
SG.SetRootDir(__dirname);

/**
* Initialize an application from an options object or
Expand Down
21 changes: 21 additions & 0 deletions intl/en/messages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"ae47060728bbbccb3b6279bfce9895e8": "Discarding middleware instructions, loopback client does not support middleware.",
"69746d336c89bf4bb371a6c2fe56304d": "{0} does not resolve to a valid value, returned as {1}. \"{2}\" must be resolvable in Environment variable or by app.get().",
"cdbbcf09fd7f613f3a3e4eacba0e614f": "WARNING: Main config file \"{0}.json\" is missing",
"3a7049e42006e8bc19e0f4fc8df63b6b": "The `app` is powered by an incompatible loopback version {0}. Supported versions: {1}",
"70654dc6eb565613a33344efed3de998": "Failed loading boot script: {0}\n{1}",
"0c8892b57ac28e5bdeb28f6d4eeace0f": "Middleware must be an array",
"33e14d1e42c43970490614c1fa38dbd3": "Middleware phases must be an array",
"35c9468dd1fc15ae5ee90a4801467772": "The phase \"{0}\" is not defined in the main config.",
"75f38e979d1caf27338aba1122e42884": "Middleware factory must be a function",
"e422b92bace89e40433df300053440c1": "The middleware \"{0}\" in phase \"{1}\"is not defined in the main config.",
"fdc23df1bd0fe55fe3faabcc89ff60f3": "Middleware \"{0}\" not found: {1}",
"34319676975b1abf107da7a056abb434": "Invalid normalization format - \"{0}\"",
"4d052d84c8620730afd4a30832f11724": "Cannot configure unknown model {0}",
"6037512314fac9d12af6c654a3804823": "Built-in model {0} should have been defined",
"79e93b2a95e969788590c14e26bb2c1b": "The data in {{model-config.json}} is in the unsupported 1.x format.",
"1e5fea50eef843cbffd1d438494912c8": "Cannot resolve path \"{0}\"",
"6447e6b342a2c51ab0bc53b3cbdf3742": "Ordering conflict: cannot add \"{0}\" after \"{1}\", because the opposite order was already specified",
"978a25819e71602cad691dbe7ba17592": "{0} config must be a valid JSON object",
"be2dcdab7aa493ed8d77287eb45cfec8": "cannot require directory contents without directory name"
}
3 changes: 2 additions & 1 deletion lib/bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

var fs = require('fs');
var path = require('path');
var g = require('strong-globalize')();
var commondir = require('commondir');
var cloneDeep = require('lodash').cloneDeep;

Expand Down Expand Up @@ -99,7 +100,7 @@ function bundleInstructions(context, bundler) {
var hasMiddleware = instructions.middleware.phases.length ||
instructions.middleware.middleware.length;
if (hasMiddleware) {
console.warn(
g.warn(
'Discarding middleware instructions,' +
' loopback client does not support middleware.');
}
Expand Down
5 changes: 3 additions & 2 deletions lib/plugin-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

var fs = require('fs');
var path = require('path');
var g = require('strong-globalize')();
var debug = require('debug')('loopback:boot:plugin');
var assert = require('assert');
var _ = require('lodash');
Expand Down Expand Up @@ -89,7 +90,7 @@ PluginBase.prototype.findConfigFiles = function(rootDir, env, name, exts) {
var master = ifExists(name + '.json');
if (!master && (ifExistsWithAnyExt(name + '.local') ||
ifExistsWithAnyExt(name + '.' + env))) {
console.warn('WARNING: Main config file "' + name + '.json" is missing');
g.warn('WARNING: Main config file "%s.json" is missing', name);
}
if (!master) return [];

Expand Down Expand Up @@ -280,7 +281,7 @@ function getConfigVariable(app, param, useEnvVars) {
// it will now return `undefined`, for the use case of
// dynamic datasources url:`undefined` to fallback to other parameters
configVariable = undefined;
console.warn('%s does not resolve to a valid value, returned as %s. ' +
g.warn('%s does not resolve to a valid value, returned as %s. ' +
'"%s" must be resolvable in Environment variable or by app.get().',
param, configVariable, varName);
debug('Dynamic Configuration: Cannot resolve variable for `%s`, ' +
Expand Down
3 changes: 2 additions & 1 deletion lib/plugins/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var util = require('util');
var assert = require('assert');
var semver = require('semver');
var format = require('util').format;
var g = require('strong-globalize')();
var PluginBase = require('../plugin-base');

module.exports = function(options) {
Expand All @@ -28,7 +29,7 @@ function assertLoopBackVersion(app) {
// while loopback-boot treats pre-releases the same way as regular versions
var version = (loopback.version || '1.0.0').replace(/-.*$/, '');
if (!semver.satisfies(version, RANGE)) {
var msg = format(
var msg = g.f(
'The `app` is powered by an incompatible loopback version %s. ' +
'Supported versions: %s',
loopback.version || '(unknown)',
Expand Down
3 changes: 2 additions & 1 deletion lib/plugins/boot-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var path = require('path');
var async = require('async');
var debug = require('debug')('loopback:boot:script');
var PluginBase = require('../plugin-base');
var g = require('strong-globalize')();
var _ = require('lodash');

module.exports = function(options) {
Expand Down Expand Up @@ -67,7 +68,7 @@ function runScripts(app, list, callback) {
});
}
} catch (err) {
console.error('Failed loading boot script: %s\n%s', filepath, err.stack);
g.error('Failed loading boot script: %s\n%s', filepath, err.stack);
throw err;
}
});
Expand Down
17 changes: 9 additions & 8 deletions lib/plugins/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
var util = require('util');
var assert = require('assert');
var path = require('path');
var g = require('strong-globalize')();
var _ = require('lodash');
var cloneDeepWith = _.cloneDeepWith;
var cloneDeep = _.cloneDeep;
Expand All @@ -31,10 +32,10 @@ Middleware.prototype.merge = function(target, config, fileName) {
if (phase in target) {
err = this.mergePhaseConfig(target[phase], config[phase], phase);
} else {
err = 'The phase "' + phase + '" is not defined in the main config.';
err = g.f('The phase "%s" is not defined in the main config.', phase);
}
if (err)
throw new Error('Cannot apply ' + fileName + ': ' + err);
throw new Error(g.ft('Cannot apply %s: %s', fileName, err));
}
};

Expand Down Expand Up @@ -68,8 +69,8 @@ Middleware.prototype.mergePhaseConfig = function(target, config, phase) {
err = this.mergeObjects(targetMiddleware, configMiddleware);
}
} else {
err = 'The middleware "' + mw + '" in phase "' + phase + '"' +
'is not defined in the main config.';
err = g.f('The middleware "%s" in phase "%s"' +
'is not defined in the main config.', mw, phase);
}
if (err) return err;
}
Expand All @@ -93,7 +94,7 @@ Middleware.prototype.buildInstructions = function(context, rootDir, config) {
// if a non-optional middleware is not resolvable, it will throw
// at resolveAppPath() and not reach here
if (!resolved.sourceFile) {
return console.log('Middleware "%s" not found: %s',
return g.log('Middleware "%s" not found: %s',
middleware,
resolved.optional
);
Expand Down Expand Up @@ -234,11 +235,11 @@ Middleware.prototype.start = function(context) {
// Phases can be empty
var phases = instructions.phases || [];
assert(Array.isArray(phases),
'Middleware phases must be an array');
g.f('Middleware phases must be an array'));

var middleware = instructions.middleware;
assert(Array.isArray(middleware),
'Middleware must be an array');
g.f('Middleware must be an array'));

debug('Defining middleware phases %j', phases);
app.defineMiddlewarePhases(phases);
Expand All @@ -251,7 +252,7 @@ Middleware.prototype.start = function(context) {
factory = factory[data.fragment].bind(factory);
}
assert(typeof factory === 'function',
'Middleware factory must be a function');
g.f('Middleware factory must be a function'));
data.config = self.getUpdatedConfigObject(context, data.config,
{ useEnvVars: true });
app.middlewareFromConfig(factory, data.config);
Expand Down
5 changes: 3 additions & 2 deletions lib/plugins/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
var util = require('util');
var fs = require('fs');
var path = require('path');
var g = require('strong-globalize')();
var PluginBase = require('../plugin-base');
var _ = require('lodash');
var debug = require('debug')('loopback:boot:mixin');
Expand Down Expand Up @@ -162,8 +163,8 @@ function normalizeMixinName(str, options) {
return normalization(str);
}

var err = new Error('Invalid normalization format - "' +
normalization + '"');
var err = new Error(g.f('Invalid normalization format - "%s"',
normalization));
err.code = 'INVALID_NORMALIZATION_FORMAT';
throw err;
}
Expand Down
8 changes: 5 additions & 3 deletions lib/plugins/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var assert = require('assert');
var util = require('util');
var PluginBase = require('../plugin-base');
var path = require('path');
var g = require('strong-globalize')();
var debug = require('debug')('loopback:boot:model');
var _ = require('lodash');
var toposort = require('toposort');
Expand Down Expand Up @@ -235,7 +236,8 @@ function assertIsValidModelConfig(config) {

if (unsupported) {
throw new Error(
'The data in model-config.json is in the unsupported 1.x format.');
g.f('The data in {{model-config.json}} is ' +
'in the unsupported 1.x format.'));
}
}
}
Expand Down Expand Up @@ -267,12 +269,12 @@ Model.prototype.start = function(context) {
if (!data.definition) {
model = registry.getModel(name);
if (!model) {
throw new Error('Cannot configure unknown model ' + name);
throw new Error(g.f('Cannot configure unknown model %s', name));
}
debug('Configuring existing model %s', name);
} else if (isBuiltinLoopBackModel(app, data)) {
model = registry.getModel(name);
assert(model, 'Built-in model ' + name + ' should have been defined');
assert(model, g.f('Built-in model %s should have been defined', name));
debug('Configuring built-in LoopBack model %s', name);
} else {
debug('Creating new model %s %j', name, data.definition);
Expand Down
13 changes: 7 additions & 6 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

var debug = require('debug')('loopback:boot');
var path = require('path');
var g = require('strong-globalize')();
var Module = require('module');
var fs = require('fs');
var assert = require('assert');
Expand All @@ -30,7 +31,7 @@ var FILE_EXTENSION_JSON = exports.FILE_EXTENSION_JSON = '.json';
*/

function findScripts(dir, extensions) {
assert(dir, 'cannot require directory contents without directory name');
assert(dir, g.t('cannot require directory contents without directory name'));

var files = tryReadDir(dir);
extensions = extensions || _.keys(require.extensions);
Expand Down Expand Up @@ -141,7 +142,7 @@ function fixFileExtension(filepath, files, onlyScriptsExportingFunction) {
function resolveAppPath(rootDir, relativePath, resolveOptions) {
var resolvedPath = tryResolveAppPath(rootDir, relativePath, resolveOptions);
if (resolvedPath === undefined && !resolveOptions.optional) {
var err = new Error('Cannot resolve path "' + relativePath + '"');
var err = new Error(g.f('Cannot resolve path "%s"', relativePath));
err.code = 'PATH_NOT_FOUND';
throw err;
}
Expand Down Expand Up @@ -241,7 +242,7 @@ function tryResolveAppPath(rootDir, relativePath, resolveOptions) {
function assertIsValidConfig(name, config) {
if (config) {
assert(typeof config === 'object',
name + ' config must be a valid JSON object');
g.f('%s config must be a valid JSON object', name));
}
}

Expand Down Expand Up @@ -313,9 +314,9 @@ function mergePhaseNameLists(currentNames, namesToMerge) {
// A new phase - try to add it after the last one,
// unless it was already registered
if (targetArray.indexOf(valueToAdd) !== -1) {
throw new Error('Ordering conflict: cannot add "' + valueToAdd +
'" after "' + previousValue + '", because the opposite order was ' +
' already specified');
throw new Error(g.f('Ordering conflict: cannot add "%s" after "%s",' +
' because the opposite order was already specified',
valueToAdd, previousValue));
}
var previousIx = targetArray.indexOf(previousValue);
targetArray.splice(previousIx + 1, 0, valueToAdd);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"debug": "^2.2.0",
"lodash": "^4.13.1",
"semver": "^5.1.0",
"strong-globalize": "^2.5.5",
"toposort": "^1.0.0"
},
"devDependencies": {
Expand Down