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

Adjusts for improved blueprint support. #23762

Merged
merged 18 commits into from
Oct 6, 2023
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
7 changes: 4 additions & 3 deletions generators/angular/support/update-languages.mts
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,18 @@ function updateLanguagesInConstantsTask(this: BaseGenerator, { application, cont
}

function updateLanguagesInWebpackTask(this: BaseGenerator, { application, control = {} }: UpdateClientLanguagesTaskParam) {
const { clientSrcDir, languages } = application;
const { clientSrcDir, clientRootDir, languages } = application;
const { ignoreNeedlesError: ignoreNonExisting } = control;
let newContent = 'groupBy: [\n';
const srcRelativePath = this.relativeDir(clientRootDir, clientSrcDir);
languages?.forEach(language => {
newContent += ` { pattern: "./${clientSrcDir}i18n/${language}/*.json", fileName: "./i18n/${language}.json" },\n`;
newContent += ` { pattern: "./${srcRelativePath}i18n/${language}/*.json", fileName: "./i18n/${language}.json" },\n`;
});
newContent +=
' // jhipster-needle-i18n-language-webpack - JHipster will add/remove languages in this array\n' +
' ]';

this.editFile(`${application.clientRootDir}webpack/webpack.custom.js`, { ignoreNonExisting }, content =>
this.editFile(`${clientRootDir}webpack/webpack.custom.js`, { ignoreNonExisting }, content =>
content.replace(/groupBy:.*\[([^\]]*jhipster-needle-i18n-language-webpack[^\]]*)\]/g, newContent),
);
}
Expand Down
15 changes: 15 additions & 0 deletions generators/app/__snapshots__/generator.spec.mts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ exports[`generator - app with default config should match snapshot 1`] = `
"defaultEnvironment": "prod",
"defaultPackaging": "jar",
"devDatabaseExtraOptions": "",
"devDatabaseName": "jhipster",
"devDatabasePassword": "",
"devDatabaseType": "postgresql",
"devDatabaseTypeH2Any": false,
Expand Down Expand Up @@ -298,6 +299,7 @@ exports[`generator - app with default config should match snapshot 1`] = `
"zookeeperTag": "zookeeper-tag-placeholder",
},
"dockerServices": [
"app",
"postgresql",
],
"dockerServicesDir": "src/main/docker/",
Expand All @@ -323,6 +325,7 @@ exports[`generator - app with default config should match snapshot 1`] = `
"generateBuiltInUserEntity": true,
"generateInMemoryUserCredentials": false,
"generateUserManagement": true,
"gradleEnterpriseHost": undefined,
"gradleVersion": "GRADLE_VERSION",
"hipster": "jhipster_family_member_3",
"humanizedBaseName": "JHipster",
Expand Down Expand Up @@ -568,6 +571,7 @@ exports[`generator - app with default config should match snapshot 1`] = `
"prettierJava": undefined,
"prettierTabWidth": 2,
"prodDatabaseExtraOptions": "",
"prodDatabaseName": "jhipster",
"prodDatabasePassword": "",
"prodDatabaseType": "postgresql",
"prodDatabaseTypeMariadb": false,
Expand Down Expand Up @@ -615,6 +619,7 @@ exports[`generator - app with default config should match snapshot 1`] = `
"testJavaPackageDir": "src/test/java/com/mycompany/myapp/",
"testResourceDir": "src/test/resources/",
"upperFirstCamelCaseBaseName": "Jhipster",
"useNpmWrapper": true,
"user": Any<Object>,
"webappEnumerationsDir": "src/main/webapp/app/entities/enumerations/",
"webappLoginRegExp": "^[a-zA-Z0-9!$&*+=?^_\`{|}~.-]+@[a-zA-Z0-9-]+(?:\\\\.[a-zA-Z0-9-]+)*$|^[_.@A-Za-z0-9-]+$",
Expand Down Expand Up @@ -715,6 +720,7 @@ exports[`generator - app with gateway should match snapshot 1`] = `
"defaultEnvironment": "prod",
"defaultPackaging": "jar",
"devDatabaseExtraOptions": "",
"devDatabaseName": "jhipster",
"devDatabasePassword": "",
"devDatabaseType": "postgresql",
"devDatabaseTypeH2Any": false,
Expand Down Expand Up @@ -859,6 +865,7 @@ exports[`generator - app with gateway should match snapshot 1`] = `
"zookeeperTag": "zookeeper-tag-placeholder",
},
"dockerServices": [
"app",
"consul",
"zipkin",
"postgresql",
Expand Down Expand Up @@ -886,6 +893,7 @@ exports[`generator - app with gateway should match snapshot 1`] = `
"generateBuiltInUserEntity": true,
"generateInMemoryUserCredentials": false,
"generateUserManagement": true,
"gradleEnterpriseHost": undefined,
"gradleVersion": "GRADLE_VERSION",
"hipster": "jhipster_family_member_3",
"humanizedBaseName": "JHipster",
Expand Down Expand Up @@ -1131,6 +1139,7 @@ exports[`generator - app with gateway should match snapshot 1`] = `
"prettierJava": undefined,
"prettierTabWidth": 2,
"prodDatabaseExtraOptions": "",
"prodDatabaseName": "jhipster",
"prodDatabasePassword": "",
"prodDatabaseType": "postgresql",
"prodDatabaseTypeMariadb": false,
Expand Down Expand Up @@ -1179,6 +1188,7 @@ exports[`generator - app with gateway should match snapshot 1`] = `
"testJavaPackageDir": "src/test/java/com/mycompany/myapp/",
"testResourceDir": "src/test/resources/",
"upperFirstCamelCaseBaseName": "Jhipster",
"useNpmWrapper": true,
"user": Any<Object>,
"webappEnumerationsDir": "src/main/webapp/app/entities/enumerations/",
"webappLoginRegExp": "^[a-zA-Z0-9!$&*+=?^_\`{|}~.-]+@[a-zA-Z0-9-]+(?:\\\\.[a-zA-Z0-9-]+)*$|^[_.@A-Za-z0-9-]+$",
Expand Down Expand Up @@ -1278,6 +1288,7 @@ exports[`generator - app with microservice should match snapshot 1`] = `
"defaultEnvironment": "prod",
"defaultPackaging": "jar",
"devDatabaseExtraOptions": "",
"devDatabaseName": "jhipster",
"devDatabasePassword": "",
"devDatabaseType": "postgresql",
"devDatabaseTypeH2Any": false,
Expand Down Expand Up @@ -1422,6 +1433,7 @@ exports[`generator - app with microservice should match snapshot 1`] = `
"zookeeperTag": "zookeeper-tag-placeholder",
},
"dockerServices": [
"app",
"consul",
"zipkin",
"hazelcast",
Expand Down Expand Up @@ -1450,6 +1462,7 @@ exports[`generator - app with microservice should match snapshot 1`] = `
"generateBuiltInUserEntity": false,
"generateInMemoryUserCredentials": false,
"generateUserManagement": false,
"gradleEnterpriseHost": undefined,
"gradleVersion": "GRADLE_VERSION",
"hipster": "jhipster_family_member_3",
"humanizedBaseName": "JHipster",
Expand Down Expand Up @@ -1640,6 +1653,7 @@ exports[`generator - app with microservice should match snapshot 1`] = `
"prettierJava": undefined,
"prettierTabWidth": 2,
"prodDatabaseExtraOptions": "",
"prodDatabaseName": "jhipster",
"prodDatabasePassword": "",
"prodDatabaseType": "postgresql",
"prodDatabaseTypeMariadb": false,
Expand Down Expand Up @@ -1687,6 +1701,7 @@ exports[`generator - app with microservice should match snapshot 1`] = `
"testJavaPackageDir": "src/test/java/com/mycompany/myapp/",
"testResourceDir": "src/test/resources/",
"upperFirstCamelCaseBaseName": "Jhipster",
"useNpmWrapper": false,
"websocket": "no",
"withAdminUi": false,
}
Expand Down
9 changes: 4 additions & 5 deletions generators/base-application/generator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import _ from 'lodash';
import { upperFirst } from 'lodash-es';
import type { Storage } from 'yeoman-generator';

import BaseGenerator from '../base/index.mjs';
Expand All @@ -31,8 +31,7 @@ import { ClientSourceType } from '../client/types.mjs';
import { LanguageSourceType } from '../languages/types.js';
import command from './command.mjs';
import { JHipsterGeneratorFeatures, JHipsterGeneratorOptions } from '../base/api.mjs';

const { upperFirst, defaults } = _;
import { mutateApplication } from '../base/support/config.mjs';

const {
LOADING,
Expand Down Expand Up @@ -125,7 +124,7 @@ export default class BaseApplicationGenerator<
});
if (this.options.applicationWithEntities.entities) {
const entities = this.options.applicationWithEntities.entities.map(entity => {
const entityName = _.upperFirst(entity.name);
const entityName = upperFirst(entity.name);
const file = this.getEntityConfigPath(entityName);
this.fs.writeJSON(file, { ...this.fs.readJSON(file), ...entity });
return entityName;
Expand Down Expand Up @@ -370,7 +369,7 @@ export default class BaseApplicationGenerator<
if ([PREPARING, LOADING].includes(priorityName)) {
return {
application,
applicationDefaults: data => defaults(application, data),
applicationDefaults: data => mutateApplication(application, data),
};
}
if (LOADING_ENTITIES === priorityName) {
Expand Down
4 changes: 4 additions & 0 deletions generators/base-application/support/prepare-entity.mts
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,9 @@ export function prepareEntityPrimaryKeyForTemplates(entityWithConfig, generator,
get name() {
return relationshipId.otherEntity.primaryKey.name;
},
get hibernateSnakeCaseName() {
return hibernateSnakeCase(relationshipId.otherEntity.primaryKey.name);
},
get nameCapitalized() {
return relationshipId.otherEntity.primaryKey.nameCapitalized;
},
Expand Down Expand Up @@ -408,6 +411,7 @@ export function prepareEntityPrimaryKeyForTemplates(entityWithConfig, generator,
entityWithConfig.primaryKey = {
derived: false,
name: primaryKeyName,
hibernateSnakeCaseName: hibernateSnakeCase(primaryKeyName),
nameCapitalized: _.upperFirst(primaryKeyName),
type: primaryKeyType,
tsType: getTypescriptKeyType(primaryKeyType),
Expand Down
29 changes: 21 additions & 8 deletions generators/base-application/tasks.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,25 @@ type ApplicationTaskParam<Definition extends GenericApplicationDefinition = Cont
application: Definition['applicationType'] & { user: Definition['entityType'] };
};

type ApplicationDefaultsTaskParam = {
/**
* Parameter properties accepts:
* - functions: receives the application and the return value is set at the application property.
* - non functions: application property will receive the property in case current value is undefined.
*
* Applies each object in order.
*
* @example
* // application = { prop: 'foo-bar', prop2: 'foo2' }
* applicationDefaults(
* application,
* { prop: 'foo', prop2: ({ prop }) => prop + 2 },
* { prop: ({ prop }) => prop + '-bar', prop2: 'won\'t override' },
* );
*/
applicationDefaults: (...defaults: Record<any, any>[]) => void;
};

export type EntitiesTaskParam<Definition extends GenericApplicationDefinition = GenericApplicationDefinition> = {
entities: Definition['entityType'][];
};
Expand Down Expand Up @@ -63,15 +82,9 @@ export type BaseApplicationGeneratorDefinition<
GenericSourceTypeDefinition<Record<string, (...args: any[]) => any>>,
> = BaseGeneratorDefinition<Definition> &
// Add application to existing priorities
Record<'loadingTaskParam' | 'preparingTaskParam', ApplicationTaskParam<Definition> & ApplicationDefaultsTaskParam> &
Record<
| 'loadingTaskParam'
| 'preparingTaskParam'
| 'defaultTaskParam'
| 'postWritingTaskParam'
| 'preConflictsTaskParam'
| 'installTaskParam'
| 'postInstallTaskParam'
| 'endTaskParam',
'defaultTaskParam' | 'postWritingTaskParam' | 'preConflictsTaskParam' | 'installTaskParam' | 'postInstallTaskParam' | 'endTaskParam',
ApplicationTaskParam<Definition>
> &
Record<'writingTaskParam', ApplicationTaskParam<Definition> & { configChanges?: Record<string, { newValue: any; oldValue: any }> }> &
Expand Down
34 changes: 34 additions & 0 deletions generators/base/support/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,37 @@ function filterValue(object: Record<string, any>, filterValue: (any) => boolean
}
return clone;
}

/**
* Picks every field from source.
* A field with undefined value is returned for missing fields.
*/
export const pickFields = (source: Record<string | number, any>, fields: (string | number)[]) =>
Object.fromEntries(fields.map(field => [field, source[field]]));

/**
* Mutation properties accepts:
* - functions: receives the application and the return value is set at the application property.
* - non functions: application property will receive the property in case current value is undefined.
*
* Applies each mutation object in order.
*
* @example
* // application = { prop: 'foo-bar', prop2: 'foo2' }
* mutateApplication(
* application,
* { prop: 'foo', prop2: ({ prop }) => prop + 2 },
* { prop: ({ prop }) => prop + '-bar', prop2: 'won\'t override' },
* );
*/
export const mutateApplication = (application: Record<string | number, any>, ...mutations: Record<string | number, any>[]) => {
for (const mutation of mutations) {
for (const [key, value] of Object.entries(mutation)) {
if (typeof value === 'function') {
application[key] = value(application);
} else if (application[key] === undefined) {
application[key] = value;
}
}
}
};
15 changes: 2 additions & 13 deletions generators/base/tasks.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,12 @@ export type GenericTask<ThisType, Arg1Type> = (this: ThisType, arg1: Arg1Type) =

export type GenericTaskGroup<ThisType, Arg1Type = ControlTaskParam> = Record<string, GenericTask<ThisType, Arg1Type>>;

type ApplicationDefaultsTaskParam = {
/**
* Set application defaults.
*
* @param any
* @returns
*/
applicationDefaults: (any) => void;
};

export type BaseGeneratorDefinition<Definition extends GenericSourceTypeDefinition = GenericSourceTypeDefinition> = Record<
| 'initializingTaskParam'
| 'promptingTaskParam'
| 'configuringTaskParam'
| 'composingTaskParam'
| 'preparingTaskParam'
| 'loadingTaskParam'
| 'defaultTaskParam'
| 'writingTaskParam'
| 'postWritingTaskParam'
Expand All @@ -40,5 +30,4 @@ export type BaseGeneratorDefinition<Definition extends GenericSourceTypeDefiniti
ControlTaskParam
> &
Record<'postWritingTaskParam', SourceTaskParam<Definition>> &
Record<'loadingTaskParam', ControlTaskParam & ApplicationDefaultsTaskParam> &
Record<'preparingTaskParam', SourceTaskParam<Definition> & ApplicationDefaultsTaskParam>;
Record<'preparingTaskParam', SourceTaskParam<Definition>>;
5 changes: 1 addition & 4 deletions generators/bootstrap-application-base/generator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,8 @@ export default class BootstrapApplicationBase extends BaseApplicationGenerator {
applicationDefaults({
nodePackageManager: 'npm',
dockerServicesDir: JAVA_DOCKER_DIR,
});

applicationDefaults({
// TODO drop clientPackageManager
clientPackageManager: application.nodePackageManager,
clientPackageManager: ({ nodePackageManager }) => nodePackageManager,
});
},
});
Expand Down
9 changes: 7 additions & 2 deletions generators/bootstrap-application/generator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,17 @@ export default class BootstrapApplicationGenerator extends BaseApplicationGenera

get preparing() {
return this.asPreparingTaskGroup({
preparing({ application }) {
preparing({ application, applicationDefaults }) {
if (application.authenticationType === 'oauth2' || application.databaseType === 'no') {
(application as any).skipUserManagement = true;
}

applicationDefaults({
useNpmWrapper: application => application.clientFrameworkAny && application.backendTypeSpringBoot,
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`;
Expand All @@ -92,7 +98,6 @@ export default class BootstrapApplicationGenerator extends BaseApplicationGenera
prettierExtensions = `${prettierExtensions},java`;
}
application.prettierExtensions = prettierExtensions;
application.documentationArchiveUrl = `${JHIPSTER_DOCUMENTATION_URL}${JHIPSTER_DOCUMENTATION_ARCHIVE_PATH}v${application.jhipsterVersion}`;
},
});
}
Expand Down
3 changes: 3 additions & 0 deletions generators/bootstrap-application/generator.spec.mts
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ describe(`generator - ${generator}`, () => {
"hasInteger": false,
"hasLong": false,
"hasUUID": true,
"hibernateSnakeCaseName": "id",
"ids": [
{
"autoGenerate": true,
Expand Down Expand Up @@ -849,6 +850,7 @@ describe(`generator - ${generator}`, () => {
"hasInteger": false,
"hasLong": false,
"hasUUID": true,
"hibernateSnakeCaseName": "id",
"ids": [
{
"autoGenerate": true,
Expand Down Expand Up @@ -1165,6 +1167,7 @@ describe(`generator - ${generator}`, () => {
"hasInteger": false,
"hasLong": false,
"hasUUID": true,
"hibernateSnakeCaseName": "id",
"ids": [
{
"autoGenerate": true,
Expand Down
6 changes: 3 additions & 3 deletions generators/common/templates/.husky/pre-commit.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
. "$(dirname "$0")/_/husky.sh"


<%_ if (skipClient || skipServer) { _%>
npx --no-install lint-staged
<%_ } else { _%>
<%_ if (useNpmWrapper) { _%>
"$(dirname "$0")/../npmw" exec --no-install lint-staged
<%_ } else { _%>
npx --no-install lint-staged
<%_ } _%>
Loading