diff --git a/generators/angular/__snapshots__/generator.spec.ts.snap b/generators/angular/__snapshots__/generator.spec.ts.snap index 6ccf39207182..2c1bbfa618ed 100644 --- a/generators/angular/__snapshots__/generator.spec.ts.snap +++ b/generators/angular/__snapshots__/generator.spec.ts.snap @@ -680,6 +680,23 @@ exports[`generator - angular gateway-jwt-skipUserManagement(true)-withAdminUi(fa } `; +exports[`generator - angular gateway-jwt-skipUserManagement(true)-withAdminUi(false)-skipJhipsterDependencies(false)-enableTranslation(false)-clientRoot/-websocket(true) should match source calls snapshot 1`] = ` +{ + "addEntitiesToClient": [ + { + "application": "Application[jhipster]", + "control": "TaskParameter[control]", + "entities": [ + "Entity[Simple]", + "Entity[Microservice]", + "Entity[EntityWithCustomId]", + ], + "source": "TaskParameter[source]", + }, + ], +} +`; + exports[`generator - angular gateway-oauth2-withAdminUi(true)-skipJhipsterDependencies(true)-enableTranslation(true)-clientRoot/-websocket(true) should match generated files snapshot 1`] = ` { ".jhipster/EntityWithCustomId.json": { @@ -1582,6 +1599,24 @@ exports[`generator - angular gateway-oauth2-withAdminUi(true)-skipJhipsterDepend } `; +exports[`generator - angular gateway-oauth2-withAdminUi(true)-skipJhipsterDependencies(true)-enableTranslation(true)-clientRoot/-websocket(true) should match source calls snapshot 1`] = ` +{ + "addEntitiesToClient": [ + { + "application": "Application[jhipster]", + "control": "TaskParameter[control]", + "entities": [ + "Entity[Authority]", + "Entity[Simple]", + "Entity[Microservice]", + "Entity[EntityWithCustomId]", + ], + "source": "TaskParameter[source]", + }, + ], +} +`; + exports[`generator - angular microservice-jwt-skipUserManagement(false)-withAdminUi(false)-skipJhipsterDependencies(false)-enableTranslation(false)-clientRoot/-websocket(false) should match generated files snapshot 1`] = ` { ".jhipster/EntityWithCustomId.json": { @@ -2241,6 +2276,28 @@ exports[`generator - angular microservice-jwt-skipUserManagement(false)-withAdmi } `; +exports[`generator - angular microservice-jwt-skipUserManagement(false)-withAdminUi(false)-skipJhipsterDependencies(false)-enableTranslation(false)-clientRoot/-websocket(false) should match source calls snapshot 1`] = ` +{ + "addEntitiesToClient": [ + { + "application": "Application[jhipster]", + "control": "TaskParameter[control]", + "entities": [ + "Entity[Simple]", + "Entity[Microservice]", + "Entity[EntityWithCustomId]", + ], + "source": "TaskParameter[source]", + }, + ], + "addWebpackConfig": [ + { + "config": "targetOptions.target === 'serve' ? {} : require('./webpack.microfrontend')(config, options, targetOptions)", + }, + ], +} +`; + exports[`generator - angular microservice-oauth2-withAdminUi(true)-skipJhipsterDependencies(true)-enableTranslation(true)--websocket(false) should match generated files snapshot 1`] = ` { ".jhipster/EntityWithCustomId.json": { @@ -2909,6 +2966,28 @@ exports[`generator - angular microservice-oauth2-withAdminUi(true)-skipJhipsterD } `; +exports[`generator - angular microservice-oauth2-withAdminUi(true)-skipJhipsterDependencies(true)-enableTranslation(true)--websocket(false) should match source calls snapshot 1`] = ` +{ + "addEntitiesToClient": [ + { + "application": "Application[jhipster]", + "control": "TaskParameter[control]", + "entities": [ + "Entity[Simple]", + "Entity[Microservice]", + "Entity[EntityWithCustomId]", + ], + "source": "TaskParameter[source]", + }, + ], + "addWebpackConfig": [ + { + "config": "targetOptions.target === 'serve' ? {} : require('./webpack.microfrontend')(config, options, targetOptions)", + }, + ], +} +`; + exports[`generator - angular monolith-jwt-skipUserManagement(false)-withAdminUi(true)-skipJhipsterDependencies(true)-enableTranslation(true)--websocket(true) should match generated files snapshot 1`] = ` { ".jhipster/EntityWithCustomId.json": { @@ -3982,6 +4061,24 @@ exports[`generator - angular monolith-jwt-skipUserManagement(false)-withAdminUi( } `; +exports[`generator - angular monolith-jwt-skipUserManagement(false)-withAdminUi(true)-skipJhipsterDependencies(true)-enableTranslation(true)--websocket(true) should match source calls snapshot 1`] = ` +{ + "addEntitiesToClient": [ + { + "application": "Application[jhipster]", + "control": "TaskParameter[control]", + "entities": [ + "Entity[Authority]", + "Entity[Simple]", + "Entity[Microservice]", + "Entity[EntityWithCustomId]", + ], + "source": "TaskParameter[source]", + }, + ], +} +`; + exports[`generator - angular monolith-oauth2-withAdminUi(false)-skipJhipsterDependencies(false)-enableTranslation(false)-websocket(false) should match generated files snapshot 1`] = ` { ".jhipster/EntityWithCustomId.json": { @@ -4635,6 +4732,23 @@ exports[`generator - angular monolith-oauth2-withAdminUi(false)-skipJhipsterDepe } `; +exports[`generator - angular monolith-oauth2-withAdminUi(false)-skipJhipsterDependencies(false)-enableTranslation(false)-websocket(false) should match source calls snapshot 1`] = ` +{ + "addEntitiesToClient": [ + { + "application": "Application[jhipster]", + "control": "TaskParameter[control]", + "entities": [ + "Entity[Simple]", + "Entity[Microservice]", + "Entity[EntityWithCustomId]", + ], + "source": "TaskParameter[source]", + }, + ], +} +`; + exports[`generator - angular monolith-session-skipUserManagement(true)-withAdminUi(false)-skipJhipsterDependencies(false)-enableTranslation(false)-websocket(true) should match generated files snapshot 1`] = ` { ".jhipster/EntityWithCustomId.json": { @@ -5297,6 +5411,23 @@ exports[`generator - angular monolith-session-skipUserManagement(true)-withAdmin } `; +exports[`generator - angular monolith-session-skipUserManagement(true)-withAdminUi(false)-skipJhipsterDependencies(false)-enableTranslation(false)-websocket(true) should match source calls snapshot 1`] = ` +{ + "addEntitiesToClient": [ + { + "application": "Application[jhipster]", + "control": "TaskParameter[control]", + "entities": [ + "Entity[Simple]", + "Entity[Microservice]", + "Entity[EntityWithCustomId]", + ], + "source": "TaskParameter[source]", + }, + ], +} +`; + exports[`generator - angular samples matrix should match snapshot 1`] = ` { "gateway-jwt-skipUserManagement(true)-withAdminUi(false)-skipJhipsterDependencies(false)-enableTranslation(false)-clientRoot/-websocket(true)": { diff --git a/generators/angular/generator.spec.ts b/generators/angular/generator.spec.ts index fbbd9b06fcef..c5c7d5483e96 100644 --- a/generators/angular/generator.spec.ts +++ b/generators/angular/generator.spec.ts @@ -91,12 +91,16 @@ describe(`generator - ${clientFramework}`, () => { .withJHipsterConfig(sampleConfig, entities) .withSharedApplication({ gatewayServicesApiAvailable: sampleConfig.applicationType === 'gateway' }) .withControl({ getWebappTranslation: () => 'translations' }) + .withMockedSource() .withMockedGenerators(['jhipster:common', 'jhipster:languages']); }); it('should match generated files snapshot', () => { expect(runResult.getStateSnapshot()).toMatchSnapshot(); }); + it('should match source calls snapshot', () => { + expect(runResult.sourceCallsArg).toMatchSnapshot(); + }); it('contains correct clientFramework', () => { runResult.assertFileContent('.yo-rc.json', new RegExp(`"clientFramework": "${clientFramework}"`)); }); diff --git a/generators/angular/generator.ts b/generators/angular/generator.ts index 5e8cd9047611..5d9dbe57bf41 100644 --- a/generators/angular/generator.ts +++ b/generators/angular/generator.ts @@ -262,14 +262,14 @@ export default class AngularGenerator extends BaseApplicationGenerator { get postWriting() { return this.asPostWritingTaskGroup({ - addWebsocketDependencies({ application }) { + addWebsocketDependencies({ application, source }) { const { authenticationTypeSession, communicationSpringWebsocket, nodeDependencies } = application; const dependencies = {}; if (communicationSpringWebsocket) { if (authenticationTypeSession) { dependencies['ngx-cookie-service'] = nodeDependencies['ngx-cookie-service']; } - this.packageJson.merge({ + source.mergeClientPackageJson!({ dependencies: { 'sockjs-client': nodeDependencies['sockjs-client'], '@stomp/rx-stomp': nodeDependencies['@stomp/rx-stomp'], diff --git a/generators/angular/templates/package.json.ejs b/generators/angular/templates/package.json.ejs index e18b8ae8aa3c..67c3126555a2 100644 --- a/generators/angular/templates/package.json.ejs +++ b/generators/angular/templates/package.json.ejs @@ -118,8 +118,6 @@ "default_environment": "prod" }, "scripts": { - "prettier:check": "prettier --check \"{,src/**/,webpack/,.blueprint/**/}*.{<%= prettierExtensions %>}\"", - "prettier:format": "prettier --write \"{,src/**/,webpack/,.blueprint/**/}*.{<%= prettierExtensions %>}\"", "lint": "eslint .", "lint:fix": "<%= clientPackageManager %> run lint -- --fix", "cleanup": "rimraf <%= this.relativeDir(clientRootDir, temporaryDir) %>", diff --git a/generators/app/__snapshots__/generator.spec.ts.snap b/generators/app/__snapshots__/generator.spec.ts.snap index 867d70e540b0..c7c22ba1c389 100644 --- a/generators/app/__snapshots__/generator.spec.ts.snap +++ b/generators/app/__snapshots__/generator.spec.ts.snap @@ -268,6 +268,7 @@ exports[`generator - app with default config should match snapshot 1`] = ` "clientFrameworkNo": false, "clientFrameworkReact": false, "clientFrameworkVue": false, + "clientPackageJsonScripts": {}, "clientPackageManager": "npm", "clientRootDir": "", "clientSrcDir": "src/main/webapp/", @@ -921,6 +922,7 @@ exports[`generator - app with gateway should match snapshot 1`] = ` "clientFrameworkNo": false, "clientFrameworkReact": false, "clientFrameworkVue": false, + "clientPackageJsonScripts": {}, "clientPackageManager": "npm", "clientRootDir": "", "clientSrcDir": "src/main/webapp/", @@ -1569,6 +1571,7 @@ exports[`generator - app with microservice should match snapshot 1`] = ` "clientFrameworkNo": true, "clientFrameworkReact": false, "clientFrameworkVue": false, + "clientPackageJsonScripts": {}, "clientPackageManager": "npm", "clientRootDir": "", "clientSrcDir": "src/main/webapp/", @@ -2078,6 +2081,7 @@ exports[`generator - app with microservice should match snapshot 1`] = ` "testJavaDir": "src/test/java/", "testJavaPackageDir": "src/test/java/com/mycompany/myapp/", "testResourceDir": "src/test/resources/", + "typescriptEslint": undefined, "upperFirstCamelCaseBaseName": "Jhipster", "useNpmWrapper": false, "websocket": "no", diff --git a/generators/bootstrap-application-base/generator.ts b/generators/bootstrap-application-base/generator.ts index 35f3ec66c46f..7d00ff2ac619 100644 --- a/generators/bootstrap-application-base/generator.ts +++ b/generators/bootstrap-application-base/generator.ts @@ -127,6 +127,7 @@ export default class BootstrapApplicationBase extends BaseApplicationGenerator { backendType: this.jhipsterConfig.backendType ?? 'Java', syncUserWithIdp: this.jhipsterConfig.syncUserWithIdp, packageJsonScripts: {}, + clientPackageJsonScripts: {}, }); }, loadNodeDependencies({ application }) { diff --git a/generators/common/__snapshots__/generator.spec.ts.snap b/generators/common/__snapshots__/generator.spec.ts.snap index 3df1e24246db..cc1cf3e3084b 100644 --- a/generators/common/__snapshots__/generator.spec.ts.snap +++ b/generators/common/__snapshots__/generator.spec.ts.snap @@ -115,6 +115,8 @@ This application was generated using JHipster JHIPSTER_VERSION, you can find doc }, "engines": {}, "scripts": { + "prettier:check": "prettier --check \\"{,src/**/,webpack/,.blueprint/**/}*.{md,json,yml,js,cjs,mjs,ts,cts,mts}\\"", + "prettier:format": "prettier --write \\"{,src/**/,webpack/,.blueprint/**/}*.{md,json,yml,js,cjs,mjs,ts,cts,mts}\\"", "prepare": "husky" }, "config": { diff --git a/generators/javascript/generators/bootstrap/generator.ts b/generators/javascript/generators/bootstrap/generator.ts index 1520c327fd8d..d26b5b66eb92 100644 --- a/generators/javascript/generators/bootstrap/generator.ts +++ b/generators/javascript/generators/bootstrap/generator.ts @@ -52,6 +52,20 @@ export default class BootstrapGenerator extends BaseApplicationGenerator { return this.delegateTasksToBlueprint(() => this.loading); } + get preparing() { + return this.asPreparingTaskGroup({ + addSource({ application, source }) { + source.mergeClientPackageJson = args => { + this.mergeDestinationJson(`${application.clientRootDir}package.json`, args); + }; + }, + }); + } + + get [BaseApplicationGenerator.PREPARING]() { + return this.delegateTasksToBlueprint(() => this.preparing); + } + get writing() { return this.asWritingTaskGroup({ async writing({ application }) { @@ -69,18 +83,29 @@ export default class BootstrapGenerator extends BaseApplicationGenerator { get postWriting() { return this.asPostWritingTaskGroup({ - addPrettierDependencies({ application }) { - const { packageJsonNodeEngine, packageJsonType, dasherizedBaseName, projectDescription, packageJsonScripts } = application; + mergePackageJson({ application, source }) { + const { + packageJsonNodeEngine, + packageJsonType, + dasherizedBaseName, + projectDescription, + packageJsonScripts, + clientPackageJsonScripts, + } = application; + this.packageJson.merge({ scripts: packageJsonScripts! }); + this.packageJson.defaults({ name: dasherizedBaseName, version: '0.0.0', description: projectDescription, license: 'UNLICENSED', }); + if (packageJsonType === 'module') { this.packageJson.merge({ type: packageJsonType }); } + if (packageJsonNodeEngine) { const packageJsonEngines: any = this.packageJson.get('engines') ?? {}; this.packageJson.set('engines', { @@ -88,6 +113,10 @@ export default class BootstrapGenerator extends BaseApplicationGenerator { node: typeof packageJsonNodeEngine === 'string' ? packageJsonNodeEngine : packageJson.engines.node, }); } + + if (clientPackageJsonScripts && Object.keys(clientPackageJsonScripts).length > 0) { + source.mergeClientPackageJson!({ scripts: clientPackageJsonScripts }); + } }, }); } diff --git a/generators/javascript/generators/eslint/command.ts b/generators/javascript/generators/eslint/command.ts index 99f9a064ba35..14dd3b0b58a2 100644 --- a/generators/javascript/generators/eslint/command.ts +++ b/generators/javascript/generators/eslint/command.ts @@ -18,15 +18,17 @@ */ import type { JHipsterCommandDefinition } from '../../../../lib/command/index.js'; -const command: JHipsterCommandDefinition = { +const command = { configs: { typescriptEslint: { cli: { type: Boolean, + hide: true, }, + scope: 'storage', }, }, import: [], -}; +} as const satisfies JHipsterCommandDefinition; export default command; diff --git a/generators/javascript/generators/prettier/__snapshots__/generator.spec.ts.snap b/generators/javascript/generators/prettier/__snapshots__/generator.spec.ts.snap index 8dd7e7b2e9e3..6f1ec69f2edb 100644 --- a/generators/javascript/generators/prettier/__snapshots__/generator.spec.ts.snap +++ b/generators/javascript/generators/prettier/__snapshots__/generator.spec.ts.snap @@ -36,6 +36,10 @@ plugins: "devDependencies": { "prettier": "PRETTIER_VERSION", "prettier-plugin-packagejson": "PRETTIER_PLUGIN_PACKAGEJSON_VERSION" + }, + "scripts": { + "prettier:check": "prettier --check \\"{,src/**/,webpack/,.blueprint/**/}*.{md,json,yml,js,cjs,mjs,ts,cts,mts}\\"", + "prettier:format": "prettier --write \\"{,src/**/,webpack/,.blueprint/**/}*.{md,json,yml,js,cjs,mjs,ts,cts,mts}\\"" } } ", @@ -171,6 +175,10 @@ plugins: "devDependencies": { "prettier": "PRETTIER_VERSION", "prettier-plugin-packagejson": "PRETTIER_PLUGIN_PACKAGEJSON_VERSION" + }, + "scripts": { + "prettier:check": "prettier --check \\"{,src/**/,webpack/,.blueprint/**/}*.{md,json,yml,js,cjs,mjs,ts,cts,mts}\\"", + "prettier:format": "prettier --write \\"{,src/**/,webpack/,.blueprint/**/}*.{md,json,yml,js,cjs,mjs,ts,cts,mts}\\"" } } ", diff --git a/generators/javascript/generators/prettier/generator.ts b/generators/javascript/generators/prettier/generator.ts index 4fda149c7507..62c11cd8b367 100644 --- a/generators/javascript/generators/prettier/generator.ts +++ b/generators/javascript/generators/prettier/generator.ts @@ -107,12 +107,14 @@ export default class PrettierGenerator extends BaseApplicationGenerator { get postWriting() { return this.asPostWritingTaskGroup({ addPrettierDependencies({ application }) { + const { clientBundlerWebpack, clientFrameworkBuiltIn, clientFrameworkNo, monorepository, nodeDependencies, prettierExtensions } = + application; this.packageJson.merge({ devDependencies: { - prettier: application.nodeDependencies.prettier, + prettier: nodeDependencies.prettier, }, }); - if (application.monorepository && !this.monorepositoryRoot) return; + if (monorepository && !this.monorepositoryRoot) return; if (this.fromInit) { this.packageJson.merge({ @@ -121,6 +123,14 @@ export default class PrettierGenerator extends BaseApplicationGenerator { 'prettier-format': 'prettier --write "{,**/}*.{md,json,yml,html,cjs,mjs,js,cts,mts,ts,tsx,css,scss,vue,java}"', }, }); + } else if (clientFrameworkBuiltIn || clientFrameworkNo) { + const folders = ['', 'src/**/', ...(clientBundlerWebpack ? ['webpack/'] : []), '.blueprint/**/']; + this.packageJson.merge({ + scripts: { + 'prettier:check': `prettier --check "{${folders.join(',')}}*.{${prettierExtensions}}"`, + 'prettier:format': `prettier --write "{${folders.join(',')}}*.{${prettierExtensions}}"`, + }, + }); } }, addPrettierPackagejson({ application, source }) { diff --git a/generators/javascript/types.d.ts b/generators/javascript/types.d.ts index fab53b454aaa..852ba6de0738 100644 --- a/generators/javascript/types.d.ts +++ b/generators/javascript/types.d.ts @@ -1,7 +1,10 @@ +/* eslint-disable @typescript-eslint/consistent-type-imports */ +import type { Merge, PackageJson, Simplify } from 'type-fest'; import type { ExportApplicationPropertiesFromCommand } from '../../lib/command/types.js'; -import type JavascriptBootstrapCommand from './generators/bootstrap/command.ts'; +import type JavascriptBootstrapCommand from './generators/bootstrap/command.js'; type JavascriptBootstrapProperties = ExportApplicationPropertiesFromCommand; +type DependencyValue = string | undefined | null; export type JavaScriptSourceType = { mergePrettierConfig?: (config: Record) => void; @@ -9,14 +12,25 @@ export type JavaScriptSourceType = { addEslintIgnore?: (opts: { ignorePattern: string }) => void; addEslintConfig?: (opts: { import?: string | string[]; config?: string | string[] }) => void; + + /** Merge data to client's package.json */ + mergeClientPackageJson?( + args: Simplify< + Merge; devDependencies?: Record }> + >, + ): void; }; -export type JavaScriptApplication = JavascriptBootstrapProperties & { - packageJsonNodeEngine?: boolean | string; - eslintConfigFile?: string; - cjsExtension?: string; - mjsExtension?: string; - packageJsonScripts: Record; +export type JavaScriptApplication = JavascriptBootstrapProperties & + ExportApplicationPropertiesFromCommand & { + packageJsonNodeEngine?: boolean | string; + eslintConfigFile?: string; + cjsExtension?: string; + mjsExtension?: string; + /** Root package.json scripts */ + packageJsonScripts: Record; + /** Root package.json scripts */ + clientPackageJsonScripts: Record; - addPrettierExtensions?: (extensions: string[]) => void; -}; + addPrettierExtensions?: (extensions: string[]) => void; + }; diff --git a/generators/react/__snapshots__/generator.spec.ts.snap b/generators/react/__snapshots__/generator.spec.ts.snap index a887e1339736..db52728e6510 100644 --- a/generators/react/__snapshots__/generator.spec.ts.snap +++ b/generators/react/__snapshots__/generator.spec.ts.snap @@ -422,6 +422,8 @@ exports[`generator - react gateway-jwt-skipUserManagement(true)-withAdminUi(fals } `; +exports[`generator - react gateway-jwt-skipUserManagement(true)-withAdminUi(false)-skipJhipsterDependencies(false)-enableTranslation(false)-clientRoot/-websocket(true) should match source calls snapshot 1`] = `{}`; + exports[`generator - react gateway-oauth2-withAdminUi(true)-skipJhipsterDependencies(true)-enableTranslation(true)-clientRoot/-websocket(true) should match generated files snapshot 1`] = ` { ".jhipster/EntityWithCustomId.json": { @@ -877,6 +879,8 @@ exports[`generator - react gateway-oauth2-withAdminUi(true)-skipJhipsterDependen } `; +exports[`generator - react gateway-oauth2-withAdminUi(true)-skipJhipsterDependencies(true)-enableTranslation(true)-clientRoot/-websocket(true) should match source calls snapshot 1`] = `{}`; + exports[`generator - react microservice-jwt-skipUserManagement(false)-withAdminUi(false)-skipJhipsterDependencies(false)-enableTranslation(false)-clientRoot/-websocket(false) should match generated files snapshot 1`] = ` { ".jhipster/EntityWithCustomId.json": { @@ -1305,6 +1309,23 @@ exports[`generator - react microservice-jwt-skipUserManagement(false)-withAdminU } `; +exports[`generator - react microservice-jwt-skipUserManagement(false)-withAdminUi(false)-skipJhipsterDependencies(false)-enableTranslation(false)-clientRoot/-websocket(false) should match source calls snapshot 1`] = ` +{ + "addWebpackConfig": [ + { + "config": "require('./webpack.microfrontend')({ serve: options.env.WEBPACK_SERVE })", + }, + ], + "mergeClientPackageJson": [ + { + "devDependencies": { + "@module-federation/enhanced": null, + }, + }, + ], +} +`; + exports[`generator - react microservice-oauth2-withAdminUi(true)-skipJhipsterDependencies(true)-enableTranslation(true)--websocket(false) should match generated files snapshot 1`] = ` { ".jhipster/EntityWithCustomId.json": { @@ -1748,6 +1769,23 @@ exports[`generator - react microservice-oauth2-withAdminUi(true)-skipJhipsterDep } `; +exports[`generator - react microservice-oauth2-withAdminUi(true)-skipJhipsterDependencies(true)-enableTranslation(true)--websocket(false) should match source calls snapshot 1`] = ` +{ + "addWebpackConfig": [ + { + "config": "require('./webpack.microfrontend')({ serve: options.env.WEBPACK_SERVE })", + }, + ], + "mergeClientPackageJson": [ + { + "devDependencies": { + "@module-federation/enhanced": null, + }, + }, + ], +} +`; + exports[`generator - react monolith-jwt-skipUserManagement(false)-withAdminUi(true)-skipJhipsterDependencies(true)-enableTranslation(true)--websocket(true) should match generated files snapshot 1`] = ` { ".jhipster/EntityWithCustomId.json": { @@ -2260,6 +2298,8 @@ exports[`generator - react monolith-jwt-skipUserManagement(false)-withAdminUi(tr } `; +exports[`generator - react monolith-jwt-skipUserManagement(false)-withAdminUi(true)-skipJhipsterDependencies(true)-enableTranslation(true)--websocket(true) should match source calls snapshot 1`] = `{}`; + exports[`generator - react monolith-oauth2-withAdminUi(false)-skipJhipsterDependencies(false)-enableTranslation(false)-websocket(false) should match generated files snapshot 1`] = ` { ".jhipster/EntityWithCustomId.json": { @@ -2682,6 +2722,8 @@ exports[`generator - react monolith-oauth2-withAdminUi(false)-skipJhipsterDepend } `; +exports[`generator - react monolith-oauth2-withAdminUi(false)-skipJhipsterDependencies(false)-enableTranslation(false)-websocket(false) should match source calls snapshot 1`] = `{}`; + exports[`generator - react monolith-session-skipUserManagement(true)-withAdminUi(false)-skipJhipsterDependencies(false)-enableTranslation(false)-websocket(true) should match generated files snapshot 1`] = ` { ".jhipster/EntityWithCustomId.json": { @@ -3098,6 +3140,8 @@ exports[`generator - react monolith-session-skipUserManagement(true)-withAdminUi } `; +exports[`generator - react monolith-session-skipUserManagement(true)-withAdminUi(false)-skipJhipsterDependencies(false)-enableTranslation(false)-websocket(true) should match source calls snapshot 1`] = `{}`; + exports[`generator - react samples matrix should match snapshot 1`] = ` { "gateway-jwt-skipUserManagement(true)-withAdminUi(false)-skipJhipsterDependencies(false)-enableTranslation(false)-clientRoot/-websocket(true)": { diff --git a/generators/react/generator.spec.ts b/generators/react/generator.spec.ts index 33ceee03817d..6239394489a0 100644 --- a/generators/react/generator.spec.ts +++ b/generators/react/generator.spec.ts @@ -62,12 +62,16 @@ describe(`generator - ${clientFramework}`, () => { .withJHipsterConfig(sampleConfig, entities) .withSharedApplication({ gatewayServicesApiAvailable: sampleConfig.applicationType === 'gateway' }) .withGenerators([[MockedLanguagesGenerator, { namespace: 'jhipster:languages' }]]) + .withMockedSource() .withMockedGenerators(['jhipster:common']); }); it('should match generated files snapshot', () => { expect(runResult.getStateSnapshot()).toMatchSnapshot(); }); + it('should match source calls snapshot', () => { + expect(runResult.sourceCallsArg).toMatchSnapshot(); + }); it('contains correct clientFramework', () => { runResult.assertFileContent('.yo-rc.json', new RegExp(`"clientFramework": "${clientFramework}"`)); }); diff --git a/generators/react/generator.ts b/generators/react/generator.ts index 5affccfdd8d5..cd2bbcf096b5 100644 --- a/generators/react/generator.ts +++ b/generators/react/generator.ts @@ -189,22 +189,22 @@ export default class ReactGenerator extends BaseApplicationGenerator { get postWriting() { return this.asPostWritingTaskGroup({ - addMicrofrontendDependencies({ application }) { + addMicrofrontendDependencies({ application, source }) { if (!application.microfrontend) return; const { applicationTypeGateway } = application; if (applicationTypeGateway) { - this.packageJson.merge({ + source.mergeClientPackageJson!({ devDependencies: { '@module-federation/utilities': null }, }); } - this.packageJson.merge({ + source.mergeClientPackageJson!({ devDependencies: { '@module-federation/enhanced': null }, }); }, - addWebsocketDependencies({ application }) { + addWebsocketDependencies({ application, source }) { const { communicationSpringWebsocket, nodeDependencies } = application; if (communicationSpringWebsocket) { - this.packageJson.merge({ + source.mergeClientPackageJson!({ dependencies: { rxjs: nodeDependencies.rxjs, 'sockjs-client': nodeDependencies['sockjs-client'], diff --git a/generators/react/templates/package.json.ejs b/generators/react/templates/package.json.ejs index f319645b111a..64cb4e7dd075 100644 --- a/generators/react/templates/package.json.ejs +++ b/generators/react/templates/package.json.ejs @@ -132,8 +132,6 @@ "default_environment": "prod" }, "scripts": { - "prettier:check": "prettier --check \"{,src/**/,webpack/,.blueprint/**/}*.{<%= prettierExtensions %>}\"", - "prettier:format": "prettier --write \"{,src/**/,webpack/,.blueprint/**/}*.{<%= prettierExtensions %>}\"", "lint": "eslint .", "lint:fix": "<%= clientPackageManager %> run lint -- --fix", "cleanup": "rimraf <%= this.relativeDir(clientRootDir, temporaryDir) %>", diff --git a/generators/spring-boot/templates/package.json.ejs b/generators/spring-boot/templates/package.json.ejs index e217c90c13cb..9af21e109b30 100644 --- a/generators/spring-boot/templates/package.json.ejs +++ b/generators/spring-boot/templates/package.json.ejs @@ -31,8 +31,5 @@ "config": { "default_environment": "prod" }, - "scripts": { - "prettier:check": "prettier --check \"{,src/**/,.blueprint/**/}*.{<%= prettierExtensions %>}\"", - "prettier:format": "prettier --write \"{,src/**/,.blueprint/**/}*.{<%= prettierExtensions %>}\"" - } + "scripts": {} } diff --git a/generators/vue/__snapshots__/generator.spec.ts.snap b/generators/vue/__snapshots__/generator.spec.ts.snap index 978209a6225e..55112da5c0bb 100644 --- a/generators/vue/__snapshots__/generator.spec.ts.snap +++ b/generators/vue/__snapshots__/generator.spec.ts.snap @@ -449,9 +449,33 @@ exports[`generator - vue gateway-jwt-skipUserManagement(true)-withAdminUi(false) "clientRoot/vitest.config.mts": { "stateCleared": "modified", }, - "package.json": { - "stateCleared": "modified", - }, +} +`; + +exports[`generator - vue gateway-jwt-skipUserManagement(true)-withAdminUi(false)-skipJhipsterDependencies(false)-enableTranslation(false)-clientRoot/-websocket(true) should match source calls snapshot 1`] = ` +{ + "addExternalResourceToRoot": [ + { + "comment": "Workaround https://github.com/axios/axios/issues/5622", + "resource": "", + }, + { + "comment": "Load vue main", + "resource": "", + }, + ], + "mergeClientPackageJson": [ + { + "scripts": { + "vite-build": "vite build", + "vite-serve": "vite", + "webapp:build:dev": "npm run vite-build", + "webapp:build:prod": "npm run vite-build", + "webapp:dev": "npm run vite-serve", + "webapp:serve": "npm run vite-serve", + }, + }, + ], } `; @@ -976,9 +1000,33 @@ exports[`generator - vue gateway-oauth2-withAdminUi(true)-skipJhipsterDependenci "clientRoot/vitest.config.mts": { "stateCleared": "modified", }, - "package.json": { - "stateCleared": "modified", - }, +} +`; + +exports[`generator - vue gateway-oauth2-withAdminUi(true)-skipJhipsterDependencies(true)-enableTranslation(true)-clientRoot/-websocket(true) should match source calls snapshot 1`] = ` +{ + "addExternalResourceToRoot": [ + { + "comment": "Workaround https://github.com/axios/axios/issues/5622", + "resource": "", + }, + { + "comment": "Load vue main", + "resource": "", + }, + ], + "mergeClientPackageJson": [ + { + "scripts": { + "vite-build": "vite build", + "vite-serve": "vite", + "webapp:build:dev": "npm run vite-build", + "webapp:build:prod": "npm run vite-build", + "webapp:dev": "npm run vite-serve", + "webapp:serve": "npm run vite-serve", + }, + }, + ], } `; @@ -1458,9 +1506,50 @@ exports[`generator - vue microservice-jwt-skipUserManagement(false)-withAdminUi( "clientRoot/webpack/webpack.prod.js": { "stateCleared": "modified", }, - "package.json": { - "stateCleared": "modified", - }, +} +`; + +exports[`generator - vue microservice-jwt-skipUserManagement(false)-withAdminUi(false)-skipJhipsterDependencies(false)-enableTranslation(false)-clientRoot/-websocket(false) should match source calls snapshot 1`] = ` +{ + "addWebpackConfig": [ + { + "config": "require('./webpack.microfrontend')({ serve: options.env.WEBPACK_SERVE })", + }, + ], + "mergeClientPackageJson": [ + { + "scripts": { + "webapp:build:dev": "npm run webpack -- --mode development --env stats=minimal", + "webapp:build:prod": "npm run webpack -- --mode production --env stats=minimal", + "webapp:dev": "npm run webpack-dev-server -- --mode development --env stats=normal", + "webpack": "webpack --config webpack/webpack.common.js", + "webpack-dev-server": "webpack serve --config webpack/webpack.common.js", + }, + }, + { + "devDependencies": { + "@module-federation/enhanced": null, + "browser-sync-webpack-plugin": null, + "copy-webpack-plugin": null, + "css-loader": null, + "css-minimizer-webpack-plugin": null, + "html-webpack-plugin": null, + "mini-css-extract-plugin": null, + "postcss-loader": null, + "sass-loader": null, + "terser-webpack-plugin": null, + "ts-loader": null, + "vue-loader": null, + "vue-style-loader": null, + "webpack": null, + "webpack-bundle-analyzer": null, + "webpack-cli": null, + "webpack-dev-server": null, + "webpack-merge": null, + "workbox-webpack-plugin": null, + }, + }, + ], } `; @@ -1943,6 +2032,52 @@ exports[`generator - vue microservice-oauth2-withAdminUi(true)-skipJhipsterDepen } `; +exports[`generator - vue microservice-oauth2-withAdminUi(true)-skipJhipsterDependencies(true)-enableTranslation(true)--websocket(false) should match source calls snapshot 1`] = ` +{ + "addWebpackConfig": [ + { + "config": "require('./webpack.microfrontend')({ serve: options.env.WEBPACK_SERVE })", + }, + ], + "mergeClientPackageJson": [ + { + "scripts": { + "webapp:build:dev": "npm run webpack -- --mode development --env stats=minimal", + "webapp:build:prod": "npm run webpack -- --mode production --env stats=minimal", + "webapp:dev": "npm run webpack-dev-server -- --mode development --env stats=normal", + "webpack": "webpack --config webpack/webpack.common.js", + "webpack-dev-server": "webpack serve --config webpack/webpack.common.js", + }, + }, + { + "devDependencies": { + "@module-federation/enhanced": null, + "browser-sync-webpack-plugin": null, + "copy-webpack-plugin": null, + "css-loader": null, + "css-minimizer-webpack-plugin": null, + "folder-hash": null, + "html-webpack-plugin": null, + "merge-jsons-webpack-plugin": null, + "mini-css-extract-plugin": null, + "postcss-loader": null, + "sass-loader": null, + "terser-webpack-plugin": null, + "ts-loader": null, + "vue-loader": null, + "vue-style-loader": null, + "webpack": null, + "webpack-bundle-analyzer": null, + "webpack-cli": null, + "webpack-dev-server": null, + "webpack-merge": null, + "workbox-webpack-plugin": null, + }, + }, + ], +} +`; + exports[`generator - vue monolith-jwt-skipUserManagement(false)-withAdminUi(true)-skipJhipsterDependencies(true)-enableTranslation(true)--websocket(true) should match generated files snapshot 1`] = ` { ".jhipster/EntityWithCustomId.json": { @@ -2554,6 +2689,33 @@ exports[`generator - vue monolith-jwt-skipUserManagement(false)-withAdminUi(true } `; +exports[`generator - vue monolith-jwt-skipUserManagement(false)-withAdminUi(true)-skipJhipsterDependencies(true)-enableTranslation(true)--websocket(true) should match source calls snapshot 1`] = ` +{ + "addExternalResourceToRoot": [ + { + "comment": "Workaround https://github.com/axios/axios/issues/5622", + "resource": "", + }, + { + "comment": "Load vue main", + "resource": "", + }, + ], + "mergeClientPackageJson": [ + { + "scripts": { + "vite-build": "vite build", + "vite-serve": "vite", + "webapp:build:dev": "npm run vite-build", + "webapp:build:prod": "npm run vite-build", + "webapp:dev": "npm run vite-serve", + "webapp:serve": "npm run vite-serve", + }, + }, + ], +} +`; + exports[`generator - vue monolith-oauth2-withAdminUi(false)-skipJhipsterDependencies(false)-enableTranslation(false)-websocket(false) should match generated files snapshot 1`] = ` { ".jhipster/EntityWithCustomId.json": { @@ -2985,6 +3147,33 @@ exports[`generator - vue monolith-oauth2-withAdminUi(false)-skipJhipsterDependen } `; +exports[`generator - vue monolith-oauth2-withAdminUi(false)-skipJhipsterDependencies(false)-enableTranslation(false)-websocket(false) should match source calls snapshot 1`] = ` +{ + "addExternalResourceToRoot": [ + { + "comment": "Workaround https://github.com/axios/axios/issues/5622", + "resource": "", + }, + { + "comment": "Load vue main", + "resource": "", + }, + ], + "mergeClientPackageJson": [ + { + "scripts": { + "vite-build": "vite build", + "vite-serve": "vite", + "webapp:build:dev": "npm run vite-build", + "webapp:build:prod": "npm run vite-build", + "webapp:dev": "npm run vite-serve", + "webapp:serve": "npm run vite-serve", + }, + }, + ], +} +`; + exports[`generator - vue monolith-session-skipUserManagement(true)-withAdminUi(false)-skipJhipsterDependencies(false)-enableTranslation(false)-websocket(true) should match generated files snapshot 1`] = ` { ".jhipster/EntityWithCustomId.json": { @@ -3425,6 +3614,33 @@ exports[`generator - vue monolith-session-skipUserManagement(true)-withAdminUi(f } `; +exports[`generator - vue monolith-session-skipUserManagement(true)-withAdminUi(false)-skipJhipsterDependencies(false)-enableTranslation(false)-websocket(true) should match source calls snapshot 1`] = ` +{ + "addExternalResourceToRoot": [ + { + "comment": "Workaround https://github.com/axios/axios/issues/5622", + "resource": "", + }, + { + "comment": "Load vue main", + "resource": "", + }, + ], + "mergeClientPackageJson": [ + { + "scripts": { + "vite-build": "vite build", + "vite-serve": "vite", + "webapp:build:dev": "npm run vite-build", + "webapp:build:prod": "npm run vite-build", + "webapp:dev": "npm run vite-serve", + "webapp:serve": "npm run vite-serve", + }, + }, + ], +} +`; + exports[`generator - vue samples matrix should match snapshot 1`] = ` { "gateway-jwt-skipUserManagement(true)-withAdminUi(false)-skipJhipsterDependencies(false)-enableTranslation(false)-clientRoot/-websocket(true)": { diff --git a/generators/vue/generator.spec.ts b/generators/vue/generator.spec.ts index 77ef9c93d759..8163624866fe 100644 --- a/generators/vue/generator.spec.ts +++ b/generators/vue/generator.spec.ts @@ -70,6 +70,7 @@ describe(`generator - ${clientFramework}`, () => { .runJHipster(generator) .withJHipsterConfig(sampleConfig, entities) .withControl({ getWebappTranslation: () => 'translations' }) + .withMockedSource() .withSharedApplication({ gatewayServicesApiAvailable: sampleConfig.applicationType === 'gateway' }) .withMockedGenerators(['jhipster:common', 'jhipster:languages']); }); @@ -77,6 +78,9 @@ describe(`generator - ${clientFramework}`, () => { it('should match generated files snapshot', () => { expect(runResult.getStateSnapshot()).toMatchSnapshot(); }); + it('should match source calls snapshot', () => { + expect(runResult.sourceCallsArg).toMatchSnapshot(); + }); it('contains correct clientFramework', () => { runResult.assertFileContent('.yo-rc.json', new RegExp(`"clientFramework": "${clientFramework}"`)); }); diff --git a/generators/vue/generator.ts b/generators/vue/generator.ts index 04cca3fb6b3c..80044fb5716b 100644 --- a/generators/vue/generator.ts +++ b/generators/vue/generator.ts @@ -177,10 +177,10 @@ export default class VueGenerator extends BaseApplicationGenerator { get postWriting() { return this.asPostWritingTaskGroup({ - addPackageJsonScripts({ application }) { - const { clientBundlerVite, clientBundlerWebpack, clientPackageManager, prettierExtensions } = application; + addPackageJsonScripts({ application, source }) { + const { clientBundlerVite, clientBundlerWebpack, clientPackageManager } = application; if (clientBundlerVite) { - this.packageJson.merge({ + source.mergeClientPackageJson!({ scripts: { 'webapp:build:dev': `${clientPackageManager} run vite-build`, 'webapp:build:prod': `${clientPackageManager} run vite-build`, @@ -191,10 +191,8 @@ export default class VueGenerator extends BaseApplicationGenerator { }, }); } else if (clientBundlerWebpack) { - this.packageJson.merge({ + source.mergeClientPackageJson!({ scripts: { - 'prettier:check': `prettier --check "{,src/**/,webpack/,.blueprint/**/}*.{${prettierExtensions}}"`, - 'prettier:format': `prettier --write "{,src/**/,webpack/,.blueprint/**/}*.{${prettierExtensions}}"`, 'webapp:build:dev': `${clientPackageManager} run webpack -- --mode development --env stats=minimal`, 'webapp:build:prod': `${clientPackageManager} run webpack -- --mode production --env stats=minimal`, 'webapp:dev': `${clientPackageManager} run webpack-dev-server -- --mode development --env stats=normal`, @@ -204,24 +202,24 @@ export default class VueGenerator extends BaseApplicationGenerator { }); } }, - addMicrofrontendDependencies({ application }) { + addMicrofrontendDependencies({ application, source }) { const { applicationTypeGateway, clientBundlerVite, clientBundlerWebpack, enableTranslation, microfrontend } = application; if (!microfrontend) return; if (clientBundlerVite) { - this.packageJson.merge({ + source.mergeClientPackageJson!({ devDependencies: { '@originjs/vite-plugin-federation': '1.3.6', }, }); } else if (clientBundlerWebpack) { if (applicationTypeGateway) { - this.packageJson.merge({ + source.mergeClientPackageJson!({ devDependencies: { '@module-federation/utilities': null, }, }); } - this.packageJson.merge({ + source.mergeClientPackageJson!({ devDependencies: { '@module-federation/enhanced': null, 'browser-sync-webpack-plugin': null, diff --git a/generators/vue/templates/package.json.ejs b/generators/vue/templates/package.json.ejs index 4e25b34c897e..f43a28d7bc97 100644 --- a/generators/vue/templates/package.json.ejs +++ b/generators/vue/templates/package.json.ejs @@ -102,8 +102,6 @@ "clean-www": "rimraf <%= this.relativeDir(clientRootDir, clientDistDir) %>", "lint": "eslint .", "lint:fix": "eslint . --fix", - "prettier:check": "prettier --check \"{,src/**/,.blueprint/**/}*.{<%= prettierExtensions %>}\"", - "prettier:format": "prettier --write \"{,src/**/,.blueprint/**/}*.{<%= prettierExtensions %>}\"", "serve": "<%= clientPackageManager %> run start --", "start": "<%= clientPackageManager %> run webapp:dev --", "start-tls": "<%= clientPackageManager %> run webapp:dev -- --env.tls",