Skip to content

Commit

Permalink
adjusts for blueprints (#27874)
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima authored Nov 14, 2024
1 parent 9074303 commit 76ac496
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 38 deletions.
1 change: 1 addition & 0 deletions generators/angular/resources/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@angular-builders/custom-webpack": "18.0.0",
"@angular-builders/jest": "18.0.0",
"@angular/cli": "18.2.11",
"@eslint/js": "9.14.0",
"@types/jest": "29.5.14",
"@types/node": "20.11.25",
"@types/sockjs-client": "1.5.4",
Expand Down
1 change: 1 addition & 0 deletions generators/angular/templates/package.json.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"@angular-builders/custom-webpack": "<%= nodeDependencies['@angular-builders/custom-webpack'] %>",
"@angular-builders/jest": "<%= nodeDependencies['@angular-builders/jest'] %>",
"@angular-devkit/build-angular": "<%= nodeDependencies['@angular/cli'] %>",
"@eslint/js": null,
"@types/jest": "<%= nodeDependencies['@types/jest'] %>",
"@types/node": "<%= nodeDependencies['@types/node'] %>",
"angular-eslint": "<%= nodeDependencies['angular-eslint'] %>",
Expand Down
2 changes: 2 additions & 0 deletions generators/app/__snapshots__/generator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ exports[`generator - app with default config should match snapshot 1`] = `
"@angular/cli": "ANGULAR_CLI_VERSION",
"@angular/common": "ANGULAR_COMMON_VERSION",
"@cypress/code-coverage": "CYPRESS_CODE_COVERAGE_VERSION",
"@eslint/js": "ESLINT_JS_VERSION",
"@fortawesome/angular-fontawesome": "FORTAWESOME_ANGULAR_FONTAWESOME_VERSION",
"@fortawesome/fontawesome-svg-core": "FORTAWESOME_FONTAWESOME_SVG_CORE_VERSION",
"@fortawesome/free-solid-svg-icons": "FORTAWESOME_FREE_SOLID_SVG_ICONS_VERSION",
Expand Down Expand Up @@ -1291,6 +1292,7 @@ exports[`generator - app with gateway should match snapshot 1`] = `
"@angular/cli": "ANGULAR_CLI_VERSION",
"@angular/common": "ANGULAR_COMMON_VERSION",
"@cypress/code-coverage": "CYPRESS_CODE_COVERAGE_VERSION",
"@eslint/js": "ESLINT_JS_VERSION",
"@fortawesome/angular-fontawesome": "FORTAWESOME_ANGULAR_FONTAWESOME_VERSION",
"@fortawesome/fontawesome-svg-core": "FORTAWESOME_FONTAWESOME_SVG_CORE_VERSION",
"@fortawesome/free-solid-svg-icons": "FORTAWESOME_FREE_SOLID_SVG_ICONS_VERSION",
Expand Down
42 changes: 21 additions & 21 deletions generators/common/templates/sonar-project.properties.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -37,45 +37,45 @@ sonar.javascript.lcov.reportPaths=<%_ if (buildToolMaven) { _%>target<%_ } else
sonar.sourceEncoding=UTF-8
sonar.exclusions=<%= clientSrcDir %>content/**/*.*, <%= clientSrcDir %>i18n/*.js, <%= clientDistDir %>**/*.*
<%_ if (!skipServer) { _%>
<%_ if (!skipServer && backendTypeJavaAny) { _%>
sonar.issue.ignore.multicriteria=\
<%_ if (backendTypeSpringBoot) { _%>
<%_ if (backendTypeSpringBoot) { _%>
S6437,\
<%_ } _%>
<%_ if (cacheProviderAny) { _%>
<%_ } _%>
<%_ if (cacheProviderAny) { _%>
S1192,\
<%_ } _%>
<%_ if (backendTypeSpringBoot) { _%>
<%_ } _%>
<%_ if (backendTypeSpringBoot) { _%>
S125,\
<%_ } _%>
<%_ if (gatlingTests) { _%>
<%_ } _%>
<%_ if (gatlingTests) { _%>
S2187,\
<%_ } _%>
<%_ } _%>
S3437,\
<%_ if (authenticationTypeJwt) { _%>
<%_ if (authenticationTypeJwt) { _%>
S4502,\
<%_ } _%>
<%_ } _%>
S4684,S5145,S7027-domain,S7027-dto,UndocumentedApi
<%_ if (backendTypeSpringBoot) { _%>
<%_ if (backendTypeSpringBoot) { _%>
# Rule https://rules.sonarsource.com/java/RSPEC-6437 is ignored, hardcoded passwords are provided for development purposes
sonar.issue.ignore.multicriteria.S6437.resourceKey=<%= srcMainResources %>config/*
sonar.issue.ignore.multicriteria.S6437.ruleKey=java:S6437
<%_ } _%>
<%_ if (gatlingTests) { _%>
<%_ } _%>
<%_ if (gatlingTests) { _%>
# Rule https://rules.sonarsource.com/java/RSPEC-2187 is ignored, gatling tests are not supported by sonar
sonar.issue.ignore.multicriteria.S2187.resourceKey= <%- srcTestJava %>gatling/**/*
sonar.issue.ignore.multicriteria.S2187.ruleKey=java:S2187
<%_ } _%>
<%_ } _%>
# Rule https://rules.sonarsource.com/java/RSPEC-3437 is ignored, as a JPA-managed field cannot be transient
sonar.issue.ignore.multicriteria.S3437.resourceKey= <%- srcMainJava %>**/*
sonar.issue.ignore.multicriteria.S3437.ruleKey=squid:S3437
<%_ if (authenticationTypeJwt) { _%>
<%_ if (authenticationTypeJwt) { _%>
# Rule https://rules.sonarsource.com/java/RSPEC-4502 is ignored, as for JWT tokens we are not subject to CSRF attack
sonar.issue.ignore.multicriteria.S4502.resourceKey= <%- srcMainJava %>**/*
sonar.issue.ignore.multicriteria.S4502.ruleKey=java:S4502
<%_ } _%>
<%_ } _%>
# Rule https://rules.sonarsource.com/java/RSPEC-4684
sonar.issue.ignore.multicriteria.S4684.resourceKey= <%- srcMainJava %>**/*
sonar.issue.ignore.multicriteria.S4684.ruleKey=java:S4684
Expand All @@ -91,14 +91,14 @@ sonar.issue.ignore.multicriteria.S7027-dto.ruleKey = javaarchitecture:S7027
# Rule https://rules.sonarsource.com/java/RSPEC-1176 is ignored, as we want to follow "clean code" guidelines and classes, methods and arguments names should be self-explanatory
sonar.issue.ignore.multicriteria.UndocumentedApi.resourceKey= <%- srcMainJava %>**/*
sonar.issue.ignore.multicriteria.UndocumentedApi.ruleKey=squid:UndocumentedApi
<%_ } _%>
<%_ if (cacheProviderAny) { _%>
<%_ if (cacheProviderAny) { _%>
# Rule https://rules.sonarsource.com/java/RSPEC-1192
sonar.issue.ignore.multicriteria.S1192.resourceKey = src/main/java/**/CacheConfiguration.java
sonar.issue.ignore.multicriteria.S1192.ruleKey = java:S1192
<%_ } _%>
<%_ if (backendTypeSpringBoot) { _%>
<%_ } _%>
<%_ if (backendTypeSpringBoot) { _%>
# Rule https://rules.sonarsource.com/xml/RSPEC-125
sonar.issue.ignore.multicriteria.S125.resourceKey = src/main/resources/logback-spring.xml
sonar.issue.ignore.multicriteria.S125.ruleKey = xml:S125
<%_ } _%>
<%_ } _%>
8 changes: 8 additions & 0 deletions generators/generate-blueprint/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ const command = {
},
scope: 'storage',
},
gitDependency: {
cli: {
description: 'Use git dependency',
type: String,
},
default: 'github:jhipster/generator-jhipster#main',
scope: 'generator',
},
cliName: {
cli: {
description: 'CLI name',
Expand Down
3 changes: 2 additions & 1 deletion generators/generate-blueprint/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export default class extends BaseGenerator {
recreatePackageLock!: boolean;
skipWorkflows!: boolean;
ignoreExistingGenerators!: boolean;
gitDependency!: string;

async _beforeQueue() {
if (!this.fromBlueprint) {
Expand Down Expand Up @@ -371,7 +372,7 @@ export default class extends BaseGenerator {
});
} else {
this.packageJson.merge({
dependencies: exactDependency,
dependencies: this.gitDependency ? { 'generator-jhipster': this.gitDependency } : exactDependency,
engines: this.jhipsterConfig.caret ? caretDependency : exactDependency,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@ import BaseGenerator from 'generator-jhipster/generators/base';
import { getGithubSamplesGroup } from 'generator-jhipster/testing';

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

constructor(args, opts, features) {
super(args, opts, { ...features, queueCommandTasks: true, jhipsterBootstrap: false });
Expand All @@ -19,17 +28,29 @@ export default class extends BaseGenerator {
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 } = samples[sampleName];
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 = `${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 +60,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 +86,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,
};
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
name: Verify Sample Projects
concurrency:
# Group PRs by head_ref, push to main branch by commit id, and others branch by ref.
group: ${{ github.workflow }}-${{ github.head_ref || (github.ref == 'refs/heads/main' && github.sha) || github.ref }}
cancel-in-progress: true
on:
push:
branches:
Expand All @@ -11,6 +15,8 @@ on:
- '*'
permissions:
contents: read
env:
FORCE_COLOR: 2
jobs:
build-matrix:
runs-on: ubuntu-latest
Expand All @@ -27,7 +33,7 @@ jobs:
./cli/cli.cjs github-build-matrix
samples:
name: ${{ matrix.job-name || matrix.sample }}
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
needs: build-matrix
defaults:
run:
Expand Down
4 changes: 2 additions & 2 deletions generators/git/templates/.gitignore.jhi.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ Desktop.ini
######################
# Code coverage
######################
/coverage/
/.nyc_output/
coverage/
.nyc_output/

<&- fragments.render({ join: '\n\n' }) &>

0 comments on commit 76ac496

Please sign in to comment.