Skip to content
Merged
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
11 changes: 9 additions & 2 deletions bin/lb-ng.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
8 changes: 8 additions & 0 deletions test/lb-ng.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down