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

upgrade to generator-jhipster v8 #383

Merged
merged 32 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9a52160
update samples
mshima Jun 18, 2024
22d9c0f
update jdl samples
mshima Jun 18, 2024
1af5c2c
migrate v8 config
mshima Jun 18, 2024
39d9d9c
revert ng-gradle-fr
mshima Jun 18, 2024
829ad83
revert document entities samples
mshima Jun 18, 2024
0b10ddf
workflow adjusts
mshima Jun 18, 2024
0651e44
move samples to generate-samples templates
mshima Jun 18, 2024
54904bc
rework logo
mshima Jun 13, 2024
ee65cd0
convert to esm
mshima Jun 18, 2024
694ea64
workflow adjusts.
mshima Jun 18, 2024
6d0881b
cleanup
mshima Jun 18, 2024
8ff5797
adjusts
mshima Jun 18, 2024
ef0c85f
adjust couchbase
mshima Jun 19, 2024
6cb9049
update eslint config
mshima Jun 19, 2024
dfbcc35
adjusts
mshima Jun 19, 2024
95f1f05
drop couchbase from ci matrix
mshima Jun 19, 2024
03a830c
update to generator-jhipster main
mshima Jun 19, 2024
4ae2fbc
pass ignoreNeedlesError to tests
mshima Jun 20, 2024
6240fe3
cleanup tests
mshima Jun 20, 2024
561c23b
rename eslint.config to js
mshima Jun 21, 2024
f75b64c
update generator-jhipster snapshot
mshima Jun 21, 2024
44b7745
adjusts for generator-jhipster api changes
mshima Jun 21, 2024
4a568c9
add matrix test
mshima Jun 19, 2024
716b98a
update to final v8.6.0
mshima Jun 25, 2024
2280fc4
use mergeMavenPomContent
mshima Jun 25, 2024
7cbfbed
revert samples names to ngx
mshima Jun 25, 2024
d2cef93
adjusts to templates
mshima Jul 22, 2024
78fe10b
disable ktlint failures
mshima Jul 22, 2024
c20a6ec
don't fail on detekt error
mshima Jul 22, 2024
6004cdd
downgrade elasticsearch
mshima Jul 22, 2024
062658a
dto mapper adjusts.
mshima Jul 22, 2024
f815bf9
adjusts to generate-sample
mshima Jul 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export { default } from './index.js';

const defaultCommands = {
'generate-sample': {
desc: 'Generate a test sample',
blueprint: '@jhipster/jhipster-dev',
},
};

