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 to generator-jhipster v8.8.0 #436

Merged
merged 8 commits into from
Dec 24, 2024
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
27 changes: 24 additions & 3 deletions .blueprint/generate-sample/command.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
* limitations under the License.
*/
import { GENERATOR_APP } from 'generator-jhipster/generators';
import { getGithubSamplesGroup } from 'generator-jhipster/testing';
import { getGithubSamplesGroup, getGithubSamplesGroups } from 'generator-jhipster/testing';

const DEFAULT_SAMPLES_GROUP = 'samples';

/**
* @type {import('generator-jhipster').JHipsterCommandDefinition}
Expand All @@ -34,15 +36,34 @@ const command = {
cli: {
type: String,
},
default: 'samples',
scope: 'generator',
},
samplesGroup: {
description: 'Samples group to lookup',
cli: {
type: String,
},
prompt: gen => ({
when: !gen.all && !gen.sampleName,
type: 'list',
message: 'which sample group do you want to lookup?',
choices: async () => getGithubSamplesGroups(gen.templatePath(gen.samplesFolder ?? '')),
default: DEFAULT_SAMPLES_GROUP,
}),
configure: gen => {
gen.samplesGroup = DEFAULT_SAMPLES_GROUP;
},
scope: 'generator',
},
sampleName: {
prompt: gen => ({
when: !gen.all,
type: 'list',
message: 'which sample do you want to generate?',
choices: async () => getGithubSamplesGroup(gen.templatePath(gen.samplesFolder)),
choices: async answers => {
const samples = await getGithubSamplesGroup(gen.templatePath(), answers.samplesFolder ?? gen.samplesFolder);
return Object.keys(samples.samples);
},
}),
scope: 'generator',
},
Expand Down
76 changes: 58 additions & 18 deletions .blueprint/generate-sample/generator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,20 @@ import BaseGenerator from 'generator-jhipster/generators/base';
import { getGithubSamplesGroup } from 'generator-jhipster/testing';

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

constructor(args, opts, features) {
super(args, opts, { ...features, queueCommandTasks: true, jhipsterBootstrap: false });
Expand All @@ -16,20 +27,33 @@ export default class extends BaseGenerator {
get [BaseGenerator.WRITING]() {
return this.asWritingTaskGroup({
async copySample() {
const { samplesFolder, all, sampleName } = this;
const { samplesFolder, samplesGroup, all, sampleName } = this;
const samplesPath = samplesFolder ? join(samplesFolder, samplesGroup) : samplesGroup;
if (all) {
this.copyTemplate(`${samplesFolder}/*.jdl`, '');
this.copyTemplate(`${samplesPath}/*.jdl`, '');
this.sampleType = 'jdl';
} else if (extname(sampleName) === '.jdl') {
this.copyTemplate(join(samplesFolder, sampleName), sampleName, { noGlob: true });
this.copyTemplate(join(samplesPath, sampleName), sampleName, { noGlob: true });
this.sampleType = 'jdl';
} else {
const { samples } = await getGithubSamplesGroup(this.templatePath(), samplesFolder);
const { 'sample-type': sampleType } = samples[sampleName];
const { samples } = await getGithubSamplesGroup(this.templatePath(), samplesPath);
const {
'sample-type': sampleType,
'sample-file': sampleFile = sampleName,
'sample-folder': sampleFolder = samplesPath,
generatorOptions,
} = samples[sampleName];

this.generatorOptions = generatorOptions;
this.sampleType = sampleType;

if (sampleType === 'jdl') {
const jdlFile = `${sampleName}.jdl`;
this.copyTemplate(join(samplesFolder, jdlFile), jdlFile, { noGlob: true });
const jdlFile = `${sampleFile}.jdl`;
this.copyTemplate(join(sampleFolder, jdlFile), jdlFile, { noGlob: true });
} else if (sampleType === 'yo-rc') {
this.copyTemplate(join(samplesFolder, sampleName, '**'), '', {
fromBasePath: this.templatesPath(samplesFolder, sampleName),
this.copyTemplate('**', '', {
fromBasePath: this.templatePath(sampleFolder, sampleFile),
globOptions: { dot: true },
});
}
}
Expand All @@ -39,17 +63,23 @@ export default class extends BaseGenerator {

get [BaseGenerator.END]() {
return this.asEndTaskGroup({
async generateSample() {
const packageJson = JSON.parse(readFileSync(new URL('../../package.json', import.meta.url)));
const projectVersion = `${packageJson.version}-git`;
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: this.all ? await readdir(this.templatePath('samples')) : [this.sampleName],
generatorArgs: jdlFiles,
generatorOptions: {
skipJhipsterDependencies: true,
insight: false,
skipChecks: true,
projectVersion,
...generatorOptions,
...(this.all ? { workspaces: true, monorepository: true } : { skipInstall: true }),
},
});
Expand All @@ -59,4 +89,14 @@ export default class extends BaseGenerator {
},
});
}

getDefaultComposeOptions() {
const packageJson = JSON.parse(readFileSync(new URL('../../package.json', import.meta.url)));
const projectVersion = `${packageJson.version}-git`;
return {
skipJhipsterDependencies: true,
projectVersion,
...this.generatorOptions,
};
}
}
116 changes: 116 additions & 0 deletions .blueprint/github-build-matrix/__snapshots__/generator.spec.mjs.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`generator - github-build-matrix > with samples > should match matrix value 1`] = `
{
"include": [
{
"default-environment": "prod",
"java-version": "17",
"job-name": "gradle-jwt-react",
"jwt-secret-key": "ZjY4MTM4YjI5YzMwZjhjYjI2OTNkNTRjMWQ5Y2Q0Y2YwOWNmZTE2NzRmYzU3NTMwM2NjOTE3MTllOTM3MWRkMzcyYTljMjVmNmQ0Y2MxOTUzODc0MDhhMTlkMDIxMzI2YzQzZDM2ZDE3MmQ3NjVkODk3OTVmYzljYTQyZDNmMTQ=",
"node-version": "22.12.0",
"npm-version": "11.0.0",
"os": "ubuntu-latest",
"sample": "gradle-jwt-react",
"sample-type": "jdl",
"samples-group": "samples",
},
{
"default-environment": "prod",
"java-version": "17",
"job-name": "gradle-ms-eureka-oauth",
"jwt-secret-key": "ZjY4MTM4YjI5YzMwZjhjYjI2OTNkNTRjMWQ5Y2Q0Y2YwOWNmZTE2NzRmYzU3NTMwM2NjOTE3MTllOTM3MWRkMzcyYTljMjVmNmQ0Y2MxOTUzODc0MDhhMTlkMDIxMzI2YzQzZDM2ZDE3MmQ3NjVkODk3OTVmYzljYTQyZDNmMTQ=",
"node-version": "22.12.0",
"npm-version": "11.0.0",
"os": "ubuntu-latest",
"sample": "gradle-ms-eureka-oauth",
"sample-type": "jdl",
"samples-group": "samples",
},
{
"default-environment": "prod",
"java-version": "17",
"job-name": "gradle-oauth-angular",
"jwt-secret-key": "ZjY4MTM4YjI5YzMwZjhjYjI2OTNkNTRjMWQ5Y2Q0Y2YwOWNmZTE2NzRmYzU3NTMwM2NjOTE3MTllOTM3MWRkMzcyYTljMjVmNmQ0Y2MxOTUzODc0MDhhMTlkMDIxMzI2YzQzZDM2ZDE3MmQ3NjVkODk3OTVmYzljYTQyZDNmMTQ=",
"node-version": "22.12.0",
"npm-version": "11.0.0",
"os": "ubuntu-latest",
"sample": "gradle-oauth-angular",
"sample-type": "jdl",
"samples-group": "samples",
},
{
"default-environment": "prod",
"java-version": "17",
"job-name": "jdl-default-app",
"jwt-secret-key": "ZjY4MTM4YjI5YzMwZjhjYjI2OTNkNTRjMWQ5Y2Q0Y2YwOWNmZTE2NzRmYzU3NTMwM2NjOTE3MTllOTM3MWRkMzcyYTljMjVmNmQ0Y2MxOTUzODc0MDhhMTlkMDIxMzI2YzQzZDM2ZDE3MmQ3NjVkODk3OTVmYzljYTQyZDNmMTQ=",
"node-version": "22.12.0",
"npm-version": "11.0.0",
"os": "ubuntu-latest",
"sample": "jdl-default-app",
"sample-type": "jdl",
"samples-group": "samples",
},
{
"default-environment": "prod",
"java-version": "17",
"job-name": "mvn-jwt-angular",
"jwt-secret-key": "ZjY4MTM4YjI5YzMwZjhjYjI2OTNkNTRjMWQ5Y2Q0Y2YwOWNmZTE2NzRmYzU3NTMwM2NjOTE3MTllOTM3MWRkMzcyYTljMjVmNmQ0Y2MxOTUzODc0MDhhMTlkMDIxMzI2YzQzZDM2ZDE3MmQ3NjVkODk3OTVmYzljYTQyZDNmMTQ=",
"node-version": "22.12.0",
"npm-version": "11.0.0",
"os": "ubuntu-latest",
"sample": "mvn-jwt-angular",
"sample-type": "jdl",
"samples-group": "samples",
},
{
"default-environment": "prod",
"java-version": "17",
"job-name": "mvn-jwt-redis-angular",
"jwt-secret-key": "ZjY4MTM4YjI5YzMwZjhjYjI2OTNkNTRjMWQ5Y2Q0Y2YwOWNmZTE2NzRmYzU3NTMwM2NjOTE3MTllOTM3MWRkMzcyYTljMjVmNmQ0Y2MxOTUzODc0MDhhMTlkMDIxMzI2YzQzZDM2ZDE3MmQ3NjVkODk3OTVmYzljYTQyZDNmMTQ=",
"node-version": "22.12.0",
"npm-version": "11.0.0",
"os": "ubuntu-latest",
"sample": "mvn-jwt-redis-angular",
"sample-type": "jdl",
"samples-group": "samples",
},
{
"default-environment": "prod",
"java-version": "17",
"job-name": "mvn-ms-consul-jwt",
"jwt-secret-key": "ZjY4MTM4YjI5YzMwZjhjYjI2OTNkNTRjMWQ5Y2Q0Y2YwOWNmZTE2NzRmYzU3NTMwM2NjOTE3MTllOTM3MWRkMzcyYTljMjVmNmQ0Y2MxOTUzODc0MDhhMTlkMDIxMzI2YzQzZDM2ZDE3MmQ3NjVkODk3OTVmYzljYTQyZDNmMTQ=",
"node-version": "22.12.0",
"npm-version": "11.0.0",
"os": "ubuntu-latest",
"sample": "mvn-ms-consul-jwt",
"sample-type": "jdl",
"samples-group": "samples",
},
{
"default-environment": "prod",
"java-version": "17",
"job-name": "mvn-no-client",
"jwt-secret-key": "ZjY4MTM4YjI5YzMwZjhjYjI2OTNkNTRjMWQ5Y2Q0Y2YwOWNmZTE2NzRmYzU3NTMwM2NjOTE3MTllOTM3MWRkMzcyYTljMjVmNmQ0Y2MxOTUzODc0MDhhMTlkMDIxMzI2YzQzZDM2ZDE3MmQ3NjVkODk3OTVmYzljYTQyZDNmMTQ=",
"node-version": "22.12.0",
"npm-version": "11.0.0",
"os": "ubuntu-latest",
"sample": "mvn-no-client",
"sample-type": "jdl",
"samples-group": "samples",
},
{
"default-environment": "prod",
"java-version": "17",
"job-name": "mvn-oauth-angular",
"jwt-secret-key": "ZjY4MTM4YjI5YzMwZjhjYjI2OTNkNTRjMWQ5Y2Q0Y2YwOWNmZTE2NzRmYzU3NTMwM2NjOTE3MTllOTM3MWRkMzcyYTljMjVmNmQ0Y2MxOTUzODc0MDhhMTlkMDIxMzI2YzQzZDM2ZDE3MmQ3NjVkODk3OTVmYzljYTQyZDNmMTQ=",
"node-version": "22.12.0",
"npm-version": "11.0.0",
"os": "ubuntu-latest",
"sample": "mvn-oauth-angular",
"sample-type": "jdl",
"samples-group": "samples",
},
],
}
`;
7 changes: 7 additions & 0 deletions .blueprint/github-build-matrix/command.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ const command = {
cli: {
type: String,
},
scope: 'generator',
},
samplesGroup: {
description: 'Samples Group',
argument: {
type: String,
},
default: 'samples',
scope: 'generator',
},
Expand Down
21 changes: 14 additions & 7 deletions .blueprint/github-build-matrix/generator.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { join } from 'node:path';
import BaseGenerator from 'generator-jhipster/generators/base';
import { convertToGitHubMatrix, getGithubOutputFile, getGithubSamplesGroup, setGithubTaskOutput } from 'generator-jhipster/testing';

export default class extends BaseGenerator {
/** @type {string} */
samplesFolder;
/** @type {string} */
samplesGroup;
/** @type {object} */
matrix;

