From 696280324720c251d8b1e6633ff045c456cfa498 Mon Sep 17 00:00:00 2001 From: dungreact Date: Mon, 30 Oct 2023 23:41:06 +0700 Subject: [PATCH] success build --- generators/react/files-react.mjs | 321 ------------------ generators/react/generator.mjs | 300 +++++++++++++++- .../app/shared/layout/sider/sider.tsx.ejs | 10 +- 3 files changed, 303 insertions(+), 328 deletions(-) delete mode 100644 generators/react/files-react.mjs diff --git a/generators/react/files-react.mjs b/generators/react/files-react.mjs deleted file mode 100644 index e0ef2a9..0000000 --- a/generators/react/files-react.mjs +++ /dev/null @@ -1,321 +0,0 @@ -/** - * Copyright 2013-2023 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. - */ -import { - clientApplicationTemplatesBlock, - clientRootTemplatesBlock, - clientSrcTemplatesBlock, -} from 'generator-jhipster/generators/client/support'; - -export const files = { - common: [ - clientRootTemplatesBlock({ - templates: [ - 'package.json', - '.eslintrc.json', - 'tsconfig.json', - 'tsconfig.test.json', - 'jest.conf.js', - 'webpack/environment.js', - 'webpack/webpack.common.js', - 'webpack/webpack.dev.js', - 'webpack/webpack.prod.js', - 'webpack/utils.js', - 'webpack/logo-jhipster.png', - ], - }), - ], - sass: [ - clientRootTemplatesBlock({ - templates: ['postcss.config.js'], - }), - ], - reactApp: [ - { - ...clientApplicationTemplatesBlock(), - templates: [ - 'app.tsx', - 'index.tsx', - 'routes.tsx', - 'setup-tests.ts', - 'typings.d.ts', - 'config/constants.ts', - 'config/dayjs.ts', - 'config/axios-interceptor.ts', - 'config/error-middleware.ts', - 'config/logger-middleware.ts', - 'config/notification-middleware.ts', - 'config/store.ts', - 'config/icon-loader.ts', - ], - }, - { - condition: generator => generator.enableTranslation, - ...clientApplicationTemplatesBlock(), - templates: ['config/translation.ts'], - }, - { - condition: generator => generator.communicationSpringWebsocket, - ...clientApplicationTemplatesBlock(), - templates: ['config/websocket-middleware.ts'], - }, - { - ...clientApplicationTemplatesBlock(), - templates: ['app.scss', '_bootstrap-variables.scss'], - }, - ], - reactEntities: [ - { - ...clientApplicationTemplatesBlock(), - templates: ['entities/reducers.ts', 'entities/menu.tsx', 'entities/routes.tsx'], - }, - ], - reactMain: [ - { - ...clientApplicationTemplatesBlock(), - templates: ['modules/home/home.tsx', 'modules/login/logout.tsx'], - }, - { - condition: generator => !generator.authenticationTypeOauth2, - ...clientApplicationTemplatesBlock(), - templates: ['modules/login/login.tsx', 'modules/login/login-modal.tsx'], - }, - { - condition: generator => generator.authenticationTypeOauth2, - ...clientApplicationTemplatesBlock(), - templates: ['modules/login/login-redirect.tsx'], - }, - { - ...clientApplicationTemplatesBlock(), - templates: ['modules/home/home.scss'], - }, - ], - reducers: [ - { - ...clientApplicationTemplatesBlock(), - templates: [ - 'shared/reducers/index.ts', - 'shared/reducers/reducer.utils.ts', - 'shared/reducers/authentication.ts', - 'shared/reducers/application-profile.ts', - ], - }, - { - condition: generator => generator.enableTranslation, - ...clientApplicationTemplatesBlock(), - templates: ['shared/reducers/locale.ts'], - }, - { - condition: generator => generator.authenticationTypeOauth2, - ...clientApplicationTemplatesBlock(), - templates: ['shared/reducers/user-management.ts'], - }, - ], - accountModule: [ - { - condition: generator => generator.generateUserManagement, - ...clientApplicationTemplatesBlock(), - templates: [ - 'modules/account/index.tsx', - 'modules/account/activate/activate.tsx', - 'modules/account/password/password.tsx', - 'modules/account/register/register.tsx', - 'modules/account/password-reset/init/password-reset-init.tsx', - 'modules/account/password-reset/finish/password-reset-finish.tsx', - 'modules/account/settings/settings.tsx', - 'modules/account/register/register.reducer.ts', - 'modules/account/activate/activate.reducer.ts', - 'modules/account/password-reset/password-reset.reducer.ts', - 'modules/account/password/password.reducer.ts', - 'modules/account/settings/settings.reducer.ts', - ], - }, - { - condition: generator => generator.authenticationTypeSession && generator.generateUserManagement, - ...clientApplicationTemplatesBlock(), - templates: ['modules/account/sessions/sessions.tsx', 'modules/account/sessions/sessions.reducer.ts'], - }, - ], - adminModule: [ - { - ...clientApplicationTemplatesBlock(), - templates: [ - 'modules/administration/index.tsx', - 'modules/administration/administration.reducer.ts', - 'modules/administration/docs/docs.tsx', - 'modules/administration/docs/docs.scss', - ], - }, - { - condition: generator => generator.withAdminUi, - ...clientApplicationTemplatesBlock(), - templates: [ - 'modules/administration/configuration/configuration.tsx', - 'modules/administration/health/health.tsx', - 'modules/administration/health/health-modal.tsx', - 'modules/administration/logs/logs.tsx', - 'modules/administration/metrics/metrics.tsx', - ], - }, - { - condition: generator => generator.communicationSpringWebsocket, - ...clientApplicationTemplatesBlock(), - templates: ['modules/administration/tracker/tracker.tsx'], - }, - { - condition: generator => generator.generateUserManagement, - ...clientApplicationTemplatesBlock(), - templates: [ - 'modules/administration/user-management/index.tsx', - 'modules/administration/user-management/user-management.tsx', - 'modules/administration/user-management/user-management-update.tsx', - 'modules/administration/user-management/user-management-detail.tsx', - 'modules/administration/user-management/user-management-delete-dialog.tsx', - 'modules/administration/user-management/user-management.reducer.ts', - ], - }, - { - condition: generator => generator.applicationTypeGateway && generator.serviceDiscoveryAny, - ...clientApplicationTemplatesBlock(), - templates: ['modules/administration/gateway/gateway.tsx'], - }, - ], - reactShared: [ - { - ...clientApplicationTemplatesBlock(), - templates: [ - // layouts - 'shared/layout/footer/footer.tsx', - 'shared/layout/header/header.tsx', - 'shared/layout/header/header-components.tsx', - 'shared/layout/menus/index.ts', - 'shared/layout/menus/admin.tsx', - 'shared/layout/menus/account.tsx', - 'shared/layout/menus/entities.tsx', - 'shared/layout/menus/menu-components.tsx', - 'shared/layout/menus/menu-item.tsx', - 'shared/layout/password/password-strength-bar.tsx', - 'shared/layout/sider/sider.tsx', - // util - 'shared/util/date-utils.ts', - 'shared/util/pagination.constants.ts', - 'shared/util/entity-utils.ts', - // components - 'shared/auth/private-route.tsx', - 'shared/error/error-boundary.tsx', - 'shared/error/error-boundary-routes.tsx', - 'shared/error/page-not-found.tsx', - 'shared/DurationFormat.tsx', - // model - 'shared/model/user.model.ts', - ], - }, - { - condition: generator => generator.enableTranslation, - ...clientApplicationTemplatesBlock(), - templates: ['shared/layout/menus/locale.tsx'], - }, - { - condition: generator => generator.authenticationTypeOauth2, - ...clientApplicationTemplatesBlock(), - templates: ['shared/util/url-utils.ts'], - }, - { - condition: generator => generator.authenticationTypeSession && generator.communicationSpringWebsocket, - ...clientApplicationTemplatesBlock(), - templates: ['shared/util/cookie-utils.ts'], - }, - { - ...clientApplicationTemplatesBlock(), - templates: [ - 'shared/layout/header/header.scss', - 'shared/layout/footer/footer.scss', - 'shared/layout/password/password-strength-bar.scss', - ], - }, - ], - microfrontend: [ - clientRootTemplatesBlock({ - condition: generator => generator.microfrontend, - templates: ['webpack/webpack.microfrontend.js.jhi.react'], - }), - { - condition: generator => generator.microfrontend, - ...clientApplicationTemplatesBlock(), - templates: ['main.tsx', 'shared/error/error-loading.tsx'], - }, - { - condition: generator => generator.microfrontend && generator.applicationTypeGateway, - ...clientSrcTemplatesBlock(), - templates: ['microfrontends/entities-menu.tsx', 'microfrontends/entities-routes.tsx'], - }, - ], - clientTestFw: [ - { - ...clientApplicationTemplatesBlock(), - templates: [ - 'config/axios-interceptor.spec.ts', - 'config/notification-middleware.spec.ts', - 'shared/reducers/application-profile.spec.ts', - 'shared/reducers/authentication.spec.ts', - 'shared/util/entity-utils.spec.ts', - 'shared/auth/private-route.spec.tsx', - 'shared/error/error-boundary.spec.tsx', - 'shared/error/error-boundary-routes.spec.tsx', - 'shared/layout/header/header.spec.tsx', - 'shared/layout/menus/account.spec.tsx', - 'modules/administration/administration.reducer.spec.ts', - ], - }, - { - condition: generator => generator.generateUserManagement, - ...clientApplicationTemplatesBlock(), - templates: [ - // 'spec/app/modules/account/register/register.spec.tsx', - 'modules/account/register/register.reducer.spec.ts', - 'modules/account/activate/activate.reducer.spec.ts', - 'modules/account/password/password.reducer.spec.ts', - 'modules/account/settings/settings.reducer.spec.ts', - ], - }, - { - condition: generator => generator.generateUserManagement, - ...clientApplicationTemplatesBlock(), - templates: ['modules/administration/user-management/user-management.reducer.spec.ts'], - }, - { - condition: generator => generator.enableTranslation, - ...clientApplicationTemplatesBlock(), - templates: ['shared/reducers/locale.spec.ts'], - }, - { - condition: generator => generator.authenticationTypeOauth2, - ...clientApplicationTemplatesBlock(), - templates: ['shared/reducers/user-management.spec.ts'], - }, - ], -}; - -export async function writeFiles(application) { - if (!application.clientFrameworkReact) return; - - await writeFiles({ - sections: files, - context: application, - }); -} diff --git a/generators/react/generator.mjs b/generators/react/generator.mjs index 7963a2d..93a1a77 100644 --- a/generators/react/generator.mjs +++ b/generators/react/generator.mjs @@ -17,7 +17,300 @@ * limitations under the License. */ import BaseApplicationGenerator from 'generator-jhipster/generators/base-application'; -import { writeFiles } from './files-react.mjs'; +import { + clientApplicationTemplatesBlock, + clientRootTemplatesBlock, + clientSrcTemplatesBlock, +} from 'generator-jhipster/generators/client/support'; + +export const files = { + common: [ + clientRootTemplatesBlock({ + templates: [ + 'package.json', + '.eslintrc.json', + 'tsconfig.json', + 'tsconfig.test.json', + 'jest.conf.js', + 'webpack/environment.js', + 'webpack/webpack.common.js', + 'webpack/webpack.dev.js', + 'webpack/webpack.prod.js', + 'webpack/utils.js', + 'webpack/logo-jhipster.png', + ], + }), + ], + sass: [ + clientRootTemplatesBlock({ + templates: ['postcss.config.js'], + }), + ], + reactApp: [ + { + ...clientApplicationTemplatesBlock(), + templates: [ + 'app.tsx', + 'index.tsx', + 'routes.tsx', + 'setup-tests.ts', + 'typings.d.ts', + 'config/constants.ts', + 'config/dayjs.ts', + 'config/axios-interceptor.ts', + 'config/error-middleware.ts', + 'config/logger-middleware.ts', + 'config/notification-middleware.ts', + 'config/store.ts', + 'config/icon-loader.ts', + ], + }, + { + condition: generator => generator.enableTranslation, + ...clientApplicationTemplatesBlock(), + templates: ['config/translation.ts'], + }, + { + condition: generator => generator.communicationSpringWebsocket, + ...clientApplicationTemplatesBlock(), + templates: ['config/websocket-middleware.ts'], + }, + { + ...clientApplicationTemplatesBlock(), + templates: ['app.scss', '_bootstrap-variables.scss'], + }, + ], + reactEntities: [ + { + ...clientApplicationTemplatesBlock(), + templates: ['entities/reducers.ts', 'entities/menu.tsx', 'entities/routes.tsx'], + }, + ], + reactMain: [ + { + ...clientApplicationTemplatesBlock(), + templates: ['modules/home/home.tsx', 'modules/login/logout.tsx'], + }, + { + condition: generator => !generator.authenticationTypeOauth2, + ...clientApplicationTemplatesBlock(), + templates: ['modules/login/login.tsx', 'modules/login/login-modal.tsx'], + }, + { + condition: generator => generator.authenticationTypeOauth2, + ...clientApplicationTemplatesBlock(), + templates: ['modules/login/login-redirect.tsx'], + }, + { + ...clientApplicationTemplatesBlock(), + templates: ['modules/home/home.scss'], + }, + ], + reducers: [ + { + ...clientApplicationTemplatesBlock(), + templates: [ + 'shared/reducers/index.ts', + 'shared/reducers/reducer.utils.ts', + 'shared/reducers/authentication.ts', + 'shared/reducers/application-profile.ts', + ], + }, + { + condition: generator => generator.enableTranslation, + ...clientApplicationTemplatesBlock(), + templates: ['shared/reducers/locale.ts'], + }, + { + condition: generator => generator.authenticationTypeOauth2, + ...clientApplicationTemplatesBlock(), + templates: ['shared/reducers/user-management.ts'], + }, + ], + accountModule: [ + { + condition: generator => generator.generateUserManagement, + ...clientApplicationTemplatesBlock(), + templates: [ + 'modules/account/index.tsx', + 'modules/account/activate/activate.tsx', + 'modules/account/password/password.tsx', + 'modules/account/register/register.tsx', + 'modules/account/password-reset/init/password-reset-init.tsx', + 'modules/account/password-reset/finish/password-reset-finish.tsx', + 'modules/account/settings/settings.tsx', + 'modules/account/register/register.reducer.ts', + 'modules/account/activate/activate.reducer.ts', + 'modules/account/password-reset/password-reset.reducer.ts', + 'modules/account/password/password.reducer.ts', + 'modules/account/settings/settings.reducer.ts', + ], + }, + { + condition: generator => generator.authenticationTypeSession && generator.generateUserManagement, + ...clientApplicationTemplatesBlock(), + templates: ['modules/account/sessions/sessions.tsx', 'modules/account/sessions/sessions.reducer.ts'], + }, + ], + adminModule: [ + { + ...clientApplicationTemplatesBlock(), + templates: [ + 'modules/administration/index.tsx', + 'modules/administration/administration.reducer.ts', + 'modules/administration/docs/docs.tsx', + 'modules/administration/docs/docs.scss', + ], + }, + { + condition: generator => generator.withAdminUi, + ...clientApplicationTemplatesBlock(), + templates: [ + 'modules/administration/configuration/configuration.tsx', + 'modules/administration/health/health.tsx', + 'modules/administration/health/health-modal.tsx', + 'modules/administration/logs/logs.tsx', + 'modules/administration/metrics/metrics.tsx', + ], + }, + { + condition: generator => generator.communicationSpringWebsocket, + ...clientApplicationTemplatesBlock(), + templates: ['modules/administration/tracker/tracker.tsx'], + }, + { + condition: generator => generator.generateUserManagement, + ...clientApplicationTemplatesBlock(), + templates: [ + 'modules/administration/user-management/index.tsx', + 'modules/administration/user-management/user-management.tsx', + 'modules/administration/user-management/user-management-update.tsx', + 'modules/administration/user-management/user-management-detail.tsx', + 'modules/administration/user-management/user-management-delete-dialog.tsx', + 'modules/administration/user-management/user-management.reducer.ts', + ], + }, + { + condition: generator => generator.applicationTypeGateway && generator.serviceDiscoveryAny, + ...clientApplicationTemplatesBlock(), + templates: ['modules/administration/gateway/gateway.tsx'], + }, + ], + reactShared: [ + { + ...clientApplicationTemplatesBlock(), + templates: [ + // layouts + 'shared/layout/footer/footer.tsx', + 'shared/layout/header/header.tsx', + 'shared/layout/header/header-components.tsx', + 'shared/layout/menus/index.ts', + 'shared/layout/menus/admin.tsx', + 'shared/layout/menus/account.tsx', + 'shared/layout/menus/entities.tsx', + 'shared/layout/menus/menu-components.tsx', + 'shared/layout/menus/menu-item.tsx', + 'shared/layout/password/password-strength-bar.tsx', + 'shared/layout/sider/sider.tsx', + // util + 'shared/util/date-utils.ts', + 'shared/util/pagination.constants.ts', + 'shared/util/entity-utils.ts', + // components + 'shared/auth/private-route.tsx', + 'shared/error/error-boundary.tsx', + 'shared/error/error-boundary-routes.tsx', + 'shared/error/page-not-found.tsx', + 'shared/DurationFormat.tsx', + // model + 'shared/model/user.model.ts', + ], + }, + { + condition: generator => generator.enableTranslation, + ...clientApplicationTemplatesBlock(), + templates: ['shared/layout/menus/locale.tsx'], + }, + { + condition: generator => generator.authenticationTypeOauth2, + ...clientApplicationTemplatesBlock(), + templates: ['shared/util/url-utils.ts'], + }, + { + condition: generator => generator.authenticationTypeSession && generator.communicationSpringWebsocket, + ...clientApplicationTemplatesBlock(), + templates: ['shared/util/cookie-utils.ts'], + }, + { + ...clientApplicationTemplatesBlock(), + templates: [ + 'shared/layout/header/header.scss', + 'shared/layout/footer/footer.scss', + 'shared/layout/password/password-strength-bar.scss', + ], + }, + ], + microfrontend: [ + clientRootTemplatesBlock({ + condition: generator => generator.microfrontend, + templates: ['webpack/webpack.microfrontend.js.jhi.react'], + }), + { + condition: generator => generator.microfrontend, + ...clientApplicationTemplatesBlock(), + templates: ['main.tsx', 'shared/error/error-loading.tsx'], + }, + { + condition: generator => generator.microfrontend && generator.applicationTypeGateway, + ...clientSrcTemplatesBlock(), + templates: ['microfrontends/entities-menu.tsx', 'microfrontends/entities-routes.tsx'], + }, + ], + clientTestFw: [ + { + ...clientApplicationTemplatesBlock(), + templates: [ + 'config/axios-interceptor.spec.ts', + 'config/notification-middleware.spec.ts', + 'shared/reducers/application-profile.spec.ts', + 'shared/reducers/authentication.spec.ts', + 'shared/util/entity-utils.spec.ts', + 'shared/auth/private-route.spec.tsx', + 'shared/error/error-boundary.spec.tsx', + 'shared/error/error-boundary-routes.spec.tsx', + 'shared/layout/header/header.spec.tsx', + 'shared/layout/menus/account.spec.tsx', + 'modules/administration/administration.reducer.spec.ts', + ], + }, + { + condition: generator => generator.generateUserManagement, + ...clientApplicationTemplatesBlock(), + templates: [ + // 'spec/app/modules/account/register/register.spec.tsx', + 'modules/account/register/register.reducer.spec.ts', + 'modules/account/activate/activate.reducer.spec.ts', + 'modules/account/password/password.reducer.spec.ts', + 'modules/account/settings/settings.reducer.spec.ts', + ], + }, + { + condition: generator => generator.generateUserManagement, + ...clientApplicationTemplatesBlock(), + templates: ['modules/administration/user-management/user-management.reducer.spec.ts'], + }, + { + condition: generator => generator.enableTranslation, + ...clientApplicationTemplatesBlock(), + templates: ['shared/reducers/locale.spec.ts'], + }, + { + condition: generator => generator.authenticationTypeOauth2, + ...clientApplicationTemplatesBlock(), + templates: ['shared/reducers/user-management.spec.ts'], + }, + ], +}; export default class extends BaseApplicationGenerator { constructor(args, opts, features) { @@ -27,7 +320,10 @@ export default class extends BaseApplicationGenerator { get [BaseApplicationGenerator.WRITING]() { return this.asWritingTaskGroup({ async writingTemplateTask({ application }) { - await writeFiles(application); + await this.writeFiles({ + sections: files, + context: application, + }); }, }); } diff --git a/generators/react/templates/src/main/webapp/app/shared/layout/sider/sider.tsx.ejs b/generators/react/templates/src/main/webapp/app/shared/layout/sider/sider.tsx.ejs index 8a80169..3f86f31 100644 --- a/generators/react/templates/src/main/webapp/app/shared/layout/sider/sider.tsx.ejs +++ b/generators/react/templates/src/main/webapp/app/shared/layout/sider/sider.tsx.ejs @@ -8,9 +8,9 @@ import { translate<% if (enableTranslation) { %>, Storage<% } %> } from 'react-j import LoadingBar from 'react-redux-loading-bar'; import { Layout, Menu } from 'antd'; import { Home } from '../header/header-components'; -import { AdminMenu, EntitiesMenu, AccountMenu<%_ if (enableTranslation) { _%>, LocaleMenu<%_ } _%> } from '../menus'; +import { AdminMenu, AccountMenu<%_ if (enableTranslation) { _%>, LocaleMenu<%_ } _%> } from '../menus'; +import EntitiesMenuItems from 'app/entities/menu'; import { ApartmentOutlined, ClusterOutlined, GlobalOutlined, HomeOutlined, UserOutlined } from '@ant-design/icons'; -import { languages } from 'app/config/translation'; <%_ if (enableTranslation) { _%> import { useAppDispatch } from 'app/config/store'; @@ -50,7 +50,7 @@ const Sider = (props: IHeaderProps) => { <%_ if (enableTranslation) { _%> const dispatch = useAppDispatch(); - + const handleLocaleChange = event => { const langKey = event.target.value; Storage.session.set('locale', langKey); @@ -79,13 +79,13 @@ const Sider = (props: IHeaderProps) => { }> - {EntitiesMenu} + }> {AdminMenu(props.isOpenAPIEnabled)} <%_ if (enableTranslation) { _%> - }> + }> <%_ } _%>