export default defaultCommands;
157 changes: 157 additions & 0 deletions .blueprint/generate-sample/command.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
/**
* 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.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { existsSync, readdirSync } from 'node:fs';
import { getSamples } from './get-samples.mjs';
import { entitiesByType, workflowSamples } from './support/index.mjs';

const updateSampleName = sample =>
sample.replace('ngx', 'ng').replace('ms-ng-eureka-oauth2-mongodb-caffeine', 'ms-ng-oauth2-mongodb-caffeine');

const revertSampleName = sample =>
sample.replace('ng-', 'ngx-').replace('ms-ng-oauth2-mongodb-caffeine', 'ms-ng-eureka-oauth2-mongodb-caffeine');

/**
* @type {import('generator-jhipster').JHipsterCommandDefinition}
*/
const command = {
arguments: {
sampleName: {
type: String,
},
},
configs: {
sampleName: {
prompt: gen => ({
when: !gen.all && existsSync(gen.templatePath(gen.samplesFolder)),
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,
},
configure: gen => {
if (gen.all) {
gen.generatorArgs = readdirSync(this.templatePath('samples'));
}
},
scope: 'generator',
},
samplesFolder: {
description: 'Path to the samples folder',
cli: {
type: String,
},
default: 'samples',
scope: 'generator',
},
entrypointGenerator: {
description: 'The generator to use as the entrypoint',
cli: {
type: String,
},
default: 'jdl',
scope: 'generator',
},
appSample: {
description: 'Sample name to generate',
cli: {
type: String,
env: 'JHI_APP',
},
configure: gen => {
if (gen.appSample && gen.appSample !== 'jdl') {
gen.appSample = revertSampleName(gen.appSample);

let { appSample } = gen;
appSample = workflowSamples[appSample]?.['app-sample'] ?? appSample;
gen.samplesFolder = `json-samples/${updateSampleName(appSample)}`;
gen.entrypointGenerator = 'app';
}
},
scope: 'generator',
},
jdlSamples: {
description: 'Generate JDL samples',
cli: {
type: String,
env: 'JHI_JDL_APP',
},
configure: gen => {
if (gen.jdlSamples) {
const [app, ...entities] = gen.jdlSamples.split(',');
gen.samplesFolder = `jdl-samples/${updateSampleName(app)}`;
gen.generatorArgs = '*.jdl';
if (entities && entities.length > 0) {
gen.supportingSamples.push(...entities.map(entity => `${entity}.jdl`));
}
}
},
scope: 'generator',
},
entityType: {
description: 'Entity type to generate',
cli: {
env: 'JHI_ENTITY',
type: String,
},
configure: gen => {
let { entityType } = gen;
if (!entityType && gen.appSample) {
entityType = workflowSamples[gen.appSample]?.entity;
}
if (entityType && entityType !== 'none') {
gen.supportingSamples.push(...entitiesByType[entityType].map(entity => `.jhipster/${entity}.json`));
}
},
choices: [...Object.keys(entitiesByType), 'none'],
scope: 'generator',
},
jdlEntities: {
description: 'Generate JDL entities samples',
cli: {
type: String,
env: 'JHI_JDL_ENTITY',
},
configure: gen => {
let { jdlEntities } = gen;
if (!jdlEntities && gen.appSample) {
jdlEntities = workflowSamples[gen.appSample]?.['jdl-entity'];
}
if (jdlEntities) {
const entities = jdlEntities.split(',');
gen.generatorArgs = '*.jdl';
gen.entrypointGenerator = 'jdl';
if (entities && entities.length > 0) {
gen.supportingSamples.push(...entities.map(entity => `${entity}.jdl`));
}
}
},
scope: 'generator',
},
},
options: {},
import: ['app', 'workspaces'],
};

export default command;
105 changes: 105 additions & 0 deletions .blueprint/generate-sample/generator.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { readdir } from 'node:fs/promises';
import { readFileSync } from 'node:fs';
import BaseGenerator from 'generator-jhipster/generators/base';

export default class extends BaseGenerator {
sampleName;
all;
samplesFolder;
entrypointGenerator;
generatorArgs;
appSample;
entityType;
jdlSamples;
supportingSamples = [];

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

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

get [BaseGenerator.PROMPTING]() {
return this.asPromptingTaskGroup({
async askForSample() {
await this.promptCurrentJHipsterCommand();
},
});
}

get [BaseGenerator.CONFIGURING]() {
return this.asConfiguringTaskGroup({
async configureCommand() {
await this.configureCurrentJHipsterCommandConfig();
},
});
}

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

get [BaseGenerator.WRITING]() {
return this.asWritingTaskGroup({
async copySample() {
if (this.all) {
this.log.info(`Copying all samples from ${this.samplesFolder}`);
this.copyTemplate(`${this.samplesFolder}/*.jdl`, '');
} else if (this.sampleName) {
this.log.info(`Copying sample from ${this.samplesFolder}/${this.sampleName}`);
this.copyTemplate(`${this.samplesFolder}/${this.sampleName}`, this.sampleName, { noGlob: true });
} else {
this.log.info(`Copying all files from ${this.samplesFolder}`);
this.copyTemplate('*', '', { fromBasePath: this.templatePath(this.samplesFolder), globOptions: { dot: true } });
}
},
async copySupportingSamples() {
const { supportingSamples } = this;
if (supportingSamples && supportingSamples.length > 0) {
this.log.info(`Copying support samples ${supportingSamples}`);
this.copyTemplate(supportingSamples, '', {
fromBasePath: this.templatePath('supporting-samples'),
globOptions: { dot: true },
});
}
},
});
}

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`;

if (this.generatorArgs === '*.jdl') {
this.generatorArgs = (await readdir(this.destinationPath())).filter(file => file.endsWith('.jdl'));
}
await this.composeWithJHipster(this.entrypointGenerator, {
generatorArgs: this.generatorArgs ?? [this.sampleName],
generatorOptions: {
skipJhipsterDependencies: true,
insight: false,
skipChecks: true,
projectVersion,
ignoreApplication: false,
...(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'));
};
2 changes: 2 additions & 0 deletions .blueprint/generate-sample/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default } from './generator.mjs';
export { default as command } from './command.mjs';
103 changes: 103 additions & 0 deletions .blueprint/generate-sample/support/entities-by-type.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
const sqllight = ['BankAccount', 'Label', 'Operation'];

const document = [
'DocumentBankAccount',
'EmbeddedOperation',
'Place',
'Division',

'FieldTestEntity',
'FieldTestMapstructAndServiceClassEntity',
'FieldTestServiceClassAndJpaFilteringEntity',
'FieldTestServiceImplEntity',
'FieldTestInfiniteScrollEntity',
'FieldTestPaginationEntity',

'EntityWithDTO',
'EntityWithPaginationAndDTO',
'EntityWithServiceClassAndPagination',
'EntityWithServiceClassPaginationAndDTO',
'EntityWithServiceImplAndDTO',
'EntityWithServiceImplAndPagination',
'EntityWithServiceImplPaginationAndDTO',
];

const sql = [
...sqllight,

'FieldTestEntity',
'FieldTestMapstructAndServiceClassEntity',
'FieldTestServiceClassAndJpaFilteringEntity',
'FieldTestServiceImplEntity',
'FieldTestInfiniteScrollEntity',
'FieldTestPaginationEntity',
'FieldTestEnumWithValue',

'EntityWithDTO',
'EntityWithPaginationAndDTO',
'EntityWithServiceClassAndPagination',
'EntityWithServiceClassPaginationAndDTO',
'EntityWithServiceImplAndDTO',
'EntityWithServiceImplAndPagination',
'EntityWithServiceImplPaginationAndDTO',

'MapsIdUserProfileWithDTO',
];

export const entitiesByType = {
document,
mongodb: document,
couchbase: document,
neo4j: ['Album', 'Track', 'Genre', 'Artist'],
cassandra: [
'CassBankAccount',

'FieldTestEntity',
'FieldTestServiceImplEntity',
'FieldTestMapstructAndServiceClassEntity',
'FieldTestPaginationEntity',
],
micro: [
'MicroserviceBankAccount',
'MicroserviceOperation',
'MicroserviceLabel',

'FieldTestEntity',
'FieldTestMapstructAndServiceClassEntity',
'FieldTestServiceClassAndJpaFilteringEntity',
'FieldTestServiceImplEntity',
'FieldTestInfiniteScrollEntity',
'FieldTestPaginationEntity',
],
sqllight,
sql,
sqlfull: [
...sql,
'Place',
'Division',

'TestEntity',
'TestMapstruct',
'TestServiceClass',
'TestServiceImpl',
'TestInfiniteScroll',
'TestPagination',
'TestManyToOne',
'TestManyToMany',
'TestManyRelPaginDTO',
'TestOneToOne',
'TestCustomTableName',
'TestTwoRelationshipsSameEntity',
'SuperMegaLargeTestEntity',

'MapsIdParentEntityWithoutDTO',
'MapsIdChildEntityWithoutDTO',
'MapsIdGrandchildEntityWithoutDTO',
'MapsIdParentEntityWithDTO',
'MapsIdChildEntityWithDTO',
'MapsIdGrandchildEntityWithDTO',

'JpaFilteringRelationship',
'JpaFilteringOtherSide',
],
};
2 changes: 2 additions & 0 deletions .blueprint/generate-sample/support/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './entities-by-type.mjs';
export * from './workflow-samples.mjs';
Loading
Loading