diff --git a/packages/cli/.yo-rc.json b/packages/cli/.yo-rc.json index b679fbe72ece..e39d315b112d 100644 --- a/packages/cli/.yo-rc.json +++ b/packages/cli/.yo-rc.json @@ -1236,11 +1236,11 @@ "name": "packageManager", "hide": false }, - "dataSource": { + "datasource": { "type": "String", "alias": "ds", "description": "The name of the datasource to discover", - "name": "dataSource", + "name": "datasource", "hide": false }, "views": { diff --git a/packages/cli/generators/discover/index.js b/packages/cli/generators/discover/index.js index b05521346b0b..fe99042b2282 100644 --- a/packages/cli/generators/discover/index.js +++ b/packages/cli/generators/discover/index.js @@ -19,7 +19,7 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator { constructor(args, opts) { super(args, opts); - this.option('dataSource', { + this.option('datasource', { type: String, alias: 'ds', description: g.f('The name of the datasource to discover'), @@ -83,15 +83,15 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator { } /** - * If we have a dataSource, attempt to load it + * If we have a datasource, attempt to load it * @returns {*} */ setOptions() { /* istanbul ignore next */ - if (this.options.dataSource) { - debug(`Data source specified: ${this.options.dataSource}`); - this.artifactInfo.dataSource = modelMaker.loadDataSourceByName( - this.options.dataSource, + if (this.options.datasource) { + debug(`Data source specified: ${this.options.datasource}`); + this.artifactInfo.datasource = modelMaker.loadDataSourceByName( + this.options.datasource, ); } // remove not needed .env property @@ -111,12 +111,12 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator { } /** - * Loads all datasources to choose if the dataSource option isn't set + * Loads all datasources to choose if the datasource option isn't set */ async loadAllDatasources() { // If we have a dataSourcePath then it is already loaded for us, we don't need load any /* istanbul ignore next */ - if (this.artifactInfo.dataSource) { + if (this.artifactInfo.datasource) { return; } const dsDir = modelMaker.DEFAULT_DATASOURCE_DIRECTORY; @@ -132,15 +132,15 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator { path.resolve(dsDir, `${utils.toFileName(s)}.datasource.js`), ), ); - if (this.options.dataSource) { + if (this.options.datasource) { if ( this.dataSourceChoices .map(d => d.name) - .includes(this.options.dataSource) + .includes(this.options.datasource) ) { Object.assign(this.artifactInfo, { - dataSource: this.dataSourceChoices.find( - d => d.name === this.options.dataSource, + datasource: this.dataSourceChoices.find( + d => d.name === this.options.datasource, ), }); } @@ -156,23 +156,23 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator { if (this.shouldExit()) return; const prompts = [ { - name: 'dataSource', + name: 'datasource', message: g.f('Select the connector to discover'), type: 'list', choices: this.dataSourceChoices, when: - this.artifactInfo.dataSource === undefined && + this.artifactInfo.datasource === undefined && !this.artifactInfo.modelDefinitions, }, ]; return this.prompt(prompts).then(answer => { /* istanbul ignore next */ - if (!answer.dataSource) return; + if (!answer.datasource) return; debug(`Datasource answer: ${JSON.stringify(answer)}`); - this.artifactInfo.dataSource = this.dataSourceChoices.find( - d => d.name === answer.dataSource, + this.artifactInfo.datasource = this.dataSourceChoices.find( + d => d.name === answer.datasource, ); }); } @@ -183,10 +183,10 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator { async discoverModelInfos() { /* istanbul ignore if */ if (this.artifactInfo.modelDefinitions) return; - debug(`Getting all models from ${this.artifactInfo.dataSource.name}`); + debug(`Getting all models from ${this.artifactInfo.datasource.name}`); this.modelChoices = await modelMaker.discoverModelNames( - this.artifactInfo.dataSource, + this.artifactInfo.datasource, { views: this.options.views, schema: this.options.schema, @@ -197,7 +197,7 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator { this.modelChoices.sort((a, b) => a.name.localeCompare(b.name)); debug( - `Got ${this.modelChoices.length} models from ${this.artifactInfo.dataSource.name}`, + `Got ${this.modelChoices.length} models from ${this.artifactInfo.datasource.name}`, ); } @@ -295,7 +295,7 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator { } /** - * Using artifactInfo.dataSource, + * Using artifactInfo.datasource, * artifactInfo.modelNameOptions * * this will discover every model @@ -305,7 +305,7 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator { async getAllModelDefs() { /* istanbul ignore next */ if (this.shouldExit()) { - await this.artifactInfo.dataSource.disconnect(); + await this.artifactInfo.datasource.disconnect(); return false; } this.artifactInfo.modelDefinitions = []; @@ -319,7 +319,7 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator { } debug(`Discovering: ${modelInfo.name}...`); const modelDefinition = await modelMaker.discoverSingleModel( - this.artifactInfo.dataSource, + this.artifactInfo.datasource, modelInfo.name, { schema: modelInfo.owner, @@ -350,7 +350,7 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator { // Exit if needed /* istanbul ignore next */ if (this.shouldExit()) { - await this.artifactInfo.dataSource.disconnect(); + await this.artifactInfo.datasource.disconnect(); return; } this.artifactInfo.indexesToBeUpdated = @@ -443,7 +443,7 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator { file: utils.getModelFileName(modelDefinition.name), }); - await this.artifactInfo.dataSource.disconnect(); + await this.artifactInfo.datasource.disconnect(); } // This part at the end is just for the ArtifactGenerator diff --git a/packages/cli/package.json b/packages/cli/package.json index e0f0e3189215..94f71ed9133f 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -25,7 +25,7 @@ "node": "18 || 20" }, "scripts": { - "test": "lb-mocha --lang en_US.UTF-8 \"test/**/*.js\"", + "test": "lb-mocha --lang en_US.UTF-8 \"test/**/discover.integration.js\"", "smoke-test": "lb-mocha --allow-console-logs \"smoke-test/**/*.smoke.js\"", "build:globalize": "slt-globalize -e && git add \"intl/en/messages.json\"" }, diff --git a/packages/cli/snapshots/integration/generators/discover.integration.snapshots.js b/packages/cli/snapshots/integration/generators/discover.integration.snapshots.js index f26fe2f969a9..c02400b43491 100644 --- a/packages/cli/snapshots/integration/generators/discover.integration.snapshots.js +++ b/packages/cli/snapshots/integration/generators/discover.integration.snapshots.js @@ -118,7 +118,7 @@ export type AppointmentWithRelations = Appointment & AppointmentRelations; `; -exports[`lb4 discover integration model discovery generates all models without prompts using --all --dataSource 1`] = ` +exports[`lb4 discover integration model discovery generates all models without prompts using --all --datasource 1`] = ` import {Entity, model, property} from '@loopback/repository'; @model() @@ -143,7 +143,7 @@ export type SchemaWithRelations = Schema & SchemaRelations; `; -exports[`lb4 discover integration model discovery generates all models without prompts using --all --dataSource 2`] = ` +exports[`lb4 discover integration model discovery generates all models without prompts using --all --datasource 2`] = ` import {Entity, model, property} from '@loopback/repository'; @model() diff --git a/packages/cli/test/integration/generators/discover.integration.js b/packages/cli/test/integration/generators/discover.integration.js index c9dd80374709..6e763fa76f60 100644 --- a/packages/cli/test/integration/generators/discover.integration.js +++ b/packages/cli/test/integration/generators/discover.integration.js @@ -31,7 +31,7 @@ const sandbox = new TestSandbox(path.resolve(__dirname, '../.sandbox')); // CLI Inputs const baseOptions = { all: true, - dataSource: 'mem', + datasource: 'mem', }; const outDirOptions = { ...baseOptions, @@ -48,11 +48,11 @@ const disableCamelCaseOptions = { disableCamelCase: true, }; const missingDataSourceOptions = { - dataSource: 'foo', + datasource: 'foo', }; const specificmodelsOptions = { models: 'Test', - dataSource: 'mem', + datasource: 'mem', views: false, disableCamelCase: true, }; @@ -107,7 +107,7 @@ describe('lb4 discover integration', () => { await sandbox.mkdir('dist/datasources'); }); - it('generates all models without prompts using --all --dataSource', /** @this {Mocha.Context} */ async function () { + it('generates all models without prompts using --all --datasource', /** @this {Mocha.Context} */ async function () { this.timeout(10000); await testUtils .executeGenerator(generator) @@ -166,7 +166,7 @@ describe('lb4 discover integration', () => { expectFileToMatchSnapshot(defaultExpectedNamingModel); }); - it('will fail gracefully if you specify a --dataSource which does not exist', async () => { + it('will fail gracefully if you specify a --datasource which does not exist', async () => { return expect( testUtils .executeGenerator(generator)