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): specify models with --models in lb4 discover #9092

Merged
merged 1 commit into from
Feb 26, 2023
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
3 changes: 3 additions & 0 deletions docs/site/Discovering-models.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ placed. Default is `src/models`
`--schema`: Specify the schema which the datasource will find the models to
discover

**`--models`**: Specify the models to be generated e.g:--models=table1,table2

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

not required

### Interactive Prompts
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 e.g:--models=table1,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 e.g:--models=table1,table2',
),
default: undefined,
});

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

if (this.options.models) {
const answers = {discoveringModels: this.options.models.split(',')};
debug(`Models specified: ${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 e.g:--models=table1,table2",
"name": "models",
"hide": false
},
"optionalId": {
"type": "Boolean",
"description": "Boolean to mark id property as optional field",
Expand Down
19 changes: 19 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,17 @@ 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);
});
});