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

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