diff --git a/packages/cli/generators/datasource/index.js b/packages/cli/generators/datasource/index.js index 7cfff7f4f042..ffa7c40f3343 100644 --- a/packages/cli/generators/datasource/index.js +++ b/packages/cli/generators/datasource/index.js @@ -168,7 +168,7 @@ module.exports = class DataSourceGenerator extends ArtifactGenerator { // Set defaults and merge with `setting` to override properties const question = Object.assign( {}, - {name: key, message: key, suffix: ':'}, + {name: key, message: key, suffix: ':', type: 'input'}, setting, ); @@ -178,18 +178,25 @@ module.exports = class DataSourceGenerator extends ArtifactGenerator { */ switch ((setting.type || '').toLowerCase()) { case 'string': + question.default = ''; + break; case 'number': - question.type = 'input'; + question.default = 0; break; case 'object': + question.default = '{}'; + question.validate = utils.validateStringObject(setting.type); + break; case 'array': - question.type = 'input'; + question.default = '[]'; question.validate = utils.validateStringObject(setting.type); break; case 'boolean': question.type = 'confirm'; + question.default = false; break; case 'password': + question.default = ''; break; default: console.warn( diff --git a/packages/cli/generators/interceptor/index.js b/packages/cli/generators/interceptor/index.js index cec6d3af3e29..50c59421f11b 100644 --- a/packages/cli/generators/interceptor/index.js +++ b/packages/cli/generators/interceptor/index.js @@ -137,6 +137,7 @@ module.exports = class InterceptorGenerator extends ArtifactGenerator { { type: 'input', name: 'group', + default: '', // capitalization message: g.f("Group name for the global interceptor: ('')"), }, diff --git a/packages/cli/generators/model/index.js b/packages/cli/generators/model/index.js index d49d3dac2efd..f265f823f8f9 100644 --- a/packages/cli/generators/model/index.js +++ b/packages/cli/generators/model/index.js @@ -368,6 +368,7 @@ module.exports = class ModelGenerator extends ArtifactGenerator { return true; } }, + default: '', }, ]; diff --git a/packages/cli/generators/openapi/index.js b/packages/cli/generators/openapi/index.js index 322b8b871e77..f73dc9bb9b76 100644 --- a/packages/cli/generators/openapi/index.js +++ b/packages/cli/generators/openapi/index.js @@ -274,6 +274,7 @@ module.exports = class OpenApiGenerator extends BaseGenerator { // This prevents users from accidentally pressing ENTER instead of SPACE // to select an item from the list validate: result => !!result.length, + default: choices.map(c => c.value), }, ]; const selections = diff --git a/packages/cli/generators/repository/index.js b/packages/cli/generators/repository/index.js index 3b2a5e1016be..4d86f1849041 100644 --- a/packages/cli/generators/repository/index.js +++ b/packages/cli/generators/repository/index.js @@ -366,6 +366,7 @@ module.exports = class RepositoryGenerator extends ArtifactGenerator { name: 'modelNameList', message: PROMPT_MESSAGE_MODEL, choices: modelList, + default: [], when: this.artifactInfo.modelNameList === undefined, // Require at least one model to be selected // This prevents users from accidentally pressing ENTER instead of SPACE diff --git a/packages/cli/generators/rest-crud/index.js b/packages/cli/generators/rest-crud/index.js index dd9ff01bef51..9a397858d182 100644 --- a/packages/cli/generators/rest-crud/index.js +++ b/packages/cli/generators/rest-crud/index.js @@ -258,6 +258,7 @@ module.exports = class RestCrudGenerator extends ArtifactGenerator { name: 'modelNameList', message: PROMPT_MESSAGE_MODEL, choices: modelList.map(m => ({name: m, value: m, checked: true})), + default: [], when: this.artifactInfo.modelNameList === undefined, // Require at least one model to be selected // This prevents users from accidentally pressing ENTER instead of SPACE diff --git a/packages/cli/lib/project-generator.js b/packages/cli/lib/project-generator.js index 1e56ac59dff4..58fffe144196 100644 --- a/packages/cli/lib/project-generator.js +++ b/packages/cli/lib/project-generator.js @@ -202,6 +202,7 @@ module.exports = class ProjectGenerator extends BaseGenerator { choices: choices, // Skip if all features are enabled by cli options when: choices.length > 0, + default: choices.map(c => c.short), }, ]; return this.prompt(prompts).then(props => { diff --git a/packages/cli/package-lock.json b/packages/cli/package-lock.json index 6eae812b53a7..faf93e01f456 100644 --- a/packages/cli/package-lock.json +++ b/packages/cli/package-lock.json @@ -9195,20 +9195,16 @@ } }, "yeoman-test": { - "version": "2.7.0", - "resolved": "https://registry.npmjs.org/yeoman-test/-/yeoman-test-2.7.0.tgz", - "integrity": "sha512-NNH3XYaeiYO9gWdQ2B02kZuLZnbYZhGqcqrUjyS5VW/r1xOuJ9t6FIzw7uE35/yCx+U9R0kzeTbxkQ6Iwsv3DA==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/yeoman-test/-/yeoman-test-3.0.0.tgz", + "integrity": "sha512-L8+m6u3enXxL2czVAN/+M2oCuVgDuNqAlegY4+RcO4xD8Fd9/9hdMfoMd83YtVXNUBJvvMdYBRSYj4kd7nsp3A==", "dev": true, "requires": { - "inquirer": "^7.1.0", - "lodash": "^4.17.15", - "mem-fs": "^1.2.0", - "mem-fs-editor": "^7.0.1", - "mkdirp": "^1.0.3", - "rimraf": "^3.0.2", - "sinon": "^9.0.1", - "yeoman-environment": "^2.10.0", - "yeoman-generator": "^4.10.0" + "inquirer": "^7.3.3", + "lodash": "^4.17.19", + "sinon": "^9.0.2", + "yeoman-environment": "^2.10.3", + "yeoman-generator": "^4.11.0" }, "dependencies": { "ansi-escapes": { diff --git a/packages/cli/package.json b/packages/cli/package.json index 8b750523c29e..2c4e993fefcd 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -45,7 +45,7 @@ "sinon": "^9.0.2", "strong-globalize-cli": "7.0.3", "yeoman-assert": "^3.1.1", - "yeoman-test": "~2.7.0" + "yeoman-test": "~3.0.0" }, "dependencies": { "@lerna/project": "^3.21.0", diff --git a/packages/cli/snapshots/integration/cli/cli.integration.snapshots.js b/packages/cli/snapshots/integration/cli/cli.integration.snapshots.js index 7e65f3b76ae9..c61d042f0089 100644 --- a/packages/cli/snapshots/integration/cli/cli.integration.snapshots.js +++ b/packages/cli/snapshots/integration/cli/cli.integration.snapshots.js @@ -30,6 +30,7 @@ Available commands: lb4 uninstall-completion `; + exports[`cli prints commands with --help 1`] = ` Available commands: lb4 app @@ -53,6 +54,7 @@ Available commands: lb4 uninstall-completion `; + exports[`cli saves command metadata to .yo-rc.json 1`] = ` { "commands": { diff --git a/packages/cli/snapshots/integration/generators/datasource.integration.snapshots.js b/packages/cli/snapshots/integration/generators/datasource.integration.snapshots.js index d61e5f47a64f..ff853e7590e7 100644 --- a/packages/cli/snapshots/integration/generators/datasource.integration.snapshots.js +++ b/packages/cli/snapshots/integration/generators/datasource.integration.snapshots.js @@ -14,8 +14,8 @@ import {juggler} from '@loopback/repository'; const config = { name: 'ds', connector: 'memory', - localStorage: undefined, - file: undefined + localStorage: '', + file: '' }; // Observe application's life cycle to disconnect the datasource when @@ -46,8 +46,8 @@ import {juggler} from '@loopback/repository'; const config = { name: 'ds', connector: 'memory', - localStorage: undefined, - file: undefined + localStorage: '', + file: '' }; // Observe application's life cycle to disconnect the datasource when @@ -78,13 +78,13 @@ import {juggler} from '@loopback/repository'; const config = { name: 'ds', connector: 'db2', - dsn: undefined, - host: undefined, + dsn: '', + host: '', port: 100, - user: undefined, - password: undefined, - database: undefined, - schema: undefined + user: '', + password: '', + database: '', + schema: '' }; // Observe application's life cycle to disconnect the datasource when @@ -115,7 +115,7 @@ import {juggler} from '@loopback/repository'; const config = { name: 'ds', connector: 'rest', - baseURL: undefined, + baseURL: '', options: { test: 'value' }, @@ -155,10 +155,10 @@ const config = { name: 'ds', connector: 'cloudant', url: 'http://user:pass@host.com', - database: undefined, + database: '', username: 'user', password: 'pass', - modelIndex: undefined + modelIndex: '' }; // Observe application's life cycle to disconnect the datasource when diff --git a/packages/cli/snapshots/integration/generators/relation.has-many-through.integration.snapshots.js b/packages/cli/snapshots/integration/generators/relation.has-many-through.integration.snapshots.js index 6805191f699b..9fc5aa0d742c 100644 --- a/packages/cli/snapshots/integration/generators/relation.has-many-through.integration.snapshots.js +++ b/packages/cli/snapshots/integration/generators/relation.has-many-through.integration.snapshots.js @@ -7,9 +7,7 @@ 'use strict'; -exports[ - `lb4 relation HasManyThrough checks if the controller file created answers {"relationType":"hasManyThrough","sourceModel":"Doctor","destinationModel":"Patient","throughModel":"Appointment","relationName":"myPatients"} controller file has been created with hasManyThrough relation 1` -] = ` +exports[`lb4 relation HasManyThrough checks if the controller file created answers {"relationType":"hasManyThrough","sourceModel":"Doctor","destinationModel":"Patient","throughModel":"Appointment","relationName":"myPatients"} controller file has been created with hasManyThrough relation 1`] = ` import { Count, CountSchema, @@ -123,9 +121,8 @@ export class DoctorPatientController { `; -exports[ - `lb4 relation HasManyThrough checks if the controller file created answers {"relationType":"hasManyThrough","sourceModel":"Doctor","destinationModel":"Patient","throughModel":"Appointment"} controller file has been created with hasManyThrough relation 1` -] = ` + +exports[`lb4 relation HasManyThrough checks if the controller file created answers {"relationType":"hasManyThrough","sourceModel":"Doctor","destinationModel":"Patient","throughModel":"Appointment"} controller file has been created with hasManyThrough relation 1`] = ` import { Count, CountSchema, @@ -239,9 +236,8 @@ export class DoctorPatientController { `; -exports[ - `lb4 relation HasManyThrough generates model relation with custom keyFrom and/or keyTo answers {"relationType":"hasManyThrough","sourceModel":"Doctor","destinationModel":"Patient","throughModel":"Appointment","sourceKeyOnThrough":"customKeyFrom","targetKeyOnThrough":"customKeyTo"} add custom keyTo and/or keyFrom to the through model 1` -] = ` + +exports[`lb4 relation HasManyThrough generates model relation with custom keyFrom and/or keyTo answers {"relationType":"hasManyThrough","sourceModel":"Doctor","destinationModel":"Patient","throughModel":"Appointment","sourceKeyOnThrough":"customKeyFrom","targetKeyOnThrough":"customKeyTo"} add custom keyTo and/or keyFrom to the through model 1`] = ` import {Entity, model, property, hasMany} from '@loopback/repository'; import {Patient} from './patient.model'; import {Appointment} from './appointment.model'; @@ -270,9 +266,8 @@ export class Doctor extends Entity { `; -exports[ - `lb4 relation HasManyThrough generates model relation with custom keyFrom and/or keyTo answers {"relationType":"hasManyThrough","sourceModel":"Doctor","destinationModel":"Patient","throughModel":"Appointment","sourceKeyOnThrough":"customKeyFrom","targetKeyOnThrough":"customKeyTo"} add custom keyTo and/or keyFrom to the through model 2` -] = ` + +exports[`lb4 relation HasManyThrough generates model relation with custom keyFrom and/or keyTo answers {"relationType":"hasManyThrough","sourceModel":"Doctor","destinationModel":"Patient","throughModel":"Appointment","sourceKeyOnThrough":"customKeyFrom","targetKeyOnThrough":"customKeyTo"} add custom keyTo and/or keyFrom to the through model 2`] = ` import {Entity, model, property} from '@loopback/repository'; @model() @@ -306,9 +301,8 @@ export class Appointment extends Entity { `; -exports[ - `lb4 relation HasManyThrough generates model relation with custom keyFrom and/or keyTo answers {"relationType":"hasManyThrough","sourceModel":"Doctor","destinationModel":"Patient","throughModel":"Appointment","sourceKeyOnThrough":"customKeyFrom"} add custom keyTo and/or keyFrom to the through model 1` -] = ` + +exports[`lb4 relation HasManyThrough generates model relation with custom keyFrom and/or keyTo answers {"relationType":"hasManyThrough","sourceModel":"Doctor","destinationModel":"Patient","throughModel":"Appointment","sourceKeyOnThrough":"customKeyFrom"} add custom keyTo and/or keyFrom to the through model 1`] = ` import {Entity, model, property, hasMany} from '@loopback/repository'; import {Patient} from './patient.model'; import {Appointment} from './appointment.model'; @@ -337,9 +331,8 @@ export class Doctor extends Entity { `; -exports[ - `lb4 relation HasManyThrough generates model relation with custom keyFrom and/or keyTo answers {"relationType":"hasManyThrough","sourceModel":"Doctor","destinationModel":"Patient","throughModel":"Appointment","sourceKeyOnThrough":"customKeyFrom"} add custom keyTo and/or keyFrom to the through model 2` -] = ` + +exports[`lb4 relation HasManyThrough generates model relation with custom keyFrom and/or keyTo answers {"relationType":"hasManyThrough","sourceModel":"Doctor","destinationModel":"Patient","throughModel":"Appointment","sourceKeyOnThrough":"customKeyFrom"} add custom keyTo and/or keyFrom to the through model 2`] = ` import {Entity, model, property} from '@loopback/repository'; @model() @@ -373,9 +366,8 @@ export class Appointment extends Entity { `; -exports[ - `lb4 relation HasManyThrough generates model relation with custom keyFrom and/or keyTo answers {"relationType":"hasManyThrough","sourceModel":"Doctor","destinationModel":"Patient","throughModel":"Appointment","targetKeyOnThrough":"customKeyTo"} add custom keyTo and/or keyFrom to the through model 1` -] = ` + +exports[`lb4 relation HasManyThrough generates model relation with custom keyFrom and/or keyTo answers {"relationType":"hasManyThrough","sourceModel":"Doctor","destinationModel":"Patient","throughModel":"Appointment","targetKeyOnThrough":"customKeyTo"} add custom keyTo and/or keyFrom to the through model 1`] = ` import {Entity, model, property, hasMany} from '@loopback/repository'; import {Patient} from './patient.model'; import {Appointment} from './appointment.model'; @@ -404,9 +396,8 @@ export class Doctor extends Entity { `; -exports[ - `lb4 relation HasManyThrough generates model relation with custom keyFrom and/or keyTo answers {"relationType":"hasManyThrough","sourceModel":"Doctor","destinationModel":"Patient","throughModel":"Appointment","targetKeyOnThrough":"customKeyTo"} add custom keyTo and/or keyFrom to the through model 2` -] = ` + +exports[`lb4 relation HasManyThrough generates model relation with custom keyFrom and/or keyTo answers {"relationType":"hasManyThrough","sourceModel":"Doctor","destinationModel":"Patient","throughModel":"Appointment","targetKeyOnThrough":"customKeyTo"} add custom keyTo and/or keyFrom to the through model 2`] = ` import {Entity, model, property} from '@loopback/repository'; @model() @@ -440,9 +431,8 @@ export class Appointment extends Entity { `; -exports[ - `lb4 relation HasManyThrough generates model relation with custom relation name answers {"relationType":"hasManyThrough","sourceModel":"Doctor","destinationModel":"Patient","throughModel":"Appointment","relationName":"myPatients"} relation name should be myPatients 1` -] = ` + +exports[`lb4 relation HasManyThrough generates model relation with custom relation name answers {"relationType":"hasManyThrough","sourceModel":"Doctor","destinationModel":"Patient","throughModel":"Appointment","relationName":"myPatients"} relation name should be myPatients 1`] = ` import {Entity, model, property, hasMany} from '@loopback/repository'; import {Patient} from './patient.model'; import {Appointment} from './appointment.model'; @@ -471,9 +461,8 @@ export class Doctor extends Entity { `; -exports[ - `lb4 relation HasManyThrough generates model relation with custom relation name answers {"relationType":"hasManyThrough","sourceModel":"Doctor","destinationModel":"Patient","throughModel":"Appointment","relationName":"myPatients"} relation name should be myPatients 2` -] = ` + +exports[`lb4 relation HasManyThrough generates model relation with custom relation name answers {"relationType":"hasManyThrough","sourceModel":"Doctor","destinationModel":"Patient","throughModel":"Appointment","relationName":"myPatients"} relation name should be myPatients 2`] = ` import {DefaultCrudRepository, repository, HasManyThroughRepositoryFactory} from '@loopback/repository'; import {Doctor, Patient, Appointment} from '../models'; import {DbDataSource} from '../datasources'; @@ -499,9 +488,8 @@ export class DoctorRepository extends DefaultCrudRepository< `; -exports[ - `lb4 relation HasManyThrough generates model relation with default values answers {"relationType":"hasManyThrough","sourceModel":"Doctor","destinationModel":"Patient","throughModel":"Appointment"} has correct default foreign keys 1` -] = ` + +exports[`lb4 relation HasManyThrough generates model relation with default values answers {"relationType":"hasManyThrough","sourceModel":"Doctor","destinationModel":"Patient","throughModel":"Appointment"} has correct default foreign keys 1`] = ` import {Entity, model, property} from '@loopback/repository'; @model() @@ -535,9 +523,8 @@ export class Appointment extends Entity { `; -exports[ - `lb4 relation HasManyThrough generates model relation with default values answers {"relationType":"hasManyThrough","sourceModel":"Doctor","destinationModel":"Patient","throughModel":"Appointment"} has correct imports and relation name patients 1` -] = ` + +exports[`lb4 relation HasManyThrough generates model relation with default values answers {"relationType":"hasManyThrough","sourceModel":"Doctor","destinationModel":"Patient","throughModel":"Appointment"} has correct imports and relation name patients 1`] = ` import {Entity, model, property, hasMany} from '@loopback/repository'; import {Patient} from './patient.model'; import {Appointment} from './appointment.model'; @@ -566,9 +553,8 @@ export class Doctor extends Entity { `; -exports[ - `lb4 relation HasManyThrough generates model relation with default values answers {"relationType":"hasManyThrough","sourceModel":"Doctor","destinationModel":"Patient","throughModel":"Appointment"} has correct imports and relation name patients 2` -] = ` + +exports[`lb4 relation HasManyThrough generates model relation with default values answers {"relationType":"hasManyThrough","sourceModel":"Doctor","destinationModel":"Patient","throughModel":"Appointment"} has correct imports and relation name patients 2`] = ` import {DefaultCrudRepository, repository, HasManyThroughRepositoryFactory} from '@loopback/repository'; import {Doctor, Patient, Appointment} from '../models'; import {DbDataSource} from '../datasources';