Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): add models option in discover cli command to generate spec… #8612

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
2 changes: 2 additions & 0 deletions docs/site/Discovering-models.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ placed. Default is `src/models`
`--schema`: Specify the schema which the datasource will find the models to
discover

`--models`: generate the specific models

`--optionalId`: Specify if the Id property of generated models will be marked as
not required

Expand Down
6 changes: 6 additions & 0 deletions packages/cli/.yo-rc.json
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,12 @@
"name": "outDir",
"hide": false
},
"models": {
"type": "String",
"description": "Discover specific models without prompting users to select ex:--models=tale1,table2",
"name": "models",
"hide": false
},
"optionalId": {
"type": "Boolean",
"description": "Boolean to mark id property as optional field",
Expand Down
18 changes: 18 additions & 0 deletions packages/cli/generators/discover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator {
default: undefined,
});

this.option('models', {
type: String,
description: g.f(
'Discover specific models without prompting users to select ex:--models=tale1,table2',
),
default: undefined,
});

this.option('optionalId', {
type: Boolean,
description: g.f('Boolean to mark id property as optional field'),
Expand Down Expand Up @@ -198,6 +206,16 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator {
this.discoveringModels = this.modelChoices;
}

if (this.options.models) {
const answers = {discoveringModels: this.options.models.split(',')};
debug(`Models chosen: ${JSON.stringify(answers)}`);
this.discoveringModels = [];
answers.discoveringModels.forEach(m => {
this.discoveringModels.push(this.modelChoices.find(c => c.name === m));
});
return;
}

const prompts = [
{
name: 'discoveringModels',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,12 @@ exports[`cli saves command metadata to .yo-rc.json 1`] = `
"name": "outDir",
"hide": false
},
"models": {
"type": "String",
"description": "Discover specific models without prompting users to select ex:--models=tale1,table2",
"name": "models",
"hide": false
},
"optionalId": {
"type": "Boolean",
"description": "Boolean to mark id property as optional field",
Expand Down
20 changes: 20 additions & 0 deletions packages/cli/test/integration/generators/discover.integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ const disableCamelCaseOptions = {
const missingDataSourceOptions = {
dataSource: 'foo',
};
const specificmodelsOptions = {
models: 'Test',
dataSource: 'mem',
views: false,
disableCamelCase: true,
};
const optionalIdOptions = {
...baseOptions,
optionalId: true,
Expand Down Expand Up @@ -174,4 +180,18 @@ describe('lb4 discover integration', () => {
expectFileToMatchSnapshot(defaultExpectedTestModel);
});
});

it('generates specific models without prompts using --models', async () => {
await testUtils
.executeGenerator(generator)
.inDir(sandbox.path, () =>
testUtils.givenLBProject(sandbox.path, {
additionalFiles: SANDBOX_FILES,
}),
)
.withOptions(specificmodelsOptions);

basicModelFileChecks(defaultExpectedTestModel, defaultExpectedIndexFile);
assert.file(defaultExpectedTestModel);
});
});