From 8fcb600147e6301bf69b7883dc3cc7cd63bc040e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Tue, 27 May 2014 10:35:14 +0200 Subject: [PATCH 1/7] api: configure datasources via loopback-boot Move the configuration of datasources to datasources.json, add environment-specific configuration files. Modify api/app.ap.js to setup datasources via loopback-boot. --- api/app.api.js | 19 +++++++++++++------ api/configure.js | 14 -------------- api/datasources.json | 6 ++++++ api/datasources.production.js | 2 ++ api/datasources.staging.js | 12 ++++++++++++ package.json | 1 + 6 files changed, 34 insertions(+), 20 deletions(-) create mode 100644 api/datasources.json create mode 100644 api/datasources.production.js create mode 100644 api/datasources.staging.js diff --git a/api/app.api.js b/api/app.api.js index ce43545..a708571 100644 --- a/api/app.api.js +++ b/api/app.api.js @@ -3,18 +3,25 @@ var path = require('path'); var loopback = require('loopback'); var explorer = require('loopback-explorer'); var CONFIG = require('global.config'); -var LOCAL_CONFIG = require('local.config'); +var boot = require('loopback-boot'); // server var server = module.exports = loopback(); -// data source -// var db = loopback.createDataSource(LOCAL_CONFIG.db); -var db = loopback.createDataSource({ - connector: require('loopback-connector-mongodb'), - database: 'todo-example' +boot(server, { + appRootDir: path.resolve(__dirname), + appConfig: { + // No app config to load, we are processing it manually now + // TODO(bajtos) modify Gulp to create app.* config files + }, + models: { + // No models to load, we are building them manually now + // TODO(bajtos) Move model definitions to models.json + } }); +var db = server.datasources.db; + // models var User = require('models/user'); var Todo = require('models/todo'); diff --git a/api/configure.js b/api/configure.js index 3ea2a2c..2a4e2b0 100644 --- a/api/configure.js +++ b/api/configure.js @@ -6,17 +6,3 @@ exports.global = function(env, global) { root: '/api' }; } - -exports.local = function(env, global, local) { - var db = local.db = {}; - - if(env === 'staging' || env === 'production') { - db.host = process.env.DB_HOST || global.api.host; - db.port = process.env.DB_PORT || 27015; - db.connector = 'mongodb'; - db.user = process.env.DB_USER; - db.password = process.env.DB_PASSWORD; - } else { - db.connector = 'memory'; - } -} diff --git a/api/datasources.json b/api/datasources.json new file mode 100644 index 0000000..ee53ada --- /dev/null +++ b/api/datasources.json @@ -0,0 +1,6 @@ +{ + "db": { + "connector": "memory", + "defaultForType": "db" + } +} diff --git a/api/datasources.production.js b/api/datasources.production.js new file mode 100644 index 0000000..e1680e1 --- /dev/null +++ b/api/datasources.production.js @@ -0,0 +1,2 @@ +// Use the same environment-based configuration as in staging +module.exports = require('./datasources.staging'); diff --git a/api/datasources.staging.js b/api/datasources.staging.js new file mode 100644 index 0000000..2d40ca7 --- /dev/null +++ b/api/datasources.staging.js @@ -0,0 +1,12 @@ +var globalConfig = require('global.config'); + +module.exports = { + db: { + connector: 'mongodb', + hostname: process.env.DB_HOST || globalConfig.api.host, + port: process.env.DB_PORT || 27017, + user: process.env.DB_USER, + password: process.env.DB_PASSWORD, + database: 'todo-example', + } +}; diff --git a/package.json b/package.json index 7ec9d10..fed7240 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "loopback-explorer": "~1.1.0", "loopback-connector-mongodb": "^1.2.4", "loopback-datasource-juggler": "2.0.0-beta1", + "loopback-boot": "strongloop/loopback-boot", "ejs": "^1.0.0" } } From ad202ef4239e10c46c03f2b5154decca240302f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Tue, 27 May 2014 13:10:09 +0200 Subject: [PATCH 2/7] html5: enable sourcemaps in debug env --- html5/configure.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/html5/configure.js b/html5/configure.js index 6b53f2c..c4424aa 100644 --- a/html5/configure.js +++ b/html5/configure.js @@ -76,7 +76,11 @@ exports.build = function(env, global, local, cb) { }, 'uglifyify'); } - b.bundle().pipe(out); + b.bundle({ + // TODO(bajtos) debug should be always true, the sourcemaps should be + // saved to a standalone file when !isDev(env) + debug: isDev(env) + }).pipe(out); out.on('error', cb); out.on('close', cb); From eb5cfdaef51986dda7f2caf60be499194456470b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Tue, 27 May 2014 13:36:02 +0200 Subject: [PATCH 3/7] html5: load datasources from datasources.json Modify configure.js script to merge all datasource config files and create a single browserify-enabled file. Modify html5/app.html5.js to dynamically register datasources provided in the config file. Modify configuration of the `watch` task to include json files in the change detection list. --- gulpfile.js | 4 +++- html5/app.html5.js | 17 ++++++++------- html5/configure.js | 42 ++++++++++++++++++++++++++++++++++++++ html5/datasources.json | 9 ++++++++ html5/datasources.local.js | 7 +++++++ 5 files changed, 69 insertions(+), 10 deletions(-) create mode 100644 html5/datasources.json create mode 100644 html5/datasources.local.js diff --git a/gulpfile.js b/gulpfile.js index 9468d11..2c62981 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -67,8 +67,10 @@ function findAndBuild(packageName, cb) { function findSrc(package) { var paths = []; findPackages(package).forEach(function(pkg) { - paths.push(path.join(__dirname, pkg, '*', '*') + '.js'); + paths.push(path.join(__dirname, pkg, '*', '*.js')); + paths.push(path.join(__dirname, pkg, '*', '*.json')); paths.push(path.join(__dirname, pkg, '*.js')); + paths.push(path.join(__dirname, pkg, '*.json')); }); return paths; } diff --git a/html5/app.html5.js b/html5/app.html5.js index c22d5c8..66c289d 100644 --- a/html5/app.html5.js +++ b/html5/app.html5.js @@ -2,22 +2,21 @@ var LOCAL_CONFIG = require('local.config'); var loopback = require('loopback'); var client = exports.client = loopback(); -var async = require('async'); // angular.js dependencies require('./bower_components/angular/angular.js'); require('./bower_components/angular-route/angular-route.js'); -// data sources -var remote = loopback.createDataSource({ - connector: loopback.Remote, - url: LOCAL_CONFIG.serverInfo.url -}); -var memory = loopback.createDataSource({ - connector: loopback.Memory, - localStorage: 'todo-db' +var lbapp = loopback(); + +var dataSourceConfig = require('./build/datasources.js'); +Object.keys(dataSourceConfig).forEach(function(key) { + lbapp.dataSource(key, dataSourceConfig[key]); }); +var remote = lbapp.datasources.remote; +var memory = lbapp.datasources.memory; + // models var User = require('models/user'); var RemoteTodo = window.RemoteTodo = require('models/todo'); diff --git a/html5/configure.js b/html5/configure.js index c4424aa..ce03bc3 100644 --- a/html5/configure.js +++ b/html5/configure.js @@ -1,9 +1,11 @@ var gulp = require('gulp'); +var async = require('async'); var path = require('path'); var pkg = require('./package.json'); var fs = require('fs'); var browserify = require('browserify'); var sh = require('shelljs'); +var BootConfigLoader = require('loopback-boot').ConfigLoader; exports.global = function(env, global) { // routes @@ -61,6 +63,46 @@ exports.local = function configure(env, global, local) { } exports.build = function(env, global, local, cb) { + async.waterfall([ + function(next) { + buildDataSources(env, next); + }, + function(next) { + createBundle(env, global, next); + } + ], cb); +}; + +function buildDataSources(env, cb) { + var dataSources = BootConfigLoader.loadDataSources(__dirname, env); + for (var name in dataSources) { + var cfg = dataSources[name]; + var connector = cfg.connector.toLowerCase(); + if (connector === 'memory' || connector === 'remote') { + cfg.connector = '::ref::' + connector; + } else { + return cb(new Error( + 'Datasource ' + name + ' uses unknown connector ' + connector + '.')); + } + } + + var dsconfig = 'var loopback = require(\'loopback\');' + + '\nmodule.exports = ' + + JSON.stringify(dataSources, null, 2) + + ';\n'; + + dsconfig = dsconfig + .replace(/"::ref::memory"/g, 'loopback.Memory') + .replace(/"::ref::remote"/g, 'loopback.Remote'); + + fs.writeFile( + path.resolve(__dirname, 'build', 'datasources.js'), + dsconfig, + 'utf-8', + cb); +} + +function createBundle(env, global, cb) { var b = browserify({basedir: __dirname}); b.add('./' + pkg.main); diff --git a/html5/datasources.json b/html5/datasources.json new file mode 100644 index 0000000..6000ecf --- /dev/null +++ b/html5/datasources.json @@ -0,0 +1,9 @@ +{ + "remote": { + "connector": "remote" + }, + "memory": { + "connector": "memory", + "localStorage": "todo-db" + } +} diff --git a/html5/datasources.local.js b/html5/datasources.local.js new file mode 100644 index 0000000..23a28e4 --- /dev/null +++ b/html5/datasources.local.js @@ -0,0 +1,7 @@ +var LOCAL_CONFIG = require('local.config'); + +module.exports = { + remote: { + url: LOCAL_CONFIG.serverInfo.url + } +}; From 9a11471fb9dcac2b1b88622a910f2a7c48a82085 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Tue, 27 May 2014 17:11:58 +0200 Subject: [PATCH 4/7] Load models from models.json Move the definition-releated code from models/*.js to models.json. Modify api/app.api.js to load modes via `app.boot`. Modify html5/configure.js to generate a script that will register all models and statically require() all models/*.js files. Define client-only models in `html5/client.models.json`. Rename client datasources: remote -> db (match shared models) memory -> local --- api/app.api.js | 18 +-------- html5/app.html5.js | 50 +++++++++++++------------ html5/client.models.json | 8 ++++ html5/configure.js | 58 +++++++++++++++++++++++++++- html5/datasources.json | 4 +- html5/datasources.local.js | 2 +- models.json | 37 ++++++++++++++++++ models/index.js | 2 - models/package.json | 11 ------ models/todo.js | 77 ++++++++++++++++++-------------------- models/user.js | 6 --- 11 files changed, 169 insertions(+), 104 deletions(-) create mode 100644 html5/client.models.json create mode 100644 models.json delete mode 100644 models/index.js delete mode 100644 models/package.json delete mode 100644 models/user.js diff --git a/api/app.api.js b/api/app.api.js index a708571..5395f5d 100644 --- a/api/app.api.js +++ b/api/app.api.js @@ -10,29 +10,15 @@ var server = module.exports = loopback(); boot(server, { appRootDir: path.resolve(__dirname), + modelsRootDir: path.resolve(__dirname, '..'), appConfig: { // No app config to load, we are processing it manually now // TODO(bajtos) modify Gulp to create app.* config files }, - models: { - // No models to load, we are building them manually now - // TODO(bajtos) Move model definitions to models.json - } }); -var db = server.datasources.db; - -// models -var User = require('models/user'); -var Todo = require('models/todo'); - -// setup the model data sources -User.attachTo(db); -Todo.attachTo(db); -server.model(User); -server.model(Todo); - // TODO(ritch) this should be unecessary soon.... +var Todo = server.models.Todo; server.model(Todo.getChangeModel()); // root api path diff --git a/html5/app.html5.js b/html5/app.html5.js index 66c289d..814ed5b 100644 --- a/html5/app.html5.js +++ b/html5/app.html5.js @@ -14,13 +14,33 @@ Object.keys(dataSourceConfig).forEach(function(key) { lbapp.dataSource(key, dataSourceConfig[key]); }); -var remote = lbapp.datasources.remote; -var memory = lbapp.datasources.memory; +require('./build/models.js')(lbapp); -// models -var User = require('models/user'); -var RemoteTodo = window.RemoteTodo = require('models/todo'); -var LocalTodo = window.LocalTodo = RemoteTodo.extend('LocalTodo'); +// TODO(bajtos) Move the bi-di replication to loopback core, +// add model settings to enable the replication. +// Example: +// LocalTodo: { options: { +// base: 'Todo', +// replicate: { +// target: 'Todo', +// mode: 'push' | 'pull' | 'bidi' +// }}} + +var LocalTodo = lbapp.models.LocalTodo; +var RemoteTodo = lbapp.models.Todo; + +// setup model replication +function sync(cb) { + if(window.connected()) { + RemoteTodo.replicate(LocalTodo, function() { + LocalTodo.replicate(RemoteTodo, cb); + }); + } +} + +// sync local changes if connected +LocalTodo.on('changed', sync); +LocalTodo.on('deleted', sync); // routes var routes = LOCAL_CONFIG.routes; @@ -46,11 +66,6 @@ require('./controllers/login.ctrl'); require('./controllers/register.ctrl'); require('./controllers/change.ctrl'); -// setup the model data sources -RemoteTodo.attachTo(remote); -LocalTodo.attachTo(memory); - - window.isConnected = true; window.connected = function connected() { @@ -58,19 +73,6 @@ window.connected = function connected() { return window.isConnected; } -// setup model replication -function sync(cb) { - if(connected()) { - RemoteTodo.replicate(LocalTodo, function() { - LocalTodo.replicate(RemoteTodo, cb); - }); - } -} - -// sync local changes if connected -LocalTodo.on('changed', sync); -LocalTodo.on('deleted', sync); - // setup routes Object.keys(routes) .forEach(function(route) { diff --git a/html5/client.models.json b/html5/client.models.json new file mode 100644 index 0000000..226454e --- /dev/null +++ b/html5/client.models.json @@ -0,0 +1,8 @@ +{ + "LocalTodo": { + "dataSource": "local", + "options": { + "base": "Todo" + } + } +} diff --git a/html5/configure.js b/html5/configure.js index ce03bc3..887fe5c 100644 --- a/html5/configure.js +++ b/html5/configure.js @@ -65,7 +65,14 @@ exports.local = function configure(env, global, local) { exports.build = function(env, global, local, cb) { async.waterfall([ function(next) { - buildDataSources(env, next); + async.parallel([ + function(next) { + buildDataSources(env, next); + }, + function(next) { + buildModels(env, next); + } + ], function(err) { next(err); }); }, function(next) { createBundle(env, global, next); @@ -102,6 +109,55 @@ function buildDataSources(env, cb) { cb); } +function buildModels(env, cb) { + var models = BootConfigLoader.loadModels(path.resolve(__dirname, '..'), env); + var clientModels = require('./client.models.json'); + + var modelsFile = path.resolve(__dirname, 'build', 'models.js'); + var modelsDir = path.resolve(__dirname, '..', 'models'); + + fs.readdir(modelsDir, function(err, files) { + if (err) return cb(err); + + var code = 'var loopback = require(\'loopback\');\n' + + 'var models, clientModels;\n\n' + + 'module.exports = function(app) {\n' + + ' for (var name in models) {\n' + + ' app.model(name, models[name]);\n' + + ' }\n\n'; + + files.forEach(function(f) { + f = path.resolve(modelsDir, f); + if (path.extname(f) !== '.js' || !fs.statSync(f).isFile()) return; + var relative = path.relative(path.dirname(modelsFile), f); + code += ' runExportedFn(app, require(' + + JSON.stringify(relative) + '));\n'; + }); + + // It is important to create client models only after the shared models + // were fully initialized. Otherwise client models extending server models + // won't get static methods defined in models/*.js scripts. + code += '\n' + + ' for (name in clientModels) {\n' + + ' app.model(name, clientModels[name]);\n' + + ' }\n'; + + // end of the exported fn + code += '};\n'; + + code += '\nmodels = ' + JSON.stringify(models, null, 2) + ';\n'; + code += '\nclientModels = ' + JSON.stringify(clientModels, null, 2) + ';\n'; + code += '\nfunction runExportedFn(app, fn) {\n' + + ' var executable = typeof fn === \'function\' &&\n' + + ' !(fn.prototype instanceof loopback.Model);\n' + + ' if (!executable) return;\n' + + ' fn(app);\n' + + '}'; + + fs.writeFile(modelsFile, code, 'utf-8', cb); + }); +} + function createBundle(env, global, cb) { var b = browserify({basedir: __dirname}); b.add('./' + pkg.main); diff --git a/html5/datasources.json b/html5/datasources.json index 6000ecf..5ef7a4a 100644 --- a/html5/datasources.json +++ b/html5/datasources.json @@ -1,8 +1,8 @@ { - "remote": { + "db": { "connector": "remote" }, - "memory": { + "local": { "connector": "memory", "localStorage": "todo-db" } diff --git a/html5/datasources.local.js b/html5/datasources.local.js index 23a28e4..b578bc0 100644 --- a/html5/datasources.local.js +++ b/html5/datasources.local.js @@ -1,7 +1,7 @@ var LOCAL_CONFIG = require('local.config'); module.exports = { - remote: { + db: { url: LOCAL_CONFIG.serverInfo.url } }; diff --git a/models.json b/models.json new file mode 100644 index 0000000..0a6fd45 --- /dev/null +++ b/models.json @@ -0,0 +1,37 @@ +{ + "Todo": { + "options": { + "trackChanges": true, + "base": "DataModel" + }, + "properties": { + "id": { + "id": true, + "type": "string" + }, + "title": "string", + "completed": { + "type": "boolean", + "default": false + }, + "created": { + "type": "number", + "//default": "//TODO: Date.now" + } + }, + "dataSource": "db" + }, + "user": { + "options": { + "base": "User" + }, + "properties": { + "title": "string", + "done": { + "type": "boolean", + "default": false + } + }, + "dataSource": "db" + } +} diff --git a/models/index.js b/models/index.js deleted file mode 100644 index 096a804..0000000 --- a/models/index.js +++ /dev/null @@ -1,2 +0,0 @@ -exports.Todo = require('./todo'); -exports.User = require('./user'); diff --git a/models/package.json b/models/package.json deleted file mode 100644 index 9cd65fb..0000000 --- a/models/package.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": "models", - "version": "0.0.0", - "description": "", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "author": "", - "license": "ISC" -} diff --git a/models/todo.js b/models/todo.js index 2c908ee..298d181 100644 --- a/models/todo.js +++ b/models/todo.js @@ -1,50 +1,45 @@ var loopback = require('loopback'); var async = require('async'); -var Todo = module.exports = loopback.DataModel.extend('Todo', { - id: {id: true, type: String}, - title: String, - completed: {type: Boolean, default: false}, - created: {type: Number, default: Date.now} -}, { - trackChanges: true -}); +module.exports = function(app) { + var Todo = app.models.Todo; -Todo.beforeSave = function(next, model) { - if(!model.id) model.id = 't-' + Math.floor(Math.random() * 10000).toString(); - next(); -} + Todo.beforeSave = function(next, model) { + if (!model.id) model.id = 't-' + Math.floor(Math.random() * 10000).toString(); + next(); + }; -Todo.stats = function(filter, cb) { - var stats = {}; - cb = arguments[arguments.length - 1]; - var Todo = this; - - async.parallel([ - countComplete, - count - ], function(err) { - if(err) return cb(err); - stats.remaining = stats.total - stats.completed; - cb(null, stats); - }); + Todo.stats = function(filter, cb) { + var stats = {}; + cb = arguments[arguments.length - 1]; + var Todo = this; - function countComplete(cb) { - Todo.count({completed: true}, function(err, count) { - stats.completed = count; - cb(err); + async.parallel([ + countComplete, + count + ], function(err) { + if (err) return cb(err); + stats.remaining = stats.total - stats.completed; + cb(null, stats); }); - } - function count(cb) { - Todo.count(function(err, count) { - stats.total = count; - cb(err); - }); - } -} + function countComplete(cb) { + Todo.count({completed: true}, function(err, count) { + stats.completed = count; + cb(err); + }); + } -loopback.remoteMethod(Todo.stats, { - accepts: {arg: 'filter', type: 'object'}, - returns: {arg: 'stats', type: 'object'} -}); + function count(cb) { + Todo.count(function(err, count) { + stats.total = count; + cb(err); + }); + } + }; + + loopback.remoteMethod(Todo.stats, { + accepts: {arg: 'filter', type: 'object'}, + returns: {arg: 'stats', type: 'object'} + }); +}; diff --git a/models/user.js b/models/user.js deleted file mode 100644 index b7a2eae..0000000 --- a/models/user.js +++ /dev/null @@ -1,6 +0,0 @@ -var loopback = require('loopback'); - -var User = module.exports = loopback.User.extend('User', { - title: String, - done: {type: Boolean, default: false} -}); From fd96e75744a501c1953e9fe01a02f672a2e39e95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Wed, 28 May 2014 16:41:34 +0200 Subject: [PATCH 5/7] html5/configure: add TODOs --- html5/configure.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/html5/configure.js b/html5/configure.js index 887fe5c..03570d0 100644 --- a/html5/configure.js +++ b/html5/configure.js @@ -81,6 +81,7 @@ exports.build = function(env, global, local, cb) { }; function buildDataSources(env, cb) { + // TODO(bajtos) Get rid of '::ref::' code, use loopback#287 instead var dataSources = BootConfigLoader.loadDataSources(__dirname, env); for (var name in dataSources) { var cfg = dataSources[name]; @@ -142,6 +143,8 @@ function buildModels(env, cb) { ' app.model(name, clientModels[name]);\n' + ' }\n'; + //TODO(bajtos) Require and run all files in `client.models/*` + // end of the exported fn code += '};\n'; From 958c7f280caf89afe3a74e0ec5bd24e51ff6fb41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Wed, 28 May 2014 16:47:40 +0200 Subject: [PATCH 6/7] html5: move datasource loader to generated script Move the loop defining all data-sources from hand-written html5/app.html5.js to the code generated by html5/configure.js. This new way is consistent with how models are loaded. --- html5/app.html5.js | 6 +----- html5/configure.js | 9 ++++++++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/html5/app.html5.js b/html5/app.html5.js index 814ed5b..b78ae97 100644 --- a/html5/app.html5.js +++ b/html5/app.html5.js @@ -9,11 +9,7 @@ require('./bower_components/angular-route/angular-route.js'); var lbapp = loopback(); -var dataSourceConfig = require('./build/datasources.js'); -Object.keys(dataSourceConfig).forEach(function(key) { - lbapp.dataSource(key, dataSourceConfig[key]); -}); - +require('./build/datasources.js')(lbapp); require('./build/models.js')(lbapp); // TODO(bajtos) Move the bi-di replication to loopback core, diff --git a/html5/configure.js b/html5/configure.js index 03570d0..351e453 100644 --- a/html5/configure.js +++ b/html5/configure.js @@ -95,7 +95,14 @@ function buildDataSources(env, cb) { } var dsconfig = 'var loopback = require(\'loopback\');' + - '\nmodule.exports = ' + + '\nvar config;' + + '\nmodule.exports = function(app) {\n' + + ' for (var name in config) {\n' + + ' app.dataSource(name, config[name]);\n' + + ' }\n'+ + '};\n' + + '\n' + + 'config = ' + JSON.stringify(dataSources, null, 2) + ';\n'; From a3d5be3e08b0ae1e4b4a0c3bb0970233d9ae9a4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Wed, 28 May 2014 18:55:18 +0200 Subject: [PATCH 7/7] Get rid of ::ref:: in datasources.js generator Upgrade loopback to 2.0.0-beta3. Simplify html5/configure.js and remove the hack to convert `"memory"` to `loopback.Memory`, since the built-in connectors are registered in `app.connectors` now. --- html5/configure.js | 11 ++--------- package.json | 2 +- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/html5/configure.js b/html5/configure.js index 351e453..37f89f5 100644 --- a/html5/configure.js +++ b/html5/configure.js @@ -81,14 +81,11 @@ exports.build = function(env, global, local, cb) { }; function buildDataSources(env, cb) { - // TODO(bajtos) Get rid of '::ref::' code, use loopback#287 instead var dataSources = BootConfigLoader.loadDataSources(__dirname, env); for (var name in dataSources) { var cfg = dataSources[name]; - var connector = cfg.connector.toLowerCase(); - if (connector === 'memory' || connector === 'remote') { - cfg.connector = '::ref::' + connector; - } else { + var connector = cfg.connector; + if (connector !== 'memory' && connector !== 'remote') { return cb(new Error( 'Datasource ' + name + ' uses unknown connector ' + connector + '.')); } @@ -106,10 +103,6 @@ function buildDataSources(env, cb) { JSON.stringify(dataSources, null, 2) + ';\n'; - dsconfig = dsconfig - .replace(/"::ref::memory"/g, 'loopback.Memory') - .replace(/"::ref::remote"/g, 'loopback.Remote'); - fs.writeFile( path.resolve(__dirname, 'build', 'datasources.js'), dsconfig, diff --git a/package.json b/package.json index fed7240..5381488 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ }, "dependencies": { "async": "~0.7.0", - "loopback": "2.0.0-beta2", + "loopback": "2.0.0-beta3", "loopback-explorer": "~1.1.0", "loopback-connector-mongodb": "^1.2.4", "loopback-datasource-juggler": "2.0.0-beta1",