From ac1d23cfbef7c38049b584f47bb69d5b99432490 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Fri, 6 Aug 2021 15:47:38 -0300 Subject: [PATCH] Improve api. --- generators/gradle/constants.cjs | 9 +++-- generators/gradle/generator.spec.cjs | 2 +- generators/gradle/index.cjs | 12 +++---- generators/init/config.cjs | 11 ++++-- generators/init/constants.cjs | 5 ++- generators/init/generator.spec.cjs | 4 +-- generators/init/index.cjs | 42 +++++++++++----------- generators/init/mixin.cjs | 20 +++++++---- generators/java/generator.spec.cjs | 12 +++++-- generators/java/index.cjs | 41 ++++++++++----------- generators/java/mixin.cjs | 16 +++++---- generators/maven/constants.cjs | 10 ++++-- generators/maven/generator.spec.cjs | 2 +- generators/maven/index.cjs | 12 +++---- generators/project-name/constants.cjs | 12 ++++--- generators/project-name/generator.spec.cjs | 4 +-- generators/project-name/index.cjs | 28 +++++++-------- generators/project-name/mixin.cjs | 5 ++- generators/project-name/options.cjs | 12 +++---- generators/spring-boot/generator.spec.cjs | 5 +-- generators/spring-boot/index.cjs | 22 ++++++------ generators/spring-boot/mixin.cjs | 24 +++++++------ test/support/index.cjs | 5 ++- 23 files changed, 177 insertions(+), 138 deletions(-) diff --git a/generators/gradle/constants.cjs b/generators/gradle/constants.cjs index 71b576709b2..35c8dd9c070 100644 --- a/generators/gradle/constants.cjs +++ b/generators/gradle/constants.cjs @@ -17,10 +17,13 @@ * limitations under the License. */ const GRADLE_VERSION = '7.0.2'; +const GRADLE = 'gradle'; +const GRADLE_DESCRIPTION = 'Gradle'; +const BUILD_DESTINATION_VALUE = 'build'; module.exports = { - GRADLE: 'gradle', - GRADLE_DESCRIPTION: 'Gradle', GRADLE_VERSION, - BUILD_DESTINATION_VALUE: 'build', + GRADLE, + GRADLE_DESCRIPTION, + BUILD_DESTINATION_VALUE, }; diff --git a/generators/gradle/generator.spec.cjs b/generators/gradle/generator.spec.cjs index 523ffbfd678..167035dd917 100644 --- a/generators/gradle/generator.spec.cjs +++ b/generators/gradle/generator.spec.cjs @@ -36,7 +36,7 @@ describe(`JHipster ${generator} generator`, () => { customPrompts: {}, generatorPath, }); - describe('blueprint support', () => testBlueprintSupport('gradle')); + describe('blueprint support', () => testBlueprintSupport(generator)); describe('with valid configuration', () => { let runResult; before(async () => { diff --git a/generators/gradle/index.cjs b/generators/gradle/index.cjs index 17e6b172b4c..faf2bd1cf63 100644 --- a/generators/gradle/index.cjs +++ b/generators/gradle/index.cjs @@ -61,7 +61,7 @@ module.exports = class extends MixedChain { } } - _initializing() { + get initializing() { return { validateFromCli() { this.checkInvocationFromCLI(); @@ -81,10 +81,10 @@ module.exports = class extends MixedChain { get [INITIALIZING_PRIORITY]() { if (this.delegateToBlueprint) return; - return this._initializing(); + return this.initializing; } - _loading() { + get loading() { return { configureChain() { this.configureChain(); @@ -101,7 +101,7 @@ module.exports = class extends MixedChain { get [LOADING_PRIORITY]() { if (this.delegateToBlueprint) return; - return this._loading(); + return this.loading; } get preparing() { @@ -117,7 +117,7 @@ module.exports = class extends MixedChain { return this.preparing; } - _writing() { + get writing() { return { async writeFiles() { if (this.shouldSkipFiles()) return; @@ -128,6 +128,6 @@ module.exports = class extends MixedChain { get [WRITING_PRIORITY]() { if (this.delegateToBlueprint) return; - return this._writing(); + return this.writing; } }; diff --git a/generators/init/config.cjs b/generators/init/config.cjs index 137b3b117e9..8ebb174da6c 100644 --- a/generators/init/config.cjs +++ b/generators/init/config.cjs @@ -16,7 +16,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const { PRETTIER_DEFAULT_INDENT, SKIP_COMMIT_HOOK } = require('./constants.cjs'); +const { + PRETTIER_DEFAULT_INDENT, + PRETTIER_DEFAULT_INDENT_DEFAULT_VALUE, + SKIP_COMMIT_HOOK, + SKIP_COMMIT_HOOK_DEFAULT_VALUE, +} = require('./constants.cjs'); /** Config required at .yo-rc.json */ const requiredConfig = {}; @@ -24,8 +29,8 @@ const requiredConfig = {}; /** Default config for templates */ const defaultConfig = { ...requiredConfig, - [PRETTIER_DEFAULT_INDENT]: 2, - [SKIP_COMMIT_HOOK]: false, + [PRETTIER_DEFAULT_INDENT]: PRETTIER_DEFAULT_INDENT_DEFAULT_VALUE, + [SKIP_COMMIT_HOOK]: SKIP_COMMIT_HOOK_DEFAULT_VALUE, }; module.exports = { requiredConfig, defaultConfig }; diff --git a/generators/init/constants.cjs b/generators/init/constants.cjs index 531d20d9d5f..a613e2d2185 100644 --- a/generators/init/constants.cjs +++ b/generators/init/constants.cjs @@ -17,9 +17,12 @@ * limitations under the License. */ const NODE_VERSION = '14.17.1'; + const PRETTIER_DEFAULT_INDENT = 'prettierDefaultIndent'; const PRETTIER_DEFAULT_INDENT_DEFAULT_VALUE = 2; + const SKIP_COMMIT_HOOK = 'skipCommitHook'; +const SKIP_COMMIT_HOOK_DESCRIPTION = 'Skip adding husky commit hooks'; const SKIP_COMMIT_HOOK_DEFAULT_VALUE = false; module.exports = { @@ -27,6 +30,6 @@ module.exports = { PRETTIER_DEFAULT_INDENT, PRETTIER_DEFAULT_INDENT_DEFAULT_VALUE, SKIP_COMMIT_HOOK, - SKIP_COMMIT_HOOK_DESCRIPTION: 'Skip adding husky commit hooks', + SKIP_COMMIT_HOOK_DESCRIPTION, SKIP_COMMIT_HOOK_DEFAULT_VALUE, }; diff --git a/generators/init/generator.spec.cjs b/generators/init/generator.spec.cjs index f2f2b3138b8..58ec4532672 100644 --- a/generators/init/generator.spec.cjs +++ b/generators/init/generator.spec.cjs @@ -16,8 +16,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const path = require('path'); const expect = require('expect'); +const path = require('path'); const { access } = require('fs/promises'); const { basicTests, testBlueprintSupport } = require('../../test/support/index.cjs'); @@ -42,6 +42,7 @@ describe(`JHipster ${generator} generator`, () => { }, contextBuilder, }); + describe('blueprint support', () => testBlueprintSupport(generator)); describe('with', () => { describe('default config', () => { let runResult; @@ -108,5 +109,4 @@ describe(`JHipster ${generator} generator`, () => { }); }); }); - describe('blueprint support', () => testBlueprintSupport('init')); }); diff --git a/generators/init/index.cjs b/generators/init/index.cjs index 77a7517b41f..a2d168f3c21 100644 --- a/generators/init/index.cjs +++ b/generators/init/index.cjs @@ -23,6 +23,7 @@ const { generateMixedChain } = require('../../lib/support/mixin.cjs'); const { INITIALIZING_PRIORITY, PROMPTING_PRIORITY, + CONFIGURING_PRIORITY, LOADING_PRIORITY, PREPARING_PRIORITY, WRITING_PRIORITY, @@ -32,7 +33,7 @@ const { } = require('../../lib/support/priorities.cjs'); const { GENERATOR_INIT } = require('../generator-list'); -const { SKIP_COMMIT_HOOK } = require('./constants.cjs'); +const { PRETTIER_DEFAULT_INDENT, SKIP_COMMIT_HOOK } = require('./constants.cjs'); const { files, commitHooksFiles } = require('./files.cjs'); const { defaultConfig } = require('./config.cjs'); const { dependencyChain } = require('./mixin.cjs'); @@ -66,7 +67,7 @@ module.exports = class extends MixedChain { } } - _initializing() { + get initializing() { return { validateFromCli() { this.checkInvocationFromCLI(); @@ -86,19 +87,18 @@ module.exports = class extends MixedChain { get [INITIALIZING_PRIORITY]() { if (this.delegateToBlueprint) return; - return this._initializing(); + return this.initializing; } - _prompting() { + get prompting() { return { async showPrompts() { if (this.shouldSkipPrompts()) return; await this.prompt( [ { - name: 'prettierDefaultIndent', - when: () => !this.abort, - type: 'number', + name: PRETTIER_DEFAULT_INDENT, + type: 'input', message: 'What is the default indentation?', default: defaultConfig.prettierDefaultIndent, }, @@ -111,10 +111,10 @@ module.exports = class extends MixedChain { get [PROMPTING_PRIORITY]() { if (this.delegateToBlueprint) return; - return this._prompting(); + return this.prompting; } - _configuring() { + get configuring() { return { configure() { this.configureInit(); @@ -122,12 +122,12 @@ module.exports = class extends MixedChain { }; } - get configuring() { + get [CONFIGURING_PRIORITY]() { if (this.delegateToBlueprint) return; - return this._configuring(); + return this.configuring; } - _loading() { + get loading() { return { configureChain() { this.configureChain(); @@ -146,7 +146,7 @@ module.exports = class extends MixedChain { get [LOADING_PRIORITY]() { if (this.delegateToBlueprint) return; - return this._loading(); + return this.loading; } get preparing() { @@ -162,7 +162,7 @@ module.exports = class extends MixedChain { return this.preparing; } - _writing() { + get writing() { return { async writeFiles() { if (this.shouldSkipFiles()) return; @@ -177,10 +177,10 @@ module.exports = class extends MixedChain { get [WRITING_PRIORITY]() { if (this.delegateToBlueprint) return; - return this._writing(); + return this.writing; } - _postWriting() { + get postWriting() { return { addCommitHookDependencies() { if (this.shouldSkipFiles() || this[SKIP_COMMIT_HOOK]) return; @@ -196,10 +196,10 @@ module.exports = class extends MixedChain { get [POST_WRITING_PRIORITY]() { if (this.delegateToBlueprint) return; - return this._postWriting(); + return this.postWriting; } - _install() { + get install() { return { // Initialize git repository before package manager install for commit hooks async initGitRepo() { @@ -221,10 +221,10 @@ module.exports = class extends MixedChain { get [INSTALL_PRIORITY]() { if (this.delegateToBlueprint) return; - return this._install(); + return this.install; } - _end() { + get end() { return { /** Initial commit to git repository after package manager install for package-lock.json */ async gitCommit() { @@ -266,7 +266,7 @@ module.exports = class extends MixedChain { get [END_PRIORITY]() { if (this.delegateToBlueprint) return; - return this._end(); + return this.end; } /* diff --git a/generators/init/mixin.cjs b/generators/init/mixin.cjs index 54c4a26e58d..cf611246f9a 100644 --- a/generators/init/mixin.cjs +++ b/generators/init/mixin.cjs @@ -20,7 +20,13 @@ const { defaults } = require('lodash'); const { requiredConfig, defaultConfig } = require('./config.cjs'); const { options } = require('./options.cjs'); -const { PRETTIER_DEFAULT_INDENT, SKIP_COMMIT_HOOK, NODE_VERSION } = require('./constants.cjs'); +const { + NODE_VERSION, + PRETTIER_DEFAULT_INDENT, + PRETTIER_DEFAULT_INDENT_DEFAULT_VALUE, + SKIP_COMMIT_HOOK, + SKIP_COMMIT_HOOK_DEFAULT_VALUE, +} = require('./constants.cjs'); const { GENERATOR_PROJECT_NAME } = require('../generator-list'); @@ -31,7 +37,10 @@ module.exports.mixin = parent => /** * Load init options constants. */ - loadInitOptionsConstants(into = this) {} + loadInitOptionsConstants(into = this) { + into.PRETTIER_DEFAULT_INDENT_DEFAULT_VALUE = PRETTIER_DEFAULT_INDENT_DEFAULT_VALUE; + into.SKIP_COMMIT_HOOK_DEFAULT_VALUE = SKIP_COMMIT_HOOK_DEFAULT_VALUE; + } /** * Register and parse init options. @@ -61,17 +70,16 @@ module.exports.mixin = parent => } /** - * Load derived init configs into fromInto. + * Prepare derived init properties into fromInto. * @param {any} fromInto - source/destination context */ - // eslint-disable-next-line no-empty-pattern prepareDerivedInitProperties(fromInto = this) {} /** - * Load derived init configs into 'into'. + * Load init constants into 'into'. * @param {Object} into - destination context */ loadInitConstants(into = this) { - this.NODE_VERSION = NODE_VERSION; + into.NODE_VERSION = NODE_VERSION; } }; diff --git a/generators/java/generator.spec.cjs b/generators/java/generator.spec.cjs index 98b5c2a20b2..f90551e46e5 100644 --- a/generators/java/generator.spec.cjs +++ b/generators/java/generator.spec.cjs @@ -19,13 +19,19 @@ const expect = require('expect'); const path = require('path'); -const { basicTests, testBlueprintSupport } = require('../../test/support/index.cjs'); const { skipPrettierHelpers: helpers } = require('../../test/utils/utils'); -const { requiredConfig, defaultConfig } = require('./config.cjs'); + +const { basicTests, testBlueprintSupport } = require('../../test/support/index.cjs'); +const { defaultConfig, requiredConfig } = require('./config.cjs'); +const { GENERATOR_JAVA } = require('../generator-list'); const generatorPath = path.join(__dirname, 'index.cjs'); +const generator = path.basename(__dirname); -describe('JHipster java generator', () => { +describe(`JHipster ${generator} generator`, () => { + it('generator-list constant matches folder name', () => { + expect(GENERATOR_JAVA).toBe(generator); + }); basicTests({ requiredConfig, defaultConfig, diff --git a/generators/java/index.cjs b/generators/java/index.cjs index 9c1a6c0c3c2..7538a9b4f87 100644 --- a/generators/java/index.cjs +++ b/generators/java/index.cjs @@ -22,6 +22,7 @@ const { generateMixedChain } = require('../../lib/support/mixin.cjs'); const { INITIALIZING_PRIORITY, PROMPTING_PRIORITY, + CONFIGURING_PRIORITY, COMPOSING_PRIORITY, LOADING_PRIORITY, PREPARING_PRIORITY, @@ -29,7 +30,7 @@ const { } = require('../../lib/support/priorities.cjs'); const { GENERATOR_JAVA } = require('../generator-list'); -const { PACKAGE_NAME, BUILD_TOOL, PRETTIER_JAVA_INDENT } = require('./constants.cjs'); +const { PACKAGE_NAME, PRETTIER_JAVA_INDENT, BUILD_TOOL } = require('./constants.cjs'); const { files } = require('./files.cjs'); const { defaultConfig } = require('./config.cjs'); const { dependencyChain } = require('./mixin.cjs'); @@ -63,7 +64,7 @@ module.exports = class extends MixedChain { } } - _initializing() { + get initializing() { return { validateFromCli() { this.checkInvocationFromCLI(); @@ -83,10 +84,10 @@ module.exports = class extends MixedChain { get [INITIALIZING_PRIORITY]() { if (this.delegateToBlueprint) return; - return this._initializing(); + return this.initializing; } - _prompting() { + get prompting() { return { async showPrompts() { if (this.shouldSkipPrompts()) return; @@ -99,6 +100,12 @@ module.exports = class extends MixedChain { message: 'What is your default Java package name?', default: () => this.getDefaultPackageName(), }, + { + name: PRETTIER_JAVA_INDENT, + type: 'input', + message: 'What is the Java indentation?', + default: () => this.PRETTIER_JAVA_INDENT_DEFAULT_VALUE, + }, { name: BUILD_TOOL, type: 'list', @@ -106,12 +113,6 @@ module.exports = class extends MixedChain { message: 'What tool do you want to use to build backend?', default: () => this.BUILD_TOOL_DEFAULT_VALUE, }, - { - name: PRETTIER_JAVA_INDENT, - type: 'input', - message: 'What is the Java indentation?', - default: defaultConfig[PRETTIER_JAVA_INDENT], - }, ], this.config ); @@ -121,10 +122,10 @@ module.exports = class extends MixedChain { get [PROMPTING_PRIORITY]() { if (this.delegateToBlueprint) return; - return this._prompting(); + return this.prompting; } - _configuring() { + get configuring() { return { configure() { this.configureJava(); @@ -132,12 +133,12 @@ module.exports = class extends MixedChain { }; } - get configuring() { + get [CONFIGURING_PRIORITY]() { if (this.delegateToBlueprint) return; - return this._configuring(); + return this.configuring; } - _composing() { + get composing() { return { async compose() { if (!this.shouldComposeModular()) return; @@ -148,10 +149,10 @@ module.exports = class extends MixedChain { get [COMPOSING_PRIORITY]() { if (this.delegateToBlueprint) return; - return this._composing(); + return this.composing; } - _loading() { + get loading() { return { configureChain() { this.configureChain(); @@ -167,7 +168,7 @@ module.exports = class extends MixedChain { get [LOADING_PRIORITY]() { if (this.delegateToBlueprint) return; - return this._loading(); + return this.loading; } get preparing() { @@ -183,7 +184,7 @@ module.exports = class extends MixedChain { return this.preparing; } - _writing() { + get writing() { return { async writeFiles() { if (this.shouldSkipFiles()) return; @@ -194,7 +195,7 @@ module.exports = class extends MixedChain { get [WRITING_PRIORITY]() { if (this.delegateToBlueprint) return; - return this._writing(); + return this.writing; } /* diff --git a/generators/java/mixin.cjs b/generators/java/mixin.cjs index ab23c3b9f3c..1b9856658ca 100644 --- a/generators/java/mixin.cjs +++ b/generators/java/mixin.cjs @@ -25,14 +25,16 @@ const { JAVA_VERSION, JAVA_APP_VERSION, JAVA_COMPATIBLE_VERSIONS, + PACKAGE_NAME, + PACKAGE_NAME_DEFAULT_VALUE, + PRETTIER_JAVA_INDENT, + PRETTIER_JAVA_INDENT_DEFAULT_VALUE, BUILD_TOOL, BUILD_TOOL_DEFAULT_VALUE, BUILD_TOOL_MAVEN, BUILD_TOOL_GRADLE, BUILD_TOOL_PROMPT_CHOICES, BUILD_DESTINATION, - PACKAGE_NAME, - PRETTIER_JAVA_INDENT, } = require('./constants.cjs'); const { GENERATOR_INIT } = require('../generator-list'); @@ -45,6 +47,8 @@ module.exports.mixin = parent => * Load java options constants. */ loadJavaOptionsConstants(into = this) { + into.PACKAGE_NAME_DEFAULT_VALUE = PACKAGE_NAME_DEFAULT_VALUE; + into.PRETTIER_JAVA_INDENT_DEFAULT_VALUE = PRETTIER_JAVA_INDENT_DEFAULT_VALUE; into.BUILD_TOOL_DEFAULT_VALUE = BUILD_TOOL_DEFAULT_VALUE; into.BUILD_TOOL_PROMPT_CHOICES = BUILD_TOOL_PROMPT_CHOICES; } @@ -73,13 +77,13 @@ module.exports.mixin = parent => loadJavaConfig(config = this.jhipsterConfig, into = this) { config = defaults({}, config, defaultConfig); into[PACKAGE_NAME] = config[PACKAGE_NAME]; - into[BUILD_TOOL] = config[BUILD_TOOL]; into[PRETTIER_JAVA_INDENT] = config[PRETTIER_JAVA_INDENT]; + into[BUILD_TOOL] = config[BUILD_TOOL]; into[BUILD_DESTINATION] = config[BUILD_DESTINATION]; } /** - * Load derived java configs into fromInto. + * Prepare derived java properties into fromInto. * @param {any} fromInto - source/destination context */ prepareDerivedJavaProperties(fromInto = this) { @@ -92,7 +96,7 @@ module.exports.mixin = parent => } /** - * Load derived java configs into 'into'. + * Load java constants into 'into'. * @param {Object} into - destination context */ loadJavaConstants(into = this) { @@ -102,7 +106,7 @@ module.exports.mixin = parent => } /** - * Compose with selected java. + * Compose with selected java configuration. */ async composeWithJavaDependencies(config = this.jhipsterConfig) { config = defaults({}, config, defaultConfig); diff --git a/generators/maven/constants.cjs b/generators/maven/constants.cjs index 53c4580f1ac..067365b9dfb 100644 --- a/generators/maven/constants.cjs +++ b/generators/maven/constants.cjs @@ -16,8 +16,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +const MAVEN = 'maven'; +const MAVEN_DESCRIPTION = 'Maven'; +const BUILD_DESTINATION_VALUE = 'target'; + module.exports = { - MAVEN: 'maven', - MAVEN_DESCRIPTION: 'Maven', - BUILD_DESTINATION_VALUE: 'target', + MAVEN, + MAVEN_DESCRIPTION, + BUILD_DESTINATION_VALUE, }; diff --git a/generators/maven/generator.spec.cjs b/generators/maven/generator.spec.cjs index 7f2bb66a738..7a5c36665e9 100644 --- a/generators/maven/generator.spec.cjs +++ b/generators/maven/generator.spec.cjs @@ -37,7 +37,7 @@ describe(`JHipster ${generator} generator`, () => { customPrompts: {}, generatorPath, }); - describe('blueprint support', () => testBlueprintSupport('maven')); + describe('blueprint support', () => testBlueprintSupport(generator)); describe('with valid configuration', () => { let runResult; before(async () => { diff --git a/generators/maven/index.cjs b/generators/maven/index.cjs index e2b719a2e62..279c2a15c4d 100644 --- a/generators/maven/index.cjs +++ b/generators/maven/index.cjs @@ -57,7 +57,7 @@ module.exports = class extends MixedChain { } } - _initializing() { + get initializing() { return { validateFromCli() { this.checkInvocationFromCLI(); @@ -77,10 +77,10 @@ module.exports = class extends MixedChain { get [INITIALIZING_PRIORITY]() { if (this.delegateToBlueprint) return; - return this._initializing(); + return this.initializing; } - _loading() { + get loading() { return { configureChain() { this.configureChain(); @@ -96,7 +96,7 @@ module.exports = class extends MixedChain { get [LOADING_PRIORITY]() { if (this.delegateToBlueprint) return; - return this._loading(); + return this.loading; } get preparing() { @@ -112,7 +112,7 @@ module.exports = class extends MixedChain { return this.preparing; } - _writing() { + get writing() { return { async writeFiles() { if (this.shouldSkipFiles()) return; @@ -123,6 +123,6 @@ module.exports = class extends MixedChain { get [WRITING_PRIORITY]() { if (this.delegateToBlueprint) return; - return this._writing(); + return this.writing; } }; diff --git a/generators/project-name/constants.cjs b/generators/project-name/constants.cjs index bfd842ef7f2..9de3d59b9c0 100644 --- a/generators/project-name/constants.cjs +++ b/generators/project-name/constants.cjs @@ -17,17 +17,21 @@ * limitations under the License. */ const BASE_NAME = 'baseName'; -const BASE_NAME_DESC = 'Application base name'; +const BASE_NAME_DESCRIPTION = 'Application base name'; + const JHIPSTER_VERSION = 'jhipsterVersion'; -const JHIPSTER_VERSION_DESC = 'Force jhipsterVersion for reproducibility'; +const JHIPSTER_VERSION_DESCRIPTION = 'Force jhipsterVersion for reproducibility'; + const PROJECT_NAME = 'projectName'; +const PROJECT_NAME_DESCRIPTION = 'Project name'; const PROJECT_NAME_DEFAULT_VALUE = 'JHipster project'; module.exports = { BASE_NAME, - BASE_NAME_DESC, + BASE_NAME_DESCRIPTION, JHIPSTER_VERSION, - JHIPSTER_VERSION_DESC, + JHIPSTER_VERSION_DESCRIPTION, PROJECT_NAME, + PROJECT_NAME_DESCRIPTION, PROJECT_NAME_DEFAULT_VALUE, }; diff --git a/generators/project-name/generator.spec.cjs b/generators/project-name/generator.spec.cjs index 22b6e30d585..32e751892bf 100644 --- a/generators/project-name/generator.spec.cjs +++ b/generators/project-name/generator.spec.cjs @@ -20,7 +20,7 @@ const expect = require('expect'); const path = require('path'); const { basicTests, testBlueprintSupport } = require('../../test/support/index.cjs'); -const { requiredConfig, defaultConfig, reproducibleConfigForTests } = require('./config.cjs'); +const { defaultConfig, requiredConfig, reproducibleConfigForTests } = require('./config.cjs'); const { GENERATOR_PROJECT_NAME } = require('../generator-list'); const generatorPath = path.join(__dirname, 'index.cjs'); @@ -39,5 +39,5 @@ describe(`JHipster ${generator} generator`, () => { }, generatorPath, }); - describe('blueprint support', () => testBlueprintSupport('project-name')); + describe('blueprint support', () => testBlueprintSupport(generator)); }); diff --git a/generators/project-name/index.cjs b/generators/project-name/index.cjs index e7cc2cecead..a9eabe09e4a 100644 --- a/generators/project-name/index.cjs +++ b/generators/project-name/index.cjs @@ -61,7 +61,7 @@ module.exports = class extends MixedChain { } } - _initializing() { + get initializing() { return { validateFromCli() { this.checkInvocationFromCLI(); @@ -81,21 +81,15 @@ module.exports = class extends MixedChain { get [INITIALIZING_PRIORITY]() { if (this.delegateToBlueprint) return; - return this._initializing(); + return this.initializing; } - _prompting() { + get prompting() { return { async showPrompts() { if (this.shouldSkipPrompts()) return; await this.prompt( [ - { - name: PROJECT_NAME, - type: 'input', - message: 'What is the project name of your application?', - default: () => this._getDefaultProjectName(), - }, { name: BASE_NAME, type: 'input', @@ -103,6 +97,12 @@ module.exports = class extends MixedChain { message: 'What is the base name of your application?', default: () => this.getDefaultAppName(), }, + { + name: PROJECT_NAME, + type: 'input', + message: 'What is the project name of your application?', + default: () => this._getDefaultProjectName(), + }, ], this.config ); @@ -112,10 +112,10 @@ module.exports = class extends MixedChain { get [PROMPTING_PRIORITY]() { if (this.delegateToBlueprint) return; - return this._prompting(); + return this.prompting; } - _configuring() { + get configuring() { return { configure() { this.configureProjectName(); @@ -125,10 +125,10 @@ module.exports = class extends MixedChain { get [CONFIGURING_PRIORITY]() { if (this.delegateToBlueprint) return; - return this._configuring(); + return this.configuring; } - _loading() { + get loading() { return { configureChain() { this.configureChain(); @@ -144,7 +144,7 @@ module.exports = class extends MixedChain { get [LOADING_PRIORITY]() { if (this.delegateToBlueprint) return; - return this._loading(); + return this.loading; } get preparing() { diff --git a/generators/project-name/mixin.cjs b/generators/project-name/mixin.cjs index d446befca7a..0f1d6cd7267 100644 --- a/generators/project-name/mixin.cjs +++ b/generators/project-name/mixin.cjs @@ -66,17 +66,16 @@ module.exports.mixin = parent => } /** - * Load derived project-name configs into fromInto. + * Prepare derived project-name properties into fromInto. * @param {any} fromInto - source/destination context */ - // eslint-disable-next-line no-empty-pattern prepareDerivedProjectNameProperties(fromInto = this) { fromInto.dasherizedBaseName = kebabCase(fromInto[BASE_NAME]); fromInto.humanizedBaseName = startCase(fromInto[BASE_NAME]); } /** - * Load derived project-name configs into 'into'. + * Load project-name constants into 'into'. * @param {Object} into - destination context */ loadProjectNameConstants(into = this) {} diff --git a/generators/project-name/options.cjs b/generators/project-name/options.cjs index cd176418ed6..d2710d657ed 100644 --- a/generators/project-name/options.cjs +++ b/generators/project-name/options.cjs @@ -16,18 +16,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const { BASE_NAME, BASE_NAME_DESC, JHIPSTER_VERSION, JHIPSTER_VERSION_DESC } = require('./constants.cjs'); +const { BASE_NAME, BASE_NAME_DESCRIPTION, JHIPSTER_VERSION, JHIPSTER_VERSION_DESCRIPTION } = require('./constants.cjs'); module.exports.options = { - [JHIPSTER_VERSION]: { - desc: JHIPSTER_VERSION_DESC, + [BASE_NAME]: { + desc: BASE_NAME_DESCRIPTION, type: String, - hide: true, scope: 'storage', }, - [BASE_NAME]: { - desc: BASE_NAME_DESC, + [JHIPSTER_VERSION]: { + desc: JHIPSTER_VERSION_DESCRIPTION, type: String, + hide: true, scope: 'storage', }, }; diff --git a/generators/spring-boot/generator.spec.cjs b/generators/spring-boot/generator.spec.cjs index 75cbde3be8a..869c76c97a2 100644 --- a/generators/spring-boot/generator.spec.cjs +++ b/generators/spring-boot/generator.spec.cjs @@ -19,8 +19,9 @@ const expect = require('expect'); const path = require('path'); -const { basicTests, testBlueprintSupport } = require('../../test/support/index.cjs'); const { skipPrettierHelpers: helpers } = require('../../test/utils/utils'); + +const { basicTests, testBlueprintSupport } = require('../../test/support/index.cjs'); const { requiredConfig, defaultConfig } = require('./config.cjs'); const { GENERATOR_SPRING_BOOT } = require('../generator-list'); @@ -37,7 +38,7 @@ describe(`JHipster ${generator} generator`, () => { customPrompts: {}, generatorPath, }); - describe('blueprint support', () => testBlueprintSupport('spring-boot')); + describe('blueprint support', () => testBlueprintSupport(generator)); describe('with', () => { describe('default config', () => { let runResult; diff --git a/generators/spring-boot/index.cjs b/generators/spring-boot/index.cjs index 74e6fff792d..ef2da677d4f 100644 --- a/generators/spring-boot/index.cjs +++ b/generators/spring-boot/index.cjs @@ -61,7 +61,7 @@ module.exports = class extends MixedChain { } } - _initializing() { + get initializing() { return { validateFromCli() { this.checkInvocationFromCLI(); @@ -81,10 +81,10 @@ module.exports = class extends MixedChain { get [INITIALIZING_PRIORITY]() { if (this.delegateToBlueprint) return; - return this._initializing(); + return this.initializing; } - _configuring() { + get configuring() { return { configure() { this.configureSpringBoot(); @@ -94,24 +94,24 @@ module.exports = class extends MixedChain { get [CONFIGURING_PRIORITY]() { if (this.delegateToBlueprint) return; - return this._configuring(); + return this.configuring; } - _composing() { + get composing() { return { async compose() { - // eslint-disable-next-line no-useless-return if (!this.shouldComposeModular()) return; + await this.composeWithSpringBootConfig(); }, }; } get [COMPOSING_PRIORITY]() { if (this.delegateToBlueprint) return; - return this._composing(); + return this.composing; } - _loading() { + get loading() { return { configureChain() { this.configureChain(); @@ -127,7 +127,7 @@ module.exports = class extends MixedChain { get [LOADING_PRIORITY]() { if (this.delegateToBlueprint) return; - return this._loading(); + return this.loading; } get preparing() { @@ -143,7 +143,7 @@ module.exports = class extends MixedChain { return this.preparing; } - _writing() { + get writing() { return { async writeFiles() { if (this.shouldSkipFiles()) return; @@ -154,6 +154,6 @@ module.exports = class extends MixedChain { get [WRITING_PRIORITY]() { if (this.delegateToBlueprint) return; - return this._writing(); + return this.writing; } }; diff --git a/generators/spring-boot/mixin.cjs b/generators/spring-boot/mixin.cjs index 9c6ff37206b..58ff8e9182f 100644 --- a/generators/spring-boot/mixin.cjs +++ b/generators/spring-boot/mixin.cjs @@ -17,9 +17,10 @@ * limitations under the License. */ const { defaults } = require('lodash'); + const { requiredConfig, defaultConfig } = require('./config.cjs'); const { options } = require('./options.cjs'); -const { SPRING_BOOT_VERSION, SPRING_BOOT_PARENT_BOM } = require('./constants.cjs'); +const { SPRING_BOOT_VERSION, SPRING_BOOT_PARENT_BOM, SPRING_BOOT_PARENT_BOM_DEFAULT_VALUE } = require('./constants.cjs'); const { GENERATOR_JAVA } = require('../generator-list'); @@ -27,6 +28,13 @@ module.exports.dependencyChain = [GENERATOR_JAVA]; module.exports.mixin = parent => class extends parent { + /** + * Load spring-boot options constants. + */ + loadSpringBootOptionsConstants(into = this) { + into.SPRING_BOOT_PARENT_BOM_DEFAULT_VALUE = SPRING_BOOT_PARENT_BOM_DEFAULT_VALUE; + } + /** * Register and parse spring-boot options. */ @@ -54,13 +62,13 @@ module.exports.mixin = parent => } /** - * Load derived spring-boot configs into fromInto. + * Prepare derived spring-boot properties into fromInto. * @param {any} fromInto - source/destination context */ prepareDerivedSpringBootProperties(fromInto = this) {} /** - * Load derived spring-boot configs into 'into'. + * Load spring-boot constants into 'into'. * @param {Object} into - destination context */ loadSpringBootConstants(into = this) { @@ -68,15 +76,9 @@ module.exports.mixin = parent => } /** - * Load derived spring-boot configs into 'into'. - * @param {Object} into - destination context - */ - loadSpringBootOptionsConstants(into = this) {} - - /** - * Compose with selected spring-boot. + * Compose with selected spring-boot configuration. */ - async composeWithSelectedSpringBoot(config = this.jhipsterConfig) { + async composeWithSpringBootConfig(config = this.jhipsterConfig) { config = defaults({}, config, defaultConfig); } }; diff --git a/test/support/index.cjs b/test/support/index.cjs index 8046423c49e..865a7845625 100644 --- a/test/support/index.cjs +++ b/test/support/index.cjs @@ -155,10 +155,9 @@ const testBlueprintSupport = generatorName => { throw new Error(`${priority} should not be called`); }; } - generator[`_${priority}`] = callback; Object.defineProperty(generator, priority, { get() { - generator[`_${priority}`](); + callback(); return {}; }, enumerable: true, @@ -193,7 +192,7 @@ const testBlueprintSupport = generatorName => { const context = helpers .run(path.join(__dirname, `../../generators/${generatorName}/index.cjs`)) .withMockedGenerators([`jhipster-foo-sbs:${generatorName}`]) - .withOptions({ blueprint: 'foo-sbs', skipChecks: true }) + .withOptions({ blueprint: 'foo-sbs', skipChecks: true, configure: true }) .on('ready', generator => { spy = addSpies(generator); });