diff --git a/bin/lb-ng b/bin/lb-ng index 7b2dc09..6750239 100755 --- a/bin/lb-ng +++ b/bin/lb-ng @@ -13,7 +13,9 @@ var argv = optimist .describe('m', 'The name for generated Angular module.') .default('m', 'lbServices') .describe('u', 'URL of the REST API end-point') - .alias({ u : 'url', m: 'module-name' }) + .describe('s', 'Include schema definition in generated models') + .boolean('s') + .alias({ u : 'url', m: 'module-name', s: 'include-schema' }) .demand(1) .argv; @@ -33,9 +35,14 @@ if (app.booting) { function runGenerator() { var ngModuleName = argv['module-name'] || 'lbServices'; var apiUrl = argv['url'] || app.get('restApiRoot') || '/api'; + var includeSchema = argv['include-schema'] || false; console.error('Generating %j for the API endpoint %j', ngModuleName, apiUrl); - var result = generator.services(app, ngModuleName, apiUrl); + var result = generator.services(app, { + ngModuleName: ngModuleName, + apiUrl: apiUrl, + includeSchema: includeSchema + }); if (outputFile) { outputFile = path.resolve(outputFile); diff --git a/package.json b/package.json index fab81e8..6cc72a5 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "node": ">= 0.8.0" }, "dependencies": { - "loopback-sdk-angular": "^1.1.1", + "loopback-sdk-angular": "^1.8.0", "optimist": "^0.6.1", "semver": "^2.2.1" }, diff --git a/test/fixtures/app.js b/test/fixtures/app.js index f48302e..e9358d3 100644 --- a/test/fixtures/app.js +++ b/test/fixtures/app.js @@ -8,4 +8,33 @@ var app = loopback(); app.set('restApiRoot', '/rest-api-root'); +app.dataSource('db', { connector: 'memory' }); +var TestModel = app.registry.createModel( + 'TestModel', + { foobaz: 'string' } +); +app.model(TestModel, { dataSource: 'db' }); + +// this is a hack to give the angular SDK a model to export +// TODO: find out why the model created above is not +// returned by the rest adapter +var TestClass = { + name: 'TestModel', + sharedClass: { + ctor: { + settings: { + description: 'Test Class', + }, + }, + }, + ctor: { + getFullPath: function() {} + }, + methods: [], +}; + +app.handler('rest').adapter.getClasses = function() { + return [TestClass]; +}; + module.exports = app; diff --git a/test/lb-ng.test.js b/test/lb-ng.test.js index 4d8cefe..1ad540e 100644 --- a/test/lb-ng.test.js +++ b/test/lb-ng.test.js @@ -54,6 +54,14 @@ describe('lb-ng', function() { }); }); + it('passes the include-schema flag from the command-line', function() { + return runLbNg('-s', sampleAppJs) + .spread(function(script, stderr) { + expect(script).to.contain('R\.schema ='); + expect(script).to.contain('schema of the model'); + }); + }); + it('saves the script to a file', function() { var outfile = path.resolve(SANDBOX, 'lb-services.js'); return runLbNg('-m', 'a-module', sampleAppJs, outfile)