diff --git a/generators/angular/generator.ts b/generators/angular/generator.ts index ddf2fdd3c917..d6ad1b473b28 100644 --- a/generators/angular/generator.ts +++ b/generators/angular/generator.ts @@ -88,13 +88,15 @@ export default class AngularGenerator extends BaseApplicationGenerator { get preparing() { return this.asPreparingTaskGroup({ - applicationDefauts({ applicationDefaults }) { + applicationDefauts({ application, applicationDefaults }) { applicationDefaults({ __override__: true, eslintConfigFile: app => `eslint.config.${app.packageJsonType === 'module' ? 'js' : 'mjs'}`, webappEnumerationsDir: app => `${app.clientSrcDir}app/entities/enumerations/`, angularLocaleId: app => app.nativeLanguageDefinition.angularLocale ?? defaultLanguage.angularLocale, }); + + application.addPrettierExtensions?.(['html', 'css', 'scss']); }, addNeedles({ source, application }) { source.addEntitiesToClient = param => { diff --git a/generators/app/__snapshots__/generator.spec.ts.snap b/generators/app/__snapshots__/generator.spec.ts.snap index 41fca92f6e23..75173630f55b 100644 --- a/generators/app/__snapshots__/generator.spec.ts.snap +++ b/generators/app/__snapshots__/generator.spec.ts.snap @@ -27,9 +27,9 @@ Options: --skip-jhipster-dependencies Don't write jhipster dependencies to package.json. --creation-timestamp Project creation timestamp (used for reproducible builds) --jdl-store JDL store - --skip-commit-hook Skip adding husky commit hooks --prettier-tab-width Default tab width for prettier --monorepository Use monorepository + --skip-commit-hook Skip adding husky commit hooks --db Provide DB name for the application when skipping server side generation --incremental-changelog Creates incremental database changelogs --skip-user-management Skip the user management module during app generation @@ -213,6 +213,7 @@ exports[`generator - app with default config should match snapshot 1`] = ` "SERVER_TEST_SRC_DIR": "src/test/java/", "TEST_DIR": "src/test/", "VUE": "vue", + "addPrettierExtensions": [Function], "addSpringMilestoneRepository": false, "angularLocaleId": "en", "anyEntityHasRelationshipWithUser": false, @@ -719,10 +720,13 @@ exports[`generator - app with default config should match snapshot 1`] = ` "packageName": "com.mycompany.myapp.web.rest.vm", }, ], + "packageJsonNodeEngine": undefined, + "packageJsonType": "commonjs", "packageName": "com.mycompany.myapp", "pages": [], "prettierConfigFile": ".prettierrc", - "prettierExtensions": "md,json,yml,html,cjs,mjs,js,ts,tsx,css,scss,java", + "prettierExtensions": "md,json,yml,js,cjs,mjs,ts,cts,mts,java,html,css,scss", + "prettierFolders": ",**/", "prettierJava": undefined, "prettierTabWidth": 2, "prodDatabaseDriver": { @@ -825,6 +829,7 @@ exports[`generator - app with gateway should match snapshot 1`] = ` "SERVER_TEST_SRC_DIR": "src/test/java/", "TEST_DIR": "src/test/", "VUE": "vue", + "addPrettierExtensions": [Function], "addSpringMilestoneRepository": false, "angularLocaleId": "en", "anyEntityHasRelationshipWithUser": false, @@ -1327,10 +1332,13 @@ exports[`generator - app with gateway should match snapshot 1`] = ` "packageName": "com.mycompany.myapp.web.rest.vm", }, ], + "packageJsonNodeEngine": undefined, + "packageJsonType": "commonjs", "packageName": "com.mycompany.myapp", "pages": [], "prettierConfigFile": ".prettierrc", - "prettierExtensions": "md,json,yml,html,cjs,mjs,js,ts,tsx,css,scss,java", + "prettierExtensions": "md,json,yml,js,cjs,mjs,ts,cts,mts,java,html,css,scss", + "prettierFolders": ",**/", "prettierJava": undefined, "prettierTabWidth": 2, "prodDatabaseDriver": { @@ -1435,6 +1443,7 @@ exports[`generator - app with microservice should match snapshot 1`] = ` "SERVER_TEST_SRC_DIR": "src/test/java/", "TEST_DIR": "src/test/", "VUE": "vue", + "addPrettierExtensions": [Function], "addSpringMilestoneRepository": false, "anyEntityHasRelationshipWithUser": false, "applicationType": "microservice", @@ -1831,6 +1840,8 @@ exports[`generator - app with microservice should match snapshot 1`] = ` }, "nodeDependencies": { "concurrently": "CONCURRENTLY_VERSION", + "eslint-config-prettier": "ESLINT_CONFIG_PRETTIER_VERSION", + "eslint-plugin-prettier": "ESLINT_PLUGIN_PRETTIER_VERSION", "husky": "HUSKY_VERSION", "lint-staged": "LINT_STAGED_VERSION", "npm": "NPM_VERSION", @@ -1880,10 +1891,13 @@ exports[`generator - app with microservice should match snapshot 1`] = ` "packageName": "com.mycompany.myapp.web.rest.vm", }, ], + "packageJsonNodeEngine": undefined, + "packageJsonType": "commonjs", "packageName": "com.mycompany.myapp", "pages": [], "prettierConfigFile": ".prettierrc", - "prettierExtensions": "md,json,yml,html,java", + "prettierExtensions": "md,json,yml,js,cjs,mjs,ts,cts,mts,java", + "prettierFolders": ",**/", "prettierJava": undefined, "prettierTabWidth": 2, "prodDatabaseDriver": { diff --git a/generators/bootstrap-application/generator.ts b/generators/bootstrap-application/generator.ts index a4d7be482dc4..d57707b27b1d 100644 --- a/generators/bootstrap-application/generator.ts +++ b/generators/bootstrap-application/generator.ts @@ -69,12 +69,6 @@ export default class BootstrapApplicationGenerator extends BaseApplicationGenera gatewayServicesApiAvailable: undefined, }); - applicationDefaults({ - useNpmWrapper: application => application.clientFrameworkAny && application.backendTypeJavaAny, - documentationArchiveUrl: ({ jhipsterVersion }) => - `${JHIPSTER_DOCUMENTATION_URL}${JHIPSTER_DOCUMENTATION_ARCHIVE_PATH}v${jhipsterVersion}`, - }); - let prettierExtensions = 'md,json,yml,html'; if (application.clientFrameworkAny) { prettierExtensions = `${prettierExtensions},cjs,mjs,js,ts,tsx,css,scss`; @@ -85,7 +79,14 @@ export default class BootstrapApplicationGenerator extends BaseApplicationGenera if (!application.skipServer) { prettierExtensions = `${prettierExtensions},java`; } - application.prettierExtensions = prettierExtensions; + + applicationDefaults({ + // TODO remove prettierExtensions, moved to prettier generator + prettierExtensions, + useNpmWrapper: application => application.clientFrameworkAny && application.backendTypeJavaAny, + documentationArchiveUrl: ({ jhipsterVersion }) => + `${JHIPSTER_DOCUMENTATION_URL}${JHIPSTER_DOCUMENTATION_ARCHIVE_PATH}v${jhipsterVersion}`, + }); }, }); } diff --git a/generators/common/__snapshots__/generator.spec.js.snap b/generators/common/__snapshots__/generator.spec.js.snap index fbf37e6dcf7f..61635a011280 100644 --- a/generators/common/__snapshots__/generator.spec.js.snap +++ b/generators/common/__snapshots__/generator.spec.js.snap @@ -30,17 +30,13 @@ trim_trailing_whitespace = false "stateCleared": "modified", }, ".husky/pre-commit": { - "contents": "#!/bin/sh -. "$(dirname "$0")/_/husky.sh" - - -"$(dirname "$0")/../npmw" exec --no-install lint-staged + "contents": "lint-staged ", "stateCleared": "modified", }, ".lintstagedrc.cjs": { "contents": "module.exports = { - '{,**/}*.{md,json,yml,html,cjs,mjs,js,ts,tsx,css,scss,java}': ['prettier --write'], + '{,**/}*.{md,json,yml,js,cjs,mjs,ts,cts,mts}': ['prettier --write'], }; ", "stateCleared": "modified", @@ -111,20 +107,27 @@ This application was generated using JHipster JHIPSTER_VERSION, you can find doc }, "package.json": { "contents": "{ - "config": { - "default_environment": "prod" - }, + "private": true, + "dependencies": {}, "devDependencies": { "generator-jhipster": "JHIPSTER_VERSION", - "husky": "HUSKY_VERSION", - "lint-staged": "LINT_STAGED_VERSION", "prettier": "PRETTIER_VERSION", "prettier-plugin-packagejson": "PRETTIER_PLUGIN_PACKAGEJSON_VERSION", - "prettier-plugin-java": "PRETTIER_PLUGIN_JAVA_VERSION" + "husky": "HUSKY_VERSION", + "lint-staged": "LINT_STAGED_VERSION" }, + "engines": {}, "scripts": { "prepare": "husky" - } + }, + "config": { + "default_environment": "prod" + }, + "name": "jhipster", + "version": "0.0.0", + "description": "Description for JHipster", + "license": "UNLICENSED", + "type": "commonjs" } ", "stateCleared": "modified", diff --git a/generators/common/command.ts b/generators/common/command.ts index ad3ac009f69a..ecec82f73785 100644 --- a/generators/common/command.ts +++ b/generators/common/command.ts @@ -20,13 +20,6 @@ import { JHipsterCommandDefinition } from '../base/api.js'; import { GENERATOR_BOOTSTRAP_APPLICATION_BASE } from '../generator-list.js'; const command: JHipsterCommandDefinition = { - options: { - skipCommitHook: { - description: 'Skip adding husky commit hooks', - type: Boolean, - scope: 'storage', - }, - }, configs: { defaultEnvironment: { description: 'Default environment for the application', @@ -40,7 +33,7 @@ const command: JHipsterCommandDefinition = { scope: 'storage', }, }, - import: [GENERATOR_BOOTSTRAP_APPLICATION_BASE, 'jhipster:javascript:prettier'], + import: [GENERATOR_BOOTSTRAP_APPLICATION_BASE, 'jhipster:javascript:prettier', 'jhipster:javascript:husky'], }; export default command; diff --git a/generators/common/files.js b/generators/common/files.js index 860040a65100..2faecc9ff2f9 100644 --- a/generators/common/files.js +++ b/generators/common/files.js @@ -32,12 +32,6 @@ export const commonFiles = { templates: ['sonar-project.properties'], }, ], - commitHooks: [ - { - condition: generator => !generator.skipCommitHook, - templates: ['.lintstagedrc.cjs', '.husky/pre-commit'], - }, - ], }; export function writeFiles() { diff --git a/generators/common/generator.js b/generators/common/generator.js index 8733e4100cba..32282865fb36 100644 --- a/generators/common/generator.js +++ b/generators/common/generator.js @@ -79,6 +79,9 @@ export default class CommonGenerator extends BaseApplicationGenerator { return this.asComposingTaskGroup({ async composing() { await this.composeWithJHipster('jhipster:javascript:prettier'); + if (!this.jhipsterConfig.skipCommitHook) { + await this.composeWithJHipster('jhipster:javascript:husky'); + } }, }); } @@ -225,27 +228,6 @@ export default class CommonGenerator extends BaseApplicationGenerator { }, }); }, - addCommitHookDependencies({ application }) { - if (application.skipCommitHook) return; - this.packageJson.merge({ - scripts: { - prepare: 'husky', - }, - devDependencies: { - husky: application.nodeDependencies.husky, - 'lint-staged': application.nodeDependencies['lint-staged'], - prettier: application.nodeDependencies.prettier, - 'prettier-plugin-packagejson': application.nodeDependencies['prettier-plugin-packagejson'], - }, - }); - if (application.backendTypeJavaAny) { - this.packageJson.merge({ - devDependencies: { - 'prettier-plugin-java': application.nodeDependencies['prettier-plugin-java'], - }, - }); - } - }, }); } diff --git a/generators/common/resources/package.json b/generators/common/resources/package.json index e5d4bff5d8a2..3a29190ba942 100644 --- a/generators/common/resources/package.json +++ b/generators/common/resources/package.json @@ -1,8 +1,6 @@ { "devDependencies": { "concurrently": "8.2.2", - "husky": "9.0.11", - "lint-staged": "15.2.7", "npm": "10.8.2", "wait-on": "7.2.0" } diff --git a/generators/common/templates/.husky/pre-commit.ejs b/generators/common/templates/.husky/pre-commit.ejs deleted file mode 100755 index 96421e83b237..000000000000 --- a/generators/common/templates/.husky/pre-commit.ejs +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh -. "$(dirname "$0")/_/husky.sh" - - -<%_ if (useNpmWrapper) { _%> -"$(dirname "$0")/../npmw" exec --no-install lint-staged -<%_ } else { _%> -npx --no-install lint-staged -<%_ } _%> diff --git a/generators/common/templates/.lintstagedrc.cjs.ejs b/generators/common/templates/.lintstagedrc.cjs.ejs deleted file mode 100644 index d87d1d08e925..000000000000 --- a/generators/common/templates/.lintstagedrc.cjs.ejs +++ /dev/null @@ -1,21 +0,0 @@ -<%# - 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. --%> -module.exports = { - '{,**/}*.{<%= prettierExtensions %>}': ['prettier --write'], -}; diff --git a/generators/java/generators/bootstrap/generator.ts b/generators/java/generators/bootstrap/generator.ts index ddacd234e4f8..43b4af3ff2eb 100644 --- a/generators/java/generators/bootstrap/generator.ts +++ b/generators/java/generators/bootstrap/generator.ts @@ -75,6 +75,9 @@ export default class BootstrapGenerator extends BaseApplicationGenerator { get preparing() { return this.asPreparingTaskGroup({ + applicationDefaults({ application }) { + application.addPrettierExtensions?.(['java']); + }, prepareJavaApplication({ application, source }) { source.hasJavaProperty = (property: string) => application.javaProperties![property] !== undefined; source.hasJavaManagedProperty = (property: string) => application.javaManagedProperties![property] !== undefined; diff --git a/generators/javascript/generators/bootstrap/__snapshots__/generator.spec.ts.snap b/generators/javascript/generators/bootstrap/__snapshots__/generator.spec.ts.snap index 498e89996569..0e42ad79e019 100644 --- a/generators/javascript/generators/bootstrap/__snapshots__/generator.spec.ts.snap +++ b/generators/javascript/generators/bootstrap/__snapshots__/generator.spec.ts.snap @@ -9,17 +9,17 @@ exports[`generator - javascript:bootstrap customVersion-commonjs should match fi }, "package.json": { "contents": "{ - "name": "dasherizedBaseName", - "version": "0.0.0", - "description": "projectDescription", "private": true, - "license": "UNLICENSED", "dependencies": {}, "devDependencies": {}, "engines": { "node": "customVersion" }, "scripts": {}, + "name": "dasherizedBaseName", + "version": "0.0.0", + "description": "projectDescription", + "license": "UNLICENSED", "type": "commonjs" } ", @@ -37,15 +37,15 @@ exports[`generator - javascript:bootstrap packageJsonNodeEngine(false)-module sh }, "package.json": { "contents": "{ - "name": "dasherizedBaseName", - "version": "0.0.0", - "description": "projectDescription", "private": true, - "license": "UNLICENSED", "dependencies": {}, "devDependencies": {}, "engines": {}, "scripts": {}, + "name": "dasherizedBaseName", + "version": "0.0.0", + "description": "projectDescription", + "license": "UNLICENSED", "type": "module" } ", @@ -63,17 +63,17 @@ exports[`generator - javascript:bootstrap packageJsonNodeEngine(true) should mat }, "package.json": { "contents": "{ - "name": "dasherizedBaseName", - "version": "0.0.0", - "description": "projectDescription", "private": true, - "license": "UNLICENSED", "dependencies": {}, "devDependencies": {}, "engines": { "node": "^18.19.0 || >= 20.6.1" }, "scripts": {}, + "name": "dasherizedBaseName", + "version": "0.0.0", + "description": "projectDescription", + "license": "UNLICENSED", "type": "commonjs" } ", diff --git a/generators/javascript/generators/bootstrap/generator.ts b/generators/javascript/generators/bootstrap/generator.ts index 3c6066554771..770a25f06449 100644 --- a/generators/javascript/generators/bootstrap/generator.ts +++ b/generators/javascript/generators/bootstrap/generator.ts @@ -68,15 +68,20 @@ export default class BootstrapGenerator extends BaseApplicationGenerator { get postWriting() { return this.asPostWritingTaskGroup({ addPrettierDependencies({ application }) { - const { packageJsonNodeEngine, packageJsonType } = application; + const { packageJsonNodeEngine, packageJsonType, dasherizedBaseName, projectDescription } = application; + this.packageJson.defaults({ + name: dasherizedBaseName, + version: '0.0.0', + description: projectDescription, + license: 'UNLICENSED', + }); if (packageJsonType) { this.packageJson.merge({ type: packageJsonType }); } if (packageJsonNodeEngine) { - this.packageJson.merge({ - engines: { - node: typeof packageJsonNodeEngine === 'string' ? packageJsonNodeEngine : packageJson.engines.node, - }, + this.packageJson.set('engines', { + ...(this.packageJson.get('engines') ?? {}), + node: typeof packageJsonNodeEngine === 'string' ? packageJsonNodeEngine : packageJson.engines.node, }); } }, diff --git a/generators/javascript/generators/bootstrap/templates/package.json.ejs b/generators/javascript/generators/bootstrap/templates/package.json.ejs index f39db40aca7d..3bd2d4152ac0 100644 --- a/generators/javascript/generators/bootstrap/templates/package.json.ejs +++ b/generators/javascript/generators/bootstrap/templates/package.json.ejs @@ -17,11 +17,7 @@ limitations under the License. -%> { - "name": "<%= dasherizedBaseName %>", - "version": "0.0.0", - "description": "<%= projectDescription %>", "private": true, - "license": "UNLICENSED", "dependencies": {}, "devDependencies": {}, "engines": {}, diff --git a/generators/javascript/generators/husky/__snapshots__/generator.spec.ts.snap b/generators/javascript/generators/husky/__snapshots__/generator.spec.ts.snap index 81c4151375dd..82daa45ae1eb 100644 --- a/generators/javascript/generators/husky/__snapshots__/generator.spec.ts.snap +++ b/generators/javascript/generators/husky/__snapshots__/generator.spec.ts.snap @@ -5,15 +5,13 @@ exports[`generator - javascript:husky skipCommitHook(false) should call source s exports[`generator - javascript:husky skipCommitHook(false) should match files snapshot 1`] = ` { ".husky/pre-commit": { - "contents": "#!/bin/sh -. "$(dirname "$0")/_/husky.sh" - -npx --no-install lint-staged", + "contents": "lint-staged +", "stateCleared": "modified", }, ".lintstagedrc.cjs": { "contents": "module.exports = { - '{,src/**/,webpack/}*.{md,json,yml,html,js,ts,tsx,css,scss,vue,java}': ['prettier --write'], + '{PRETTIER_FOLDERS}*.{PRETTIER_EXTENSIONS}': ['prettier --write'], }; ", "stateCleared": "modified", diff --git a/generators/javascript/generators/husky/generator.spec.ts b/generators/javascript/generators/husky/generator.spec.ts index 770e6cc1e377..6e8615121907 100644 --- a/generators/javascript/generators/husky/generator.spec.ts +++ b/generators/javascript/generators/husky/generator.spec.ts @@ -41,7 +41,7 @@ describe(`generator - ${generator}`, () => { .withMockedJHipsterGenerators() .withMockedSource() .withMockedNodeDependencies() - .withSharedApplication({}) + .withSharedApplication({ prettierExtensions: 'PRETTIER_EXTENSIONS', prettierFolders: 'PRETTIER_FOLDERS' }) .withJHipsterConfig(config); }); @@ -54,7 +54,7 @@ describe(`generator - ${generator}`, () => { }); it('should compose with generators', () => { - expect(result.composedMockedGenerators).toMatchObject(expect.arrayContaining(['jhipster:javascript:bootstrap'])); + expect(result.composedMockedGenerators).toMatchObject(['jhipster:javascript:prettier'] as any); }); }); } diff --git a/generators/javascript/generators/husky/generator.ts b/generators/javascript/generators/husky/generator.ts index c1055a723ff2..f751c7b713f5 100644 --- a/generators/javascript/generators/husky/generator.ts +++ b/generators/javascript/generators/husky/generator.ts @@ -29,7 +29,7 @@ export default class HuskyGenerator extends BaseApplicationGenerator { } if (!this.delegateToBlueprint) { - await this.dependsOnJHipster('jhipster:javascript:bootstrap'); + await this.dependsOnJHipster('jhipster:javascript:prettier'); } } diff --git a/generators/javascript/generators/husky/templates/.husky/pre-commit.ejs b/generators/javascript/generators/husky/templates/.husky/pre-commit.ejs index c70c608e786c..c27d8893a994 100755 --- a/generators/javascript/generators/husky/templates/.husky/pre-commit.ejs +++ b/generators/javascript/generators/husky/templates/.husky/pre-commit.ejs @@ -1,4 +1 @@ -#!/bin/sh -. "$(dirname "$0")/_/husky.sh" - -npx --no-install lint-staged \ No newline at end of file +lint-staged diff --git a/generators/javascript/generators/husky/templates/.lintstagedrc.cjs.ejs b/generators/javascript/generators/husky/templates/.lintstagedrc.cjs.ejs index 4ae14f966d2e..31cc54366c92 100644 --- a/generators/javascript/generators/husky/templates/.lintstagedrc.cjs.ejs +++ b/generators/javascript/generators/husky/templates/.lintstagedrc.cjs.ejs @@ -17,5 +17,5 @@ limitations under the License. -%> module.exports = { - '{,src/**/,webpack/}*.{md,json,yml,html,js,ts,tsx,css,scss,vue,java}': ['prettier --write'], + '{<%= prettierFolders %>}*.{<%= prettierExtensions %>}': ['prettier --write'], }; diff --git a/generators/javascript/generators/prettier/__snapshots__/generator.spec.ts.snap b/generators/javascript/generators/prettier/__snapshots__/generator.spec.ts.snap index abc19a26cb1d..b4c3a4fd5c86 100644 --- a/generators/javascript/generators/prettier/__snapshots__/generator.spec.ts.snap +++ b/generators/javascript/generators/prettier/__snapshots__/generator.spec.ts.snap @@ -1,5 +1,11 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`generator - javascript:prettier fromInit(false) should compose with generators 1`] = ` +[ + "jhipster:javascript:bootstrap", +] +`; + exports[`generator - javascript:prettier fromInit(false) should match files snapshot 1`] = ` { ".prettierignore": { @@ -37,6 +43,12 @@ plugins: } `; +exports[`generator - javascript:prettier fromInit(true) should compose with generators 1`] = ` +[ + "jhipster:javascript:bootstrap", +] +`; + exports[`generator - javascript:prettier fromInit(true) should match files snapshot 1`] = ` { ".prettierignore": { @@ -78,6 +90,12 @@ plugins: } `; +exports[`generator - javascript:prettier monorepository(true)-monorepositoryRoot(false) should compose with generators 1`] = ` +[ + "jhipster:javascript:bootstrap", +] +`; + exports[`generator - javascript:prettier monorepository(true)-monorepositoryRoot(false) should match files snapshot 1`] = ` { ".prettierignore": { @@ -115,6 +133,12 @@ plugins: } `; +exports[`generator - javascript:prettier monorepository(true)-monorepositoryRoot(true) should compose with generators 1`] = ` +[ + "jhipster:javascript:bootstrap", +] +`; + exports[`generator - javascript:prettier monorepository(true)-monorepositoryRoot(true) should match files snapshot 1`] = ` { ".prettierignore": { diff --git a/generators/javascript/generators/prettier/generator.spec.ts b/generators/javascript/generators/prettier/generator.spec.ts index a24d503fda95..314d8625b2d2 100644 --- a/generators/javascript/generators/prettier/generator.spec.ts +++ b/generators/javascript/generators/prettier/generator.spec.ts @@ -52,7 +52,7 @@ describe(`generator - ${generator}`, () => { }); it('should compose with generators', () => { - expect(result.composedMockedGenerators).toMatchInlineSnapshot('[]'); + expect(result.composedMockedGenerators).toMatchSnapshot(); }); }); }); diff --git a/generators/javascript/generators/prettier/generator.ts b/generators/javascript/generators/prettier/generator.ts index 04533140e2b1..4fda149c7507 100644 --- a/generators/javascript/generators/prettier/generator.ts +++ b/generators/javascript/generators/prettier/generator.ts @@ -33,13 +33,16 @@ export default class PrettierGenerator extends BaseApplicationGenerator { await this.composeWithBlueprints(); } - if (!this.delegateToBlueprint && !this.options.fromInit) { - await this.dependsOnBootstrapApplication(); + if (!this.delegateToBlueprint) { + if (!this.options.fromInit) { + await this.dependsOnBootstrapApplication(); + } + await this.dependsOnJHipster('jhipster:javascript:bootstrap'); } } - get preparing() { - return this.asPreparingTaskGroup({ + get loading() { + return this.asLoadingTaskGroup({ loadNodeDependencies({ application }) { this.loadNodeDependencies(application.nodeDependencies, { prettier: packageJson.dependencies.prettier, @@ -47,6 +50,29 @@ export default class PrettierGenerator extends BaseApplicationGenerator { 'prettier-plugin-packagejson': packageJson.dependencies['prettier-plugin-packagejson'], }); }, + loadDefaults({ application, applicationDefaults }) { + applicationDefaults({ + prettierFolders: ',**/', + prettierExtensions: 'md,json,yml,js,cjs,mjs,ts,cts,mts', + }); + + application.addPrettierExtensions = (extensions: string[]) => { + const currentExtensions = application.prettierExtensions!.split(','); + const extensionsToAdd = extensions.filter(ext => !currentExtensions.includes(ext)); + if (extensionsToAdd.length > 0) { + application.prettierExtensions = `${application.prettierExtensions},${extensionsToAdd.join(',')}`; + } + }; + }, + }); + } + + get [BaseApplicationGenerator.LOADING]() { + return this.delegateTasksToBlueprint(() => this.loading); + } + + get preparing() { + return this.asPreparingTaskGroup({ source({ source }) { source.mergePrettierConfig = config => this.mergeDestinationYaml(this.prettierConfigFile, config); // `.prettierignore` file is only supported in the root of a project refer to https://github.com/prettier/prettier/issues/4081. diff --git a/generators/javascript/resources/package.json b/generators/javascript/resources/package.json index 48b53a677e1c..138f05e8826b 100644 --- a/generators/javascript/resources/package.json +++ b/generators/javascript/resources/package.json @@ -2,7 +2,7 @@ "dependencies": { "eslint-config-prettier": "9.1.0", "eslint-plugin-prettier": "5.2.1", - "husky": "9.0.11", + "husky": "9.1.1", "lint-staged": "15.2.7" } } diff --git a/generators/javascript/types.d.ts b/generators/javascript/types.d.ts index 5af8355d8a83..e93b90796c66 100644 --- a/generators/javascript/types.d.ts +++ b/generators/javascript/types.d.ts @@ -7,4 +7,6 @@ export type JavaScriptApplication = { packageJsonNodeEngine?: boolean | string; packageJsonType?: string; eslintConfigFile?: string; + + addPrettierExtensions?: (extensions: string[]) => void; }; diff --git a/generators/jdl/__snapshots__/generator.spec.ts.snap b/generators/jdl/__snapshots__/generator.spec.ts.snap index 68fe9f049134..491f271792a8 100644 --- a/generators/jdl/__snapshots__/generator.spec.ts.snap +++ b/generators/jdl/__snapshots__/generator.spec.ts.snap @@ -190,8 +190,8 @@ Options: --skip-jhipster-dependencies Don't write jhipster dependencies to package.json. --creation-timestamp Project creation timestamp (used for reproducible builds) --jdl-store JDL store - --skip-commit-hook Skip adding husky commit hooks --prettier-tab-width Default tab width for prettier + --skip-commit-hook Skip adding husky commit hooks --db Provide DB name for the application when skipping server side generation --incremental-changelog Creates incremental database changelogs --recreate-initial-changelog Recreate the initial database changelog based on the current config diff --git a/generators/react/generator.js b/generators/react/generator.js index 91d809b41142..55d93cbea4f9 100644 --- a/generators/react/generator.js +++ b/generators/react/generator.js @@ -90,7 +90,9 @@ export default class ReactGenerator extends BaseApplicationGenerator { get preparing() { return this.asPreparingTaskGroup({ - applicationDefauts({ applicationDefaults }) { + applicationDefauts({ application, applicationDefaults }) { + application.addPrettierExtensions?.(['html', 'tsx', 'css', 'scss']); + applicationDefaults({ __override__: true, eslintConfigFile: app => `eslint.config.${app.packageJsonType === 'module' ? 'js' : 'mjs'}`, diff --git a/generators/vue/generator.js b/generators/vue/generator.js index d2e78e361225..ac51200f40f0 100644 --- a/generators/vue/generator.js +++ b/generators/vue/generator.js @@ -71,6 +71,8 @@ export default class VueGenerator extends BaseApplicationGenerator { get preparing() { return this.asPreparingTaskGroup({ prepareForTemplates({ application, source }) { + application.addPrettierExtensions?.(['html', 'vue', 'css', 'scss']); + application.clientWebappDir = `${application.clientSrcDir}app/`; application.webappEnumerationsDir = `${application.clientWebappDir}shared/model/enumerations/`; application.clientSpecDir = `${application.clientTestDir}spec/`;