Skip to content

Commit 0c69224

Browse files
warisniz02dhmlau
authored andcommitted
fix: change dataSource to datasource for consistency
Signed-off-by: warisniz02 <warisniz02@gmail.com> Signed-off-by: warisniz02 <warisniz02@gmail.com> Signed-off-by: warisniz02 <warisniz02@gmail.com> Signed-off-by: warisniz02 <warisniz02@gmail.com> Signed-off-by: warisniz02 <warisniz02@gmail.com> Signed-off-by: warisniz02 <warisniz02@gmail.com> Signed-off-by: warisniz02 <warisniz02@gmail.com> Signed-off-by: warisniz02 <warisniz02@gmail.com>
1 parent 666a3af commit 0c69224

6 files changed

Lines changed: 99 additions & 7 deletions

File tree

docs/site/Discovering-models.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ Models can be discovered from a supported datasource by running the
3535

3636
### Options
3737

38-
`--dataSource`: Put a valid datasource name here to skip the datasource prompt
38+
`--dataSource or --datasource`: Put a valid datasource name here to skip the
39+
datasource prompt
3940

4041
`--views`: Choose whether to discover views. Default is true
4142

packages/cli/.yo-rc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,12 @@
12431243
"name": "dataSource",
12441244
"hide": false
12451245
},
1246+
"datasource": {
1247+
"type": "String",
1248+
"description": "The name of the datasource to discover",
1249+
"name": "datasource",
1250+
"hide": false
1251+
},
12461252
"views": {
12471253
"type": "Boolean",
12481254
"description": "Boolean to discover views",

packages/cli/generators/discover/index.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator {
2525
description: g.f('The name of the datasource to discover'),
2626
});
2727

28+
this.option('datasource', {
29+
type: String,
30+
description: g.f('The name of the datasource to discover'),
31+
});
32+
2833
this.option('views', {
2934
type: Boolean,
3035
description: g.f('Boolean to discover views'),
@@ -88,10 +93,12 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator {
8893
*/
8994
setOptions() {
9095
/* istanbul ignore next */
91-
if (this.options.dataSource) {
92-
debug(`Data source specified: ${this.options.dataSource}`);
96+
if (this.options.dataSource || this.options.datasource) {
97+
debug(
98+
`Data source specified: ${this.options.dataSource || this.options.datasource}`,
99+
);
93100
this.artifactInfo.dataSource = modelMaker.loadDataSourceByName(
94-
this.options.dataSource,
101+
this.options.dataSource || this.options.datasource,
95102
);
96103
}
97104
// remove not needed .env property
@@ -132,15 +139,15 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator {
132139
path.resolve(dsDir, `${utils.toFileName(s)}.datasource.js`),
133140
),
134141
);
135-
if (this.options.dataSource) {
142+
if (this.options.dataSource || this.options.datasource) {
136143
if (
137144
this.dataSourceChoices
138145
.map(d => d.name)
139-
.includes(this.options.dataSource)
146+
.includes(this.options.dataSource || this.options.datasource)
140147
) {
141148
Object.assign(this.artifactInfo, {
142149
dataSource: this.dataSourceChoices.find(
143-
d => d.name === this.options.dataSource,
150+
d => d.name === this.options.dataSource || this.options.datasource,
144151
),
145152
});
146153
}

packages/cli/snapshots/integration/cli/cli.integration.snapshots.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,6 +1301,12 @@ exports[`cli saves command metadata to .yo-rc.json 1`] = `
13011301
"name": "dataSource",
13021302
"hide": false
13031303
},
1304+
"datasource": {
1305+
"type": "String",
1306+
"description": "The name of the datasource to discover",
1307+
"name": "datasource",
1308+
"hide": false
1309+
},
13041310
"views": {
13051311
"type": "Boolean",
13061312
"description": "Boolean to discover views",

packages/cli/snapshots/integration/generators/discover.integration.snapshots.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,56 @@
77

88
'use strict';
99

10+
exports[`lb4 discover integration generates all models without prompts using --all --datasource 1`] = `
11+
import {Entity, model, property} from '@loopback/repository';
12+
13+
@model()
14+
export class Schema extends Entity {
15+
// Define well-known properties here
16+
17+
// Indexer property to allow additional data
18+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
19+
[prop: string]: any;
20+
21+
constructor(data?: Partial<Schema>) {
22+
super(data);
23+
}
24+
}
25+
26+
export interface SchemaRelations {
27+
// describe navigational properties here
28+
}
29+
30+
export type SchemaWithRelations = Schema & SchemaRelations;
31+
32+
`;
33+
34+
35+
exports[`lb4 discover integration generates all models without prompts using --all --datasource 2`] = `
36+
import {Entity, model, property} from '@loopback/repository';
37+
38+
@model()
39+
export class View extends Entity {
40+
// Define well-known properties here
41+
42+
// Indexer property to allow additional data
43+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
44+
[prop: string]: any;
45+
46+
constructor(data?: Partial<View>) {
47+
super(data);
48+
}
49+
}
50+
51+
export interface ViewRelations {
52+
// describe navigational properties here
53+
}
54+
55+
export type ViewWithRelations = View & ViewRelations;
56+
57+
`;
58+
59+
1060
exports[`lb4 discover integration model discovery does not mark id property as required based on optionalId option 1`] = `
1161
import {Entity, model, property} from '@loopback/repository';
1262

packages/cli/test/integration/generators/discover.integration.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ const specificModelsOptions = {
6969
views: false,
7070
disableCamelCase: true,
7171
};
72+
73+
const baseOptionsWithSmallS = {
74+
all: true,
75+
datasource: 'mem',
76+
};
77+
7278
// Expected File Name
7379
const defaultExpectedTestModel = path.join(
7480
sandbox.path,
@@ -231,4 +237,20 @@ describe('lb4 discover integration', () => {
231237
basicModelFileChecks(defaultExpectedTestModel, defaultExpectedIndexFile);
232238
assert.file(defaultExpectedTestModel);
233239
});
240+
241+
it('generates all models without prompts using --all --datasource', /** @this {Mocha.Context} */ async function () {
242+
this.timeout(10000);
243+
await testUtils
244+
.executeGenerator(generator)
245+
.inDir(sandbox.path, () =>
246+
testUtils.givenLBProject(sandbox.path, {
247+
additionalFiles: SANDBOX_FILES,
248+
}),
249+
)
250+
.withOptions(baseOptionsWithSmallS);
251+
252+
basicModelFileChecks(defaultExpectedTestModel, defaultExpectedIndexFile);
253+
expectFileToMatchSnapshot(defaultExpectedSchemaModel);
254+
expectFileToMatchSnapshot(defaultExpectedViewModel);
255+
});
234256
});

0 commit comments

Comments
 (0)