Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

javascript: add mergeClientPackageJson api and adjust injection #27772

Merged
merged 8 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 131 additions & 0 deletions generators/angular/__snapshots__/generator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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)": {
Expand Down
4 changes: 4 additions & 0 deletions generators/angular/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}"`));
});
Expand Down
4 changes: 2 additions & 2 deletions generators/angular/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
2 changes: 0 additions & 2 deletions generators/angular/templates/package.json.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -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) %>",
Expand Down
4 changes: 4 additions & 0 deletions generators/app/__snapshots__/generator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Expand Down Expand Up @@ -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/",
Expand Down Expand Up @@ -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/",
Expand Down Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions generators/bootstrap-application-base/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export default class BootstrapApplicationBase extends BaseApplicationGenerator {
backendType: this.jhipsterConfig.backendType ?? 'Java',
syncUserWithIdp: this.jhipsterConfig.syncUserWithIdp,
packageJsonScripts: {},
clientPackageJsonScripts: {},
});
},
loadNodeDependencies({ application }) {
Expand Down
2 changes: 2 additions & 0 deletions generators/common/__snapshots__/generator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
33 changes: 31 additions & 2 deletions generators/javascript/generators/bootstrap/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) {
Expand All @@ -69,25 +83,40 @@ 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', {
...packageJsonEngines,
node: typeof packageJsonNodeEngine === 'string' ? packageJsonNodeEngine : packageJson.engines.node,
});
}

if (clientPackageJsonScripts && Object.keys(clientPackageJsonScripts).length > 0) {
source.mergeClientPackageJson!({ scripts: clientPackageJsonScripts });
}
},
});
}
Expand Down
6 changes: 4 additions & 2 deletions generators/javascript/generators/eslint/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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}\\""
}
}
",
Expand Down Expand Up @@ -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}\\""
}
}
",
Expand Down
Loading
Loading