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

Update generator-jhipster to 8.6.0 #493

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion .blueprint/cli/commands.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2013-2023 the original author or authors from the JHipster project.
* Copyright 2013-2024 the original author or authors from the JHipster project.
*
* This file is part of the JHipster project, see https://www.jhipster.tech/
* for more information.
Expand All @@ -22,6 +22,10 @@ const defaultCommands = {
desc: 'Generate a test sample',
blueprint: '@jhipster/jhipster-dev',
},
'github-build-matrix': {
desc: 'Build a matrix of jobs for github actions',
blueprint: '@jhipster/jhipster-dev',
},
};

export default defaultCommands;
31 changes: 27 additions & 4 deletions .blueprint/generate-sample/command.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2013-2023 the original author or authors from the JHipster project.
* Copyright 2013-2024 the original author or authors from the JHipster project.
*
* This file is part of the JHipster project, see https://www.jhipster.tech/
* for more information.
Expand All @@ -17,6 +17,8 @@
* limitations under the License.
*/
import { GENERATOR_APP } from 'generator-jhipster/generators';
import { getSamples } from './get-samples.mjs';

/**
* @type {import('generator-jhipster').JHipsterCommandDefinition}
*/
Expand All @@ -26,12 +28,33 @@ const command = {
type: String,
},
},
options: {
templateName: {
type: String,
configs: {
sampleName: {
prompt: gen => ({
when: !gen.all,
type: 'list',
message: 'which sample do you want to generate?',
choices: async () => getSamples(gen.templatePath(gen.samplesFolder)),
}),
scope: 'generator',
},
all: {
description: 'Generate every sample in a workspace',
cli: {
type: Boolean,
},
scope: 'generator',
},
samplesFolder: {
description: 'Path to the samples folder',
cli: {
type: String,
},
default: 'samples',
scope: 'generator',
},
},
options: {},
import: [GENERATOR_APP],
};

Expand Down
98 changes: 32 additions & 66 deletions .blueprint/generate-sample/generator.mjs
Original file line number Diff line number Diff line change
@@ -1,86 +1,47 @@
import { readdir } from 'node:fs/promises';
import { readFileSync } from 'node:fs';
import BaseGenerator from 'generator-jhipster/generators/base';
import { createNeedleCallback } from 'generator-jhipster/generators/base/support';
import command from './command.mjs';

export default class extends BaseGenerator {
sampleName;
templateName;
all;
samplesFolder;

constructor(args, opts, features) {
super(args, opts, { ...features, jhipsterBootstrap: false });
}

get [BaseGenerator.INITIALIZING]() {
return this.asInitializingTaskGroup({
async initializeOptions() {
this.parseJHipsterCommand(command);
async parseCommand() {
await this.parseCurrentJHipsterCommand();
},
});
}

get [BaseGenerator.PROMPTING]() {
return this.asPromptingTaskGroup({
async askForSample() {
if (!this.sampleName) {
const answers = await this.prompt({
type: 'list',
name: 'sampleName',
message: 'which sample do you want to generate?',
choices: async () => readdir(this.templatePath('samples')),
});
this.sampleName = answers.sampleName;
}
await this.promptCurrentJHipsterCommand();
},
});
}

get [BaseGenerator.LOADING]() {
return this.asLoadingTaskGroup({
async loadCommand() {
await this.loadCurrentJHipsterCommandConfig(this);
},
});
}

get [BaseGenerator.WRITING]() {
return this.asWritingTaskGroup({
async copySample() {
this.copyTemplate(`{.,}**`, '', {
fromBasePath: this.templatePath(`samples/${this.sampleName}`),
});

if (this.sampleName.includes('-template-')) {
if (!this.templateName) {
throw new Error('Template name is required');
}

const clientFrameworks = ['angular', 'vue', 'react'];
const authenticationTypes = ['jwt', 'oauth2'];
const databaseTypes = ['mysql', 'mssql', 'postgresql', 'mongodb'];

const split = this.templateName.split('-');

this._.intersection(clientFrameworks, split);
const clientFramework = this._.intersection(clientFrameworks, split)[0];
const authenticationType = this._.intersection(authenticationTypes, split)[0];
const databaseType = this._.intersection(databaseTypes, split)[0];

if (clientFramework) {
this.editFile(
`${this.sampleName}.jdl`,
createNeedleCallback({
needle: 'jhipster-needle-jdl-application-config',
contentToAdd: `clientFramework ${clientFramework}`,
}),
);
}
if (authenticationType) {
this.editFile(
`${this.sampleName}.jdl`,
createNeedleCallback({
needle: 'jhipster-needle-jdl-application-config',
contentToAdd: `authenticationType ${authenticationType}`,
}),
);
}
if (databaseType) {
this.editFile(
`${this.sampleName}.jdl`,
createNeedleCallback({
needle: 'jhipster-needle-jdl-application-config',
contentToAdd: `${databaseType === 'mongodb' ? 'databaseType' : 'prodDatabaseType'} ${databaseType}`,
}),
);
}
if (this.all) {
this.copyTemplate(`${this.samplesFolder}/*.jdl`, '');
} else {
this.copyTemplate(`${this.samplesFolder}/${this.sampleName}`, this.sampleName, { noGlob: true });
}
},
});
Expand All @@ -89,18 +50,23 @@ export default class extends BaseGenerator {
get [BaseGenerator.END]() {
return this.asEndTaskGroup({
async generateSample() {
const generator = this.sampleName.endsWith('-jdl') ? 'jdl' : 'app';
const generatorArgs = this.sampleName.endsWith('-jdl') ? [this.sampleName] : undefined;
await this.composeWithJHipster(generator, {
generatorArgs,
const packageJson = JSON.parse(readFileSync(new URL('../../package.json', import.meta.url)));
const projectVersion = `${packageJson.version}-git`;

await this.composeWithJHipster('jdl', {
generatorArgs: this.all ? await readdir(this.templatePath('samples')) : [this.sampleName],
generatorOptions: {
skipJhipsterDependencies: true,
insight: false,
skipChecks: true,
skipInstall: true,
projectVersion,
...(this.all ? { workspaces: true, monorepository: true } : { skipInstall: true }),
},
});
},
async jhipsterInfo() {
await this.composeWithJHipster('info');
},
});
}
}
11 changes: 11 additions & 0 deletions .blueprint/generate-sample/get-samples.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { readdir, stat } from 'node:fs/promises';
import { extname } from 'path';

export const getSamples = async samplesFolder => {
const filenames = await readdir(samplesFolder);
const entries = await Promise.all(filenames.map(async filename => [filename, await stat(`${samplesFolder}/${filename}`)]));
return entries
.filter(([filename, statResult]) => extname(filename) === '.jdl' || statResult.isDirectory())
.map(([filename]) => filename)
.filter(filename => !filename.includes('disabled'));
};
48 changes: 24 additions & 24 deletions .blueprint/generate-sample/templates/samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,36 @@ To generate test applications, either automatically by the CI or locally on the

Those are described in `.yo-rc.json` files which is the descriptor file created by Yeoman to keep track of the choices selected while generating an application.

- monolith-angular-jwt-18n-dev
- monolith-react-oauth2-dev
- monolith-angular-jwt-18n-dev
- monolith-react-oauth2-dev

Instead, `-jdl` suffix folders contain `.jdl` files which is the model to create full app and entities:

- monolith-client-auth-template-jdl
- monolith-angular-auth-mongodb-template-jdl
- monolith-client-auth-i18n-template-jdl
- monolith-client-database-prod-template-jdl
- microservice-oauth2-jdl
- monolith-client-auth-template-jdl
- monolith-angular-auth-mongodb-template-jdl
- monolith-client-auth-i18n-template-jdl
- monolith-client-database-prod-template-jdl
- microservice-oauth2-jdl

Every `*template-jdl` app will be customized to generate **five applications** changing **client** (`react`, `vue` or `angular`) and **auth** (`jwt` or `oauth2`) :

- monolith-react-jwt-jdl
- monolith-react-oauth2-jdl
- monolith-angular-jwt-jdl
- monolith-angular-oauth2-jdl
- monolith-angular-oauth2-mongodb-jdl
- monolith-angular-jwt-mongodb-jdl
- monolith-react-jwt-i18n-jdl
- monolith-react-oauth2-i18n-jdl
- monolith-angular-jwt-i18n-jdl
- monolith-angular-oauth2-i18n-jdl
- monolith-vue-jwt-i18n-jdl
- monolith-vue-oauth2-i18n-jdl
- monolith-react-jwt-jdl
- monolith-react-oauth2-jdl
- monolith-angular-jwt-jdl
- monolith-angular-oauth2-jdl
- monolith-angular-oauth2-mongodb-jdl
- monolith-angular-jwt-mongodb-jdl
- monolith-react-jwt-i18n-jdl
- monolith-react-oauth2-i18n-jdl
- monolith-angular-jwt-i18n-jdl
- monolith-angular-oauth2-i18n-jdl
- monolith-vue-jwt-i18n-jdl
- monolith-vue-oauth2-i18n-jdl

In case of **database** (`mssql`, `mongodb`, `mysql` and `postgresql`) will be generated:

- monolith-angular-mssql-prod-jdl
- monolith-react-mysql-prod-jdl
- monolith-angular-mongodb-prod-jdl
- monolith-angular-postgresql-prod-jdl
- monolith-vue-mongodb-prod-jdl
- monolith-angular-mssql-prod-jdl
- monolith-react-mysql-prod-jdl
- monolith-angular-mongodb-prod-jdl
- monolith-angular-postgresql-prod-jdl
- monolith-vue-mongodb-prod-jdl
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"generator-jhipster": {
"blueprints": [
{
"name": "generator-jhipster-nodejs"
}
],
"applicationType": "monolith",
"baseName": "monolithAngularJwtDevApp",
"testFrameworks": ["cypress"],
"creationTimestamp": 1615471285814,
"packageName": "com.jhipster.node",
"databaseType": "sql",
"devDatabaseType": "sqlite",
"prodDatabaseType": "mysql",
"authenticationType": "jwt",
"clientFramework": "angular",
"enableTranslation": true,
"nativeLanguage": "en",
"packageFolder": "com/jhipster/node",
"languages": ["en", "fr"]
}
"generator-jhipster": {
"blueprints": [
{
"name": "generator-jhipster-nodejs"
}
],
"applicationType": "monolith",
"baseName": "monolithAngularJwtDevApp",
"testFrameworks": ["cypress"],
"creationTimestamp": 1615471285814,
"packageName": "com.jhipster.node",
"databaseType": "sql",
"devDatabaseType": "sqlite",
"prodDatabaseType": "mysql",
"authenticationType": "jwt",
"clientFramework": "angular",
"enableTranslation": true,
"nativeLanguage": "en",
"packageFolder": "com/jhipster/node",
"languages": ["en", "fr"]
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"generator-jhipster": {
"blueprints": [
{
"name": "generator-jhipster-nodejs"
}
],
"applicationType": "monolith",
"baseName": "monolithReactOauth2DevApp",
"testFrameworks": ["cypress"],
"creationTimestamp": 1615471285814,
"packageName": "com.jhipster.node",
"databaseType": "sql",
"devDatabaseType": "sqlite",
"prodDatabaseType": "mysql",
"authenticationType": "oauth2",
"clientFramework": "react",
"enableTranslation": false,
"nativeLanguage": "en",
"packageFolder": "com/jhipster/node",
"languages": ["en"]
}
"generator-jhipster": {
"blueprints": [
{
"name": "generator-jhipster-nodejs"
}
],
"applicationType": "monolith",
"baseName": "monolithReactOauth2DevApp",
"testFrameworks": ["cypress"],
"creationTimestamp": 1615471285814,
"packageName": "com.jhipster.node",
"databaseType": "sql",
"devDatabaseType": "sqlite",
"prodDatabaseType": "mysql",
"authenticationType": "oauth2",
"clientFramework": "react",
"enableTranslation": false,
"nativeLanguage": "en",
"packageFolder": "com/jhipster/node",
"languages": ["en"]
}
}
24 changes: 24 additions & 0 deletions .blueprint/github-build-matrix/build-matrix.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { RECOMMENDED_JAVA_VERSION, RECOMMENDED_NODE_VERSION } from 'generator-jhipster';
import { fromMatrix } from 'generator-jhipster/testing';

const defaultMatrix = {
os: ['ubuntu-latest'],
'node-version': [RECOMMENDED_NODE_VERSION],
'java-version': [RECOMMENDED_JAVA_VERSION],
'default-environment': ['prod'],
};

export const buildMatrix = ({ samples, samplesFolder }) => {
return {
include: Object.values(
fromMatrix({
...defaultMatrix,
'sample-name': samples,
}),
).map(sample => ({
...sample,
'job-name': sample['sample-name'],
'extra-args': `--samples-folder ${samplesFolder}`,
})),
};
};
Loading
Loading