constructor(args, opts, features) {
super(args, opts, { ...features, queueCommandTasks: true, jhipsterBootstrap: false });
Expand All @@ -12,16 +17,18 @@ export default class extends BaseGenerator {
get [BaseGenerator.WRITING]() {
return this.asWritingTaskGroup({
async buildMatrix() {
const { samplesFolder } = this;
const { samples, warnings } = await getGithubSamplesGroup(this.templatePath('../../generate-sample/templates/'), samplesFolder);
const { samplesGroup = 'samples' } = this;
const templatePath = this.templatePath('../../generate-sample/templates/');
const samplesFolder = this.samplesFolder ? join(templatePath, this.samplesFolder) : templatePath;
const { samples, warnings } = await getGithubSamplesGroup(samplesFolder, samplesGroup);
if (warnings.length > 0) {
this.info(warnings.join('\n'));
this.log.info(warnings.join('\n'));
}
const matrix = JSON.stringify(convertToGitHubMatrix(samples));
const githubOutputFile = getGithubOutputFile(matrix);
this.log.info('matrix', matrix);
this.matrix = convertToGitHubMatrix(samples);
const githubOutputFile = getGithubOutputFile();
this.log.info('matrix', this.matrix);
if (githubOutputFile) {
setGithubTaskOutput('matrix', matrix);
setGithubTaskOutput('matrix', JSON.stringify(this.matrix));
}
},
});
Expand Down
24 changes: 24 additions & 0 deletions .blueprint/github-build-matrix/generator.spec.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { basename, dirname, join } from 'path';
import { fileURLToPath } from 'url';
import { beforeAll, describe, expect, it } from 'vitest';
import { getGithubSamplesGroups, defaultHelpers as helpers, runResult } from 'generator-jhipster/testing';

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

const generator = basename(__dirname);

describe(`generator - ${generator}`, async () => {
const groups = await getGithubSamplesGroups(join(__dirname, '../generate-sample/templates/'));
for (const workflow of groups.map(sample => sample.split('.')[0])) {
describe(`with ${workflow}`, () => {
beforeAll(async () => {
await helpers.runJHipster(join(__dirname, 'index.mjs'), { useEnvironmentBuilder: true }).withArguments(workflow);
});

it('should match matrix value', () => {
expect(runResult.generator.matrix).toMatchSnapshot();
});
});
}
});
Loading
Loading