diff --git a/bin/lb-ng.js b/bin/lb-ng.js index 88e0de2..704ed80 100755 --- a/bin/lb-ng.js +++ b/bin/lb-ng.js @@ -19,7 +19,9 @@ var argv = optimist .describe('m', g.f('The name for generated {{Angular}} module.')) .default('m', 'lbServices') .describe('u', g.f('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; @@ -39,9 +41,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; g.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 fc26f74..c2916ad 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ }, "dependencies": { "bluebird": "^1.2.4", - "loopback-sdk-angular": "^1.1.1", + "loopback-sdk-angular": "^1.8.0", "optimist": "^0.6.1", "semver": "^2.2.1", "strong-globalize": "^2.6.0" diff --git a/test/fixtures/app.js b/test/fixtures/app.js index 80187f6..9aeb20a 100644 --- a/test/fixtures/app.js +++ b/test/fixtures/app.js @@ -15,4 +15,11 @@ app.model(User, { dataSource: 'db' }); app.set('restApiRoot', '/rest-api-root'); +app.dataSource('db', { connector: 'memory' }); +var TestModel = app.registry.createModel( + 'TestModel', + { foobaz: 'string' } +); +app.model(TestModel, { dataSource: 'db' }); + module.exports = app; diff --git a/test/lb-ng.test.js b/test/lb-ng.test.js index f2d80b8..74362f3 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)