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
10 changes: 10 additions & 0 deletions model/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ module.exports = class ModelGenerator extends ActionsMixin(yeoman) {

askForName() {
if (this.abort) return;

if (this.arguments && this.arguments.length >= 1) {
debug('model name is provided as %s', this.arguments[0]);
this.name = this.arguments[0];
var valid = validateRequiredName(this.name);
if (valid === true) return;
this.log(valid);
this.name = undefined;
}

var prompts = [
{
name: 'name',
Expand Down
19 changes: 19 additions & 0 deletions test/model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,19 @@ describe('loopback:model generator', function() {
});
});

it('honors the model name in arg', function() {
return helpers.run(path.join(__dirname, '../model'))
.cd(SANDBOX)
.withArguments(['AdvancedProduct'])
.withPrompts({
dataSource: 'db',
base: 'Product',
}).then(function() {
var product = readAdvancedProductJsonSync();
expect(product).to.have.property('base', 'Product');
});
});

describe('in an empty project', function() {
beforeEach(common.resetWorkspace);
beforeEach(function createSandbox(done) {
Expand Down Expand Up @@ -267,6 +280,12 @@ describe('loopback:model generator', function() {
return JSON.parse(fs.readFileSync(productJson));
}

function readAdvancedProductJsonSync() {
var advancedProductJson = path.resolve(SANDBOX, 'common/models/advanced-product.json');
expect(fs.existsSync(advancedProductJson), 'file exists');
return JSON.parse(fs.readFileSync(advancedProductJson));
}

function readModelsJsonSync(facet) {
facet = facet || 'server';
var filepath = path.resolve(SANDBOX, facet, 'model-config.json');
Expand Down