From 76ac496c9e45d77e499ecf71a58115a86e5baf2e Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Thu, 14 Nov 2024 05:37:01 -0300 Subject: [PATCH] adjusts for blueprints (#27874) --- generators/angular/resources/package.json | 1 + generators/angular/templates/package.json.ejs | 1 + .../app/__snapshots__/generator.spec.ts.snap | 2 + .../templates/sonar-project.properties.ejs | 42 ++++++------- generators/generate-blueprint/command.ts | 8 +++ generators/generate-blueprint/generator.ts | 3 +- .../generate-sample/generator.mjs.ejs | 63 +++++++++++++++---- .../.github/workflows/samples.yml.ejs | 8 ++- generators/git/templates/.gitignore.jhi.ejs | 4 +- 9 files changed, 94 insertions(+), 38 deletions(-) diff --git a/generators/angular/resources/package.json b/generators/angular/resources/package.json index 5709ab937dc3..c86a69ba3edf 100644 --- a/generators/angular/resources/package.json +++ b/generators/angular/resources/package.json @@ -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", diff --git a/generators/angular/templates/package.json.ejs b/generators/angular/templates/package.json.ejs index 67c3126555a2..b17015881b73 100644 --- a/generators/angular/templates/package.json.ejs +++ b/generators/angular/templates/package.json.ejs @@ -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'] %>", diff --git a/generators/app/__snapshots__/generator.spec.ts.snap b/generators/app/__snapshots__/generator.spec.ts.snap index c7c22ba1c389..ff074562258a 100644 --- a/generators/app/__snapshots__/generator.spec.ts.snap +++ b/generators/app/__snapshots__/generator.spec.ts.snap @@ -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", @@ -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", diff --git a/generators/common/templates/sonar-project.properties.ejs b/generators/common/templates/sonar-project.properties.ejs index 8fa2d6e2de06..15c50ec87543 100644 --- a/generators/common/templates/sonar-project.properties.ejs +++ b/generators/common/templates/sonar-project.properties.ejs @@ -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 @@ -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 + <%_ } _%> <%_ } _%> diff --git a/generators/generate-blueprint/command.ts b/generators/generate-blueprint/command.ts index b8da8262b1f5..294914a1666d 100644 --- a/generators/generate-blueprint/command.ts +++ b/generators/generate-blueprint/command.ts @@ -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', diff --git a/generators/generate-blueprint/generator.ts b/generators/generate-blueprint/generator.ts index 21445229117e..152500595f57 100644 --- a/generators/generate-blueprint/generator.ts +++ b/generators/generate-blueprint/generator.ts @@ -57,6 +57,7 @@ export default class extends BaseGenerator { recreatePackageLock!: boolean; skipWorkflows!: boolean; ignoreExistingGenerators!: boolean; + gitDependency!: string; async _beforeQueue() { if (!this.fromBlueprint) { @@ -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, }); } diff --git a/generators/generate-blueprint/templates/.blueprint/generate-sample/generator.mjs.ejs b/generators/generate-blueprint/templates/.blueprint/generate-sample/generator.mjs.ejs index da6cbf2f124e..148dd5f88dbb 100644 --- a/generators/generate-blueprint/templates/.blueprint/generate-sample/generator.mjs.ejs +++ b/generators/generate-blueprint/templates/.blueprint/generate-sample/generator.mjs.ejs @@ -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 }); @@ -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 }, }); } } @@ -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 }), }, }); @@ -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, + }; + } } diff --git a/generators/generate-blueprint/templates/.github/workflows/samples.yml.ejs b/generators/generate-blueprint/templates/.github/workflows/samples.yml.ejs index dd093e749e4d..e263eed5aa8d 100644 --- a/generators/generate-blueprint/templates/.github/workflows/samples.yml.ejs +++ b/generators/generate-blueprint/templates/.github/workflows/samples.yml.ejs @@ -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: @@ -11,6 +15,8 @@ on: - '*' permissions: contents: read +env: + FORCE_COLOR: 2 jobs: build-matrix: runs-on: ubuntu-latest @@ -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: diff --git a/generators/git/templates/.gitignore.jhi.ejs b/generators/git/templates/.gitignore.jhi.ejs index 7a412246ff75..467351e9270e 100644 --- a/generators/git/templates/.gitignore.jhi.ejs +++ b/generators/git/templates/.gitignore.jhi.ejs @@ -149,7 +149,7 @@ Desktop.ini ###################### # Code coverage ###################### -/coverage/ -/.nyc_output/ +coverage/ +.nyc_output/ <&- fragments.render({ join: '\n\n' }) &>