Skip to content

Commit

Permalink
Update to JHipster main (#604)
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima authored Nov 14, 2024
1 parent 71bbeae commit 3bb318a
Show file tree
Hide file tree
Showing 85 changed files with 4,143 additions and 4,681 deletions.
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 { getGithubSamplesGroups } from 'generator-jhipster/testing';

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

Expand Down
151 changes: 71 additions & 80 deletions .blueprint/generate-sample/generator.mjs
Original file line number Diff line number Diff line change
@@ -1,85 +1,55 @@
import { readdir } from 'node:fs/promises';
import { readFileSync } from 'node:fs';
import { extname, join } from 'node:path';
import BaseGenerator from 'generator-jhipster/generators/base';
import { createNeedleCallback } from 'generator-jhipster/generators/base/support';
import command from './command.mjs';
import { getGithubSamplesGroup } from 'generator-jhipster/testing';

export default class extends BaseGenerator {
/** @type {string} */
sampleName;
templateName;
/** @type {boolean} */
all;
/** @type {string} */
samplesFolder;
/** @type {string} */
sampleType;
/** @type {string} */
sampleFile;
/** @type {any} */
generatorOptions;

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

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;
}
},
});
constructor(args, opts, features) {
super(args, opts, { ...features, queueCommandTasks: true, jhipsterBootstrap: false });
}

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}`,
}),
);
const { samplesFolder, all, sampleName } = this;
if (all) {
this.copyTemplate(`${samplesFolder}/*.jdl`, '');
this.sampleType = 'jdl';
} else if (extname(sampleName) === '.jdl') {
this.copyTemplate(join(samplesFolder, sampleName), sampleName, { noGlob: true });
this.sampleType = 'jdl';
} else {
const { samples } = await getGithubSamplesGroup(this.templatePath(), samplesFolder);
const {
'sample-type': sampleType,
'sample-file': sampleFile = sampleName,
'sample-folder': sampleFolder = samplesFolder,
generatorOptions,
} = samples[sampleName];
this.generatorOptions = generatorOptions;
this.sampleType = sampleType;
if (sampleType === 'jdl') {
const jdlFile = `${sampleFile}.jdl`;
this.copyTemplate(join(sampleFolder, jdlFile), jdlFile, { noGlob: true });
} else if (sampleType === 'yo-rc') {
this.copyTemplate('**', '', {
fromBasePath: this.templatePath(sampleFolder, sampleFile),
globOptions: { dot: true },
});
}
}
},
Expand All @@ -88,19 +58,40 @@ 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,
async generateYoRcSample() {
if (this.sampleType !== 'yo-rc') return;

const generatorOptions = this.getDefaultComposeOptions();
await this.composeWithJHipster('app', { generatorOptions });
},
async generateJdlSample() {
if (this.sampleType !== 'jdl') return;

const generatorOptions = this.getDefaultComposeOptions();
const folderContent = await readdir(this.destinationPath());
const jdlFiles = folderContent.filter(file => file.endsWith('.jdl'));

await this.composeWithJHipster('jdl', {
generatorArgs: jdlFiles,
generatorOptions: {
skipJhipsterDependencies: true,
insight: false,
skipChecks: true,
skipInstall: true,
...generatorOptions,
...(this.all ? { workspaces: true, monorepository: true } : { skipInstall: true }),
},
});
},
async jhipsterInfo() {
await this.composeWithJHipster('info');
},
});
}

getDefaultComposeOptions() {
const packageJson = JSON.parse(readFileSync(new URL('../../package.json', import.meta.url)));
const projectVersion = `${packageJson.version}-git`;
return {
skipJhipsterDependencies: true,
projectVersion,
...this.generatorOptions,
};
}
}
67 changes: 67 additions & 0 deletions .blueprint/generate-sample/support/prepare-sample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import assert from 'node:assert';
import { existsSync } from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { intersection } from 'lodash-es';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

export const prepareSampleEntry = sampleData => {
const [sample, data = {}] = Array.isArray(sampleData) ? sampleData : [sampleData];
const clientFrameworks = ['angular', 'vue', 'react'];
const authenticationTypes = ['jwt', 'oauth2'];
const databaseTypes = ['mysql', 'mssql', 'postgresql', 'mongodb'];

let split = sample.split('-');
if (!split.includes('jdl')) {
assert(existsSync(path.join(__dirname, '../templates/samples', `${sample}`)), `The sample ${sample} does not exist.`);
return [
sample,
{
'sample-file': sample,
'legacy-template-name': sample,
'legacy-sample-file': sample,
'sample-folder': 'samples/',
'sample-type': 'yo-rc',
...data,
},
];
}

intersection(clientFrameworks, split);
const clientFramework = intersection(clientFrameworks, split)[0];
const authenticationType = intersection(authenticationTypes, split)[0];
const databaseType = intersection(databaseTypes, split)[0];
split = split
.filter(s => s !== 'jdl')
.map(s => (s === clientFramework ? 'client' : s === authenticationType ? 'auth' : s === databaseType ? 'database' : s));

const generatorOptions = {};

if (clientFramework) {
generatorOptions.clientFramework = clientFramework;
}
if (authenticationType) {
generatorOptions.authenticationType = authenticationType;
}
if (databaseType) {
generatorOptions.prodDatabaseType = databaseType;
}

const sampleFile = [...split, 'template', 'jdl'].join('-');
const file = path.join(__dirname, '../templates/samples', `${sampleFile}.jdl`);
assert(existsSync(file), `The sample ${file} does not exist.`);

return [
sample,
{
'sample-file': sampleFile,
'legacy-template-name': sample,
'legacy-sample-file': sampleFile,
'sample-folder': 'samples/',
'sample-type': 'jdl',
generatorOptions,
...data,
},
];
};
15 changes: 15 additions & 0 deletions .blueprint/generate-sample/templates/angular.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { prepareSampleEntry } from '../support/prepare-sample.js';

const samples = [
'monolith-angular-jwt-jdl',
'monolith-angular-jwt-i18n-jdl',
'monolith-angular-oauth2-jdl',
['monolith-angular-oauth2-mongodb-jdl', { 'legacy-sample-file': 'monolith-angular-auth-mongodb-template-jdl', e2e: 'false' }],
'monolith-angular-oauth2-i18n-jdl',
'monolith-angular-jwt-i18n-dev',
['monolith-angular-jwt-mongodb-jdl', { 'legacy-sample-file': 'monolith-client-auth-database-template-jdl', e2e: 'false' }],
'monolith-angular-mssql-prod-jdl',
'monolith-angular-postgresql-prod-jdl',
];

export default Object.fromEntries(samples.map(sample => prepareSampleEntry(sample)));
6 changes: 6 additions & 0 deletions .blueprint/generate-sample/templates/microservice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
'microservice-oauth2-jdl': {
'sample-folder': 'samples/',
'sample-type': 'jdl',
},
};
13 changes: 13 additions & 0 deletions .blueprint/generate-sample/templates/react.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { prepareSampleEntry } from '../support/prepare-sample.js';

const samples = [
'monolith-react-jwt-jdl',
'monolith-react-jwt-i18n-jdl',
'monolith-react-oauth2-jdl',
'monolith-react-oauth2-i18n-jdl',
'monolith-react-mysql-prod-jdl',
['monolith-react-mongodb-prod-jdl', { 'legacy-sample-file': 'monolith-client-database-prod-template-jdl', e2e: 'false' }],
'monolith-react-oauth2-dev',
];

export default Object.fromEntries(samples.map(sample => prepareSampleEntry(sample)));
Loading

0 comments on commit 3bb318a

Please sign in to comment.