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

Blueprint support improvements. #23598

Merged
merged 10 commits into from
Sep 22, 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
2 changes: 1 addition & 1 deletion cli/cli.spec.mts
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ describe('cli', () => {
expect(stdout).toMatch('Usage: jhipster run jhipster:app [options]');
});
it('should print options', () => {
expect(stdout).toMatch('--application-type <value>');
expect(stdout).toMatch('--defaults');
});
it('should exit with code 0', () => {
expect(exitCode).toBe(0);
Expand Down
13 changes: 1 addition & 12 deletions generators/angular/generator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,12 @@ export default class AngularGenerator extends BaseApplicationGenerator {

async beforeQueue() {
await this.dependsOnJHipster(GENERATOR_CLIENT);
await this.dependsOnJHipster(GENERATOR_LANGUAGES);
if (!this.fromBlueprint) {
await this.composeWithBlueprints(GENERATOR_ANGULAR);
}
}

get composing() {
return this.asComposingTaskGroup({
async composing() {
await this.composeWithJHipster(GENERATOR_LANGUAGES);
},
});
}

get [BaseApplicationGenerator.COMPOSING]() {
return this.asComposingTaskGroup(this.delegateTasksToBlueprint(() => this.composing));
}

get loading() {
return this.asLoadingTaskGroup({
loadPackageJson({ application }) {
Expand Down
27 changes: 16 additions & 11 deletions generators/app/__snapshots__/generator.spec.mts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,51 +10,53 @@ Options:
--defaults Execute jhipster with default config
--skip-client Skip the client-side application generation
--skip-server Skip the server-side application generation
--skip-commit-hook Skip adding husky commit hooks
--skip-user-management Skip the user management module during app generation
--skip-check-length-of-identifier Skip check the length of the identifier, only for recent Oracle databases that support 30+ characters metadata
--skip-fake-data Skip generation of fake data for development
--jhi-prefix <value> Add prefix before services, controllers and states name
--entity-suffix <value> Add suffix after entities name
--dto-suffix <value> Add suffix after dtos name
--auth <value> Provide authentication type for the application when skipping server side generation
--db <value> Provide DB name for the application when skipping server side generation
--blueprint <value...> DEPRECATED: Specify a generator blueprint to use for the sub generators
--blueprints <value> A comma separated list of one or more generator blueprints to use for the sub generators, e.g. --blueprints kotlin,vuejs
--incremental-changelog Creates incremental database changelogs
--recreate-initial-changelog Recreate the initial database changelog based on the current config
--ignore-errors Don't fail on prettier errors.
--enable-translation Enable translation
-l, --language <value...> Language to be added to application (existing languages are not removed)
--pk-type <value> Default primary key type (beta)
--client-package-manager <value> Force an unsupported client package manager
--test-frameworks <value...> Test frameworks to be generated
--application-type <value> Application type to generate (choices: "monolith", "gateway", "microservice")
--skip-cache Do not remember prompt answers (default: false)
--skip-install Do not automatically install dependencies (default: false)
--force-install Fail on install dependencies error (default: false)
--ask-answered Show prompts for already configured options (default: false)
--auth <value> Provide authentication type for the application when skipping server side generation
--db <value> Provide DB name for the application when skipping server side generation
--incremental-changelog Creates incremental database changelogs
--skip-user-management Skip the user management module during app generation
--recreate-initial-changelog Recreate the initial database changelog based on the current config
--build <value> Provide build tool for the application when skipping server side generation
--cache-provider <value> Cache provider
--enable-swagger-codegen API first development using OpenAPI-generator
--enable-hibernate-cache Enable hibernate cache
--message-broker <value> message broker
--reactive Generate a reactive backend
--search-engine <value> Provide search engine for the application when skipping server side generation
--skip-check-length-of-identifier Skip check the length of the identifier, only for recent Oracle databases that support 30+ characters metadata
--skip-db-changelog Skip the generation of database migrations
--skip-fake-data Skip generation of fake data for development
--websocket <value> Provide websocket option for the application when skipping server side generation
--project-version <value> project version to use, this option is not persisted (env: JHI_PROJECT_VERSION)
--jhipster-dependencies-version <value> jhipster-dependencies version to use, this option is not persisted (env: JHIPSTER_DEPENDENCIES_VERSION)
--application-type <value> Application type to generate (choices: "monolith", "gateway", "microservice")
--with-generated-flag Add a GeneratedByJHipster annotation to all generated java classes and interfaces
--dev-database-type <value> Development database
--client-framework <value> Provide client framework for the application (choices: "angular", "react", "vue", "no")
--microfrontend Enable microfrontend support
--microfrontends <value> Microfrontends to load
--with-admin-ui Generate administrative user interface
--prettier-tab-width <value> Default tab width for prettier
--skip-commit-hook Skip adding husky commit hooks
--skip-git Skip git repository initialization
--monorepository Use monorepository
--cypress-coverage Enable Cypress code coverage report generation
--cypress-audit Enable cypress-audit/lighthouse report generation
--enable-translation Enable translation
-l, --language <value...> Language to be added to application (existing languages are not removed)
-n, --native-language [value] Set application native language
-h, --help display help for command
"
`;
Expand Down Expand Up @@ -85,6 +87,7 @@ exports[`generator - app with default config should match snapshot 1`] = `
"addSpringMilestoneRepository": false,
"angularLocaleId": "en",
"applicationType": "monolith",
"applicationTypeAny": true,
"applicationTypeGateway": false,
"applicationTypeMicroservice": false,
"applicationTypeMonolith": true,
Expand Down Expand Up @@ -637,6 +640,7 @@ exports[`generator - app with gateway should match snapshot 1`] = `
"addSpringMilestoneRepository": false,
"angularLocaleId": "en",
"applicationType": "gateway",
"applicationTypeAny": true,
"applicationTypeGateway": true,
"applicationTypeMicroservice": false,
"applicationTypeMonolith": false,
Expand Down Expand Up @@ -1189,6 +1193,7 @@ exports[`generator - app with microservice should match snapshot 1`] = `
"VUE": "vue",
"addSpringMilestoneRepository": false,
"applicationType": "microservice",
"applicationTypeAny": true,
"applicationTypeGateway": false,
"applicationTypeMicroservice": true,
"applicationTypeMonolith": false,
Expand Down
67 changes: 1 addition & 66 deletions generators/app/command.mts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import chalk from 'chalk';
import { JHipsterCommandDefinition } from '../base/api.mjs';
import {
GENERATOR_BOOTSTRAP,
Expand All @@ -27,7 +26,6 @@ import {
GENERATOR_LANGUAGES,
GENERATOR_SERVER,
} from '../generator-list.mjs';
import { APPLICATION_TYPE_GATEWAY, APPLICATION_TYPE_MICROSERVICE, APPLICATION_TYPE_MONOLITH } from '../../jdl/index.js';

const command: JHipsterCommandDefinition = {
options: {
Expand All @@ -45,26 +43,6 @@ const command: JHipsterCommandDefinition = {
type: Boolean,
scope: 'storage',
},
skipCommitHook: {
description: 'Skip adding husky commit hooks',
type: Boolean,
scope: 'storage',
},
skipUserManagement: {
description: 'Skip the user management module during app generation',
type: Boolean,
scope: 'storage',
},
skipCheckLengthOfIdentifier: {
description: 'Skip check the length of the identifier, only for recent Oracle databases that support 30+ characters metadata',
type: Boolean,
scope: 'storage',
},
skipFakeData: {
description: 'Skip generation of fake data for development',
type: Boolean,
scope: 'storage',
},
jhiPrefix: {
description: 'Add prefix before services, controllers and states name',
type: String,
Expand All @@ -80,16 +58,6 @@ const command: JHipsterCommandDefinition = {
type: String,
scope: 'storage',
},
authenticationType: {
name: 'auth',
description: 'Provide authentication type for the application when skipping server side generation',
type: String,
scope: 'storage',
},
db: {
description: 'Provide DB name for the application when skipping server side generation',
type: String,
},
blueprint: {
description: 'DEPRECATED: Specify a generator blueprint to use for the sub generators',
type: Array,
Expand All @@ -99,30 +67,10 @@ const command: JHipsterCommandDefinition = {
'A comma separated list of one or more generator blueprints to use for the sub generators, e.g. --blueprints kotlin,vuejs',
type: String,
},
incrementalChangelog: {
description: 'Creates incremental database changelogs',
type: Boolean,
scope: 'storage',
},
recreateInitialChangelog: {
description: 'Recreate the initial database changelog based on the current config',
type: Boolean,
},
ignoreErrors: {
description: "Don't fail on prettier errors.",
type: Boolean,
},
enableTranslation: {
description: 'Enable translation',
type: Boolean,
required: false,
scope: 'storage',
},
language: {
alias: 'l',
description: 'Language to be added to application (existing languages are not removed)',
type: Array,
},
pkType: {
description: 'Default primary key type (beta)',
type: String,
Expand All @@ -138,20 +86,7 @@ const command: JHipsterCommandDefinition = {
type: Array,
},
},
configs: {
applicationType: {
description: 'Application type to generate',
cli: {
type: String,
},
prompt: {
type: 'list',
message: `Which ${chalk.yellow('*type*')} of application would you like to create?`,
},
choices: [APPLICATION_TYPE_MONOLITH, APPLICATION_TYPE_GATEWAY, APPLICATION_TYPE_MICROSERVICE],
},
},
loadGeneratorOptions: true,
configs: {},
import: [
GENERATOR_BOOTSTRAP,
GENERATOR_SERVER,
Expand Down
8 changes: 4 additions & 4 deletions generators/app/composing.spec.mts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ describe('generator - app - composing', () => {
const ClientGenerator = runResult.mockedGenerators['jhipster:client'];
assert(ClientGenerator.calledOnce);
});
it('should compose with languages generator', () => {
it('should not compose with languages generator', () => {
const LanguagesGenerator = runResult.mockedGenerators['jhipster:languages'];
assert(LanguagesGenerator.calledOnce);
assert.equal(LanguagesGenerator.callCount, 0);
});
it('should not compose with entities generator', () => {
const MockedGenerator = runResult.mockedGenerators['jhipster:entities'];
Expand Down Expand Up @@ -83,9 +83,9 @@ describe('generator - app - composing', () => {
const ClientGenerator = runResult.mockedGenerators['jhipster:client'];
assert.equal(ClientGenerator.callCount, 0);
});
it('should compose with languages generator', () => {
it('should not compose with languages generator', () => {
const LanguagesGenerator = runResult.mockedGenerators['jhipster:languages'];
assert(LanguagesGenerator.calledOnce);
assert.equal(LanguagesGenerator.callCount, 0);
});
it('should not compose with entities generator', () => {
const MockedGenerator = runResult.mockedGenerators['jhipster:entities'];
Expand Down
43 changes: 18 additions & 25 deletions generators/app/generator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import statistics from '../statistics.mjs';
import {
GENERATOR_APP,
GENERATOR_COMMON,
GENERATOR_LANGUAGES,
GENERATOR_CLIENT,
GENERATOR_PAGE,
GENERATOR_SERVER,
Expand All @@ -42,6 +41,8 @@ const { MICROSERVICE } = applicationTypes;
const { JHI_PREFIX, BASE_NAME, JWT_SECRET_KEY, PACKAGE_NAME, PACKAGE_FOLDER, REMEMBER_ME_KEY } = applicationOptions.OptionNames;

export default class JHipsterAppGenerator extends BaseApplicationGenerator {
command = command;

async beforeQueue() {
loadStoredAppOptions.call(this);

Expand All @@ -66,7 +67,7 @@ export default class JHipsterAppGenerator extends BaseApplicationGenerator {
}
},
loadOptions() {
this.parseJHipsterCommand(command);
this.parseJHipsterCommand(this.command);
},

validate() {
Expand All @@ -86,7 +87,7 @@ export default class JHipsterAppGenerator extends BaseApplicationGenerator {
askForInsightOptIn,
async prompting({ control }) {
if (control.existingProject && this.options.askAnswered !== true) return;
await this.prompt(this.prepareQuestions(command.configs));
await this.prompt(this.prepareQuestions(this.command.configs));
},
});
}
Expand Down Expand Up @@ -120,34 +121,32 @@ export default class JHipsterAppGenerator extends BaseApplicationGenerator {
* Composing with others generators, must be executed after `configuring` priority to let others
* generators `configuring` priority to run.
*
* Generators `server`, `client`, `common`, `languages` depends on each other.
* We are composing in the same task so every priority are executed in parallel.
* - compose (app) -> initializing (common) -> initializing (server) -> ...
*
* When composing in different tasks the result would be:
* Composing in different tasks the result would be:
* - composeCommon (app) -> initializing (common) -> prompting (common) -> ... -> composeServer (app) -> initializing (server) -> ...
*
* This behaviour allows a more consistent blueprint support.
*/
async compose() {
const { enableTranslation, skipServer, skipClient } = this.jhipsterConfigWithDefaults;
async composeCommon() {
await this.composeWithJHipster(GENERATOR_COMMON);
if (enableTranslation) {
await this.composeWithJHipster(GENERATOR_LANGUAGES, {
generatorOptions: { regenerate: true },
});
}
if (!skipServer) {
},
async composeServer() {
if (!this.jhipsterConfigWithDefaults.skipServer) {
await this.composeWithJHipster(GENERATOR_SERVER);
}
if (!skipClient) {
},
async composeClient() {
if (!this.jhipsterConfigWithDefaults.skipClient) {
await this.composeWithJHipster(GENERATOR_CLIENT);
}
},

/**
* At this point every other generator should already be configured, so, enforce defaults fallback.
*/
saveConfigWithDefaults() {
this._validateAppConfiguration();
const config = this.jhipsterConfigWithDefaults;
if (config.entitySuffix === config.dtoSuffix) {
throw new Error('Entities cannot be generated as the entity suffix and DTO suffix are equals !');
}
},

async composePages() {
Expand Down Expand Up @@ -196,10 +195,4 @@ export default class JHipsterAppGenerator extends BaseApplicationGenerator {
get [BaseApplicationGenerator.WRITING]() {
return this.delegateTasksToBlueprint(() => this.writing);
}

_validateAppConfiguration(config = this.jhipsterConfigWithDefaults) {
if (config.entitySuffix === config.dtoSuffix) {
throw new Error('Entities cannot be generated as the entity suffix and DTO suffix are equals !');
}
}
}
Loading
Loading