Skip to content

Commit

Permalink
add version compare structure
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed May 7, 2024
1 parent 562ec73 commit 4c709cd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"extends": ["eslint:recommended", "plugin:prettier/recommended"],
"parserOptions": {
"ecmaVersion": 11,
"ecmaVersion": 13,
"sourceType": "module"
},
"overrides": [
Expand Down
27 changes: 24 additions & 3 deletions generators/server/generator.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { readFile } from 'node:fs/promises';
import { fileURLToPath } from 'node:url';
import { extname } from 'node:path';
import { passthrough } from '@yeoman/transform';
import { isFileStateDeleted, isFileStateModified } from 'mem-fs-editor/state';
import ServerGenerator from 'generator-jhipster/generators/server';
import ServerGenerator from 'generator-jhipster/generators/base-application';
import { javaMainPackageTemplatesBlock, addJavaAnnotation } from 'generator-jhipster/generators/java/support';
import { lt as semverLessThan } from 'semver';

import { NATIVE_BUILDTOOLS_VERSION } from '../../lib/constants.js';
import { mavenDefinition } from './support/index.js';

export default class extends ServerGenerator {
blueprintVersion;

constructor(args, opts, features) {
super(args, opts, { ...features, checkBlueprint: true, sbsBlueprint: true });
}
Expand All @@ -16,6 +21,16 @@ export default class extends ServerGenerator {
await this.dependsOnJHipster('bootstrap-application');
}

get [ServerGenerator.CONFIGURING]() {
return this.asConfiguringTaskGroup({
async setVersion() {
this.blueprintVersion = this.blueprintStorage.get('version');
const { version } = JSON.parse(await readFile(fileURLToPath(new URL('../../package.json', import.meta.url)), 'utf8'));
this.blueprintStorage.set('version', version);
},
});
}

get [ServerGenerator.DEFAULT]() {
return this.asDefaultTaskGroup({
// workaround for https://github.com/spring-projects/spring-boot/issues/32195
Expand Down Expand Up @@ -45,8 +60,10 @@ export default class extends ServerGenerator {

get [ServerGenerator.WRITING]() {
return this.asWritingTaskGroup({
async writingTemplateTask({ application }) {
this.removeFile('src/main/resources/META-INF/native-image/liquibase/resource-config.json');
async writingTemplateTask({ application, control }) {
if (control.existingProject && (this.blueprintVersion === undefined || this.isBlueprintVersionLessThan('2.0.1'))) {
this.removeFile('src/main/resources/META-INF/native-image/liquibase/resource-config.json');
}

await this.writeFiles({
sections: {
Expand Down Expand Up @@ -319,4 +336,8 @@ import org.springframework.security.oauth2.core.oidc.user.OidcUser;`,
},
};
}

isBlueprintVersionLessThan(version) {
return this.blueprintVersion ? semverLessThan(this.blueprintVersion, version) : false;
}
}

0 comments on commit 4c709cd

Please sign in to comment.