@common-stack/generate-plugin 6.0.8-alpha.3 → 6.0.8-alpha.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +112 -4
- package/docker-releases/backend/package.json +6 -7
- package/docker-releases/frontend/antd/package.json +7 -7
- package/lib/generators/add-backend/files/package.json +1 -1
- package/lib/generators/add-backend/files/webpack.config.js +3 -1
- package/lib/generators/add-frontend/frameworks/antui/context.tsx.template +8 -0
- package/lib/generators/add-frontend/frameworks/antui/entry.client.tsx.template +9 -2
- package/lib/generators/add-frontend/frameworks/antui/entry.server.tsx.template +60 -51
- package/lib/generators/add-frontend/frameworks/antui/root.tsx.template +7 -11
- package/lib/generators/add-frontend/frameworks/chakraui/context.tsx.template +6 -0
- package/lib/generators/add-frontend/frameworks/chakraui/entry.client.tsx.template +23 -15
- package/lib/generators/add-frontend/frameworks/chakraui/entry.server.tsx.template +33 -30
- package/lib/generators/add-frontend/frameworks/chakraui/root.tsx.template +8 -4
- package/lib/generators/add-frontend/templates/package.json +2 -2
- package/lib/generators/add-fullstack/files/package.json +4 -4
- package/lib/generators/add-moleculer/files/config.json +5 -0
- package/lib/generators/add-moleculer/files/package.json +5 -5
- package/lib/generators/add-moleculer/files/rollup.config.mjs +14 -1
- package/package.json +3 -3
- package/src/generators/add-frontend/frameworks/antui/context.tsx.template +8 -0
- package/src/generators/add-frontend/frameworks/antui/entry.client.tsx.template +9 -2
- package/src/generators/add-frontend/frameworks/antui/entry.server.tsx.template +60 -51
- package/src/generators/add-frontend/frameworks/antui/root.tsx.template +7 -11
- package/src/generators/add-frontend/frameworks/chakraui/context.tsx.template +6 -0
- package/src/generators/add-frontend/frameworks/chakraui/entry.client.tsx.template +23 -15
- package/src/generators/add-frontend/frameworks/chakraui/entry.server.tsx.template +33 -30
- package/src/generators/add-frontend/frameworks/chakraui/root.tsx.template +8 -4
- package/src/generators/add-fullstack/files/package.json +4 -4
- package/src/generators/add-moleculer/files/config.json +5 -0
- package/src/generators/add-moleculer/files/package.json +5 -5
- package/src/generators/add-moleculer/files/rollup.config.mjs +14 -1
- package/lib/generators/add-moleculer/files/src/modules/module.ts.template +0 -31
- package/src/generators/add-moleculer/files/src/modules/module.ts.template +0 -31
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,114 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [6.0.8-alpha.30](https://github.com/cdmbase/common-stack/compare/v6.0.8-alpha.29...v6.0.8-alpha.30) (2025-01-27)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @common-stack/generate-plugin
|
|
9
|
+
|
|
10
|
+
## [6.0.8-alpha.29](https://github.com/cdmbase/common-stack/compare/v6.0.8-alpha.28...v6.0.8-alpha.29) (2025-01-27)
|
|
11
|
+
|
|
12
|
+
**Note:** Version bump only for package @common-stack/generate-plugin
|
|
13
|
+
|
|
14
|
+
## [6.0.8-alpha.28](https://github.com/cdmbase/common-stack/compare/v6.0.8-alpha.27...v6.0.8-alpha.28) (2025-01-27)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @common-stack/generate-plugin
|
|
17
|
+
|
|
18
|
+
## [6.0.8-alpha.27](https://github.com/cdmbase/common-stack/compare/v6.0.8-alpha.26...v6.0.8-alpha.27) (2025-01-27)
|
|
19
|
+
|
|
20
|
+
**Note:** Version bump only for package @common-stack/generate-plugin
|
|
21
|
+
|
|
22
|
+
## [6.0.8-alpha.26](https://github.com/cdmbase/common-stack/compare/v6.0.8-alpha.25...v6.0.8-alpha.26) (2025-01-27)
|
|
23
|
+
|
|
24
|
+
**Note:** Version bump only for package @common-stack/generate-plugin
|
|
25
|
+
|
|
26
|
+
## [6.0.8-alpha.25](https://github.com/cdmbase/common-stack/compare/v6.0.8-alpha.24...v6.0.8-alpha.25) (2025-01-27)
|
|
27
|
+
|
|
28
|
+
**Note:** Version bump only for package @common-stack/generate-plugin
|
|
29
|
+
|
|
30
|
+
## [6.0.8-alpha.24](https://github.com/cdmbase/common-stack/compare/v6.0.8-alpha.23...v6.0.8-alpha.24) (2025-01-27)
|
|
31
|
+
|
|
32
|
+
**Note:** Version bump only for package @common-stack/generate-plugin
|
|
33
|
+
|
|
34
|
+
## [6.0.8-alpha.23](https://github.com/cdmbase/common-stack/compare/v6.0.8-alpha.22...v6.0.8-alpha.23) (2025-01-22)
|
|
35
|
+
|
|
36
|
+
**Note:** Version bump only for package @common-stack/generate-plugin
|
|
37
|
+
|
|
38
|
+
## [6.0.8-alpha.22](https://github.com/cdmbase/common-stack/compare/v6.0.8-alpha.21...v6.0.8-alpha.22) (2025-01-20)
|
|
39
|
+
|
|
40
|
+
**Note:** Version bump only for package @common-stack/generate-plugin
|
|
41
|
+
|
|
42
|
+
## [6.0.8-alpha.21](https://github.com/cdmbase/common-stack/compare/v6.0.8-alpha.20...v6.0.8-alpha.21) (2025-01-19)
|
|
43
|
+
|
|
44
|
+
**Note:** Version bump only for package @common-stack/generate-plugin
|
|
45
|
+
|
|
46
|
+
## [6.0.8-alpha.20](https://github.com/cdmbase/common-stack/compare/v6.0.8-alpha.19...v6.0.8-alpha.20) (2025-01-17)
|
|
47
|
+
|
|
48
|
+
**Note:** Version bump only for package @common-stack/generate-plugin
|
|
49
|
+
|
|
50
|
+
## [6.0.8-alpha.19](https://github.com/cdmbase/common-stack/compare/v6.0.8-alpha.18...v6.0.8-alpha.19) (2025-01-14)
|
|
51
|
+
|
|
52
|
+
**Note:** Version bump only for package @common-stack/generate-plugin
|
|
53
|
+
|
|
54
|
+
## [6.0.8-alpha.18](https://github.com/cdmbase/common-stack/compare/v6.0.8-alpha.17...v6.0.8-alpha.18) (2025-01-11)
|
|
55
|
+
|
|
56
|
+
**Note:** Version bump only for package @common-stack/generate-plugin
|
|
57
|
+
|
|
58
|
+
## [6.0.8-alpha.17](https://github.com/cdmbase/common-stack/compare/v6.0.8-alpha.16...v6.0.8-alpha.17) (2025-01-08)
|
|
59
|
+
|
|
60
|
+
**Note:** Version bump only for package @common-stack/generate-plugin
|
|
61
|
+
|
|
62
|
+
## [6.0.8-alpha.16](https://github.com/cdmbase/common-stack/compare/v6.0.8-alpha.15...v6.0.8-alpha.16) (2025-01-08)
|
|
63
|
+
|
|
64
|
+
**Note:** Version bump only for package @common-stack/generate-plugin
|
|
65
|
+
|
|
66
|
+
## [6.0.8-alpha.15](https://github.com/cdmbase/common-stack/compare/v6.0.8-alpha.14...v6.0.8-alpha.15) (2025-01-03)
|
|
67
|
+
|
|
68
|
+
**Note:** Version bump only for package @common-stack/generate-plugin
|
|
69
|
+
|
|
70
|
+
## [6.0.8-alpha.14](https://github.com/cdmbase/common-stack/compare/v6.0.8-alpha.13...v6.0.8-alpha.14) (2024-12-30)
|
|
71
|
+
|
|
72
|
+
**Note:** Version bump only for package @common-stack/generate-plugin
|
|
73
|
+
|
|
74
|
+
## [6.0.8-alpha.13](https://github.com/cdmbase/common-stack/compare/v6.0.8-alpha.12...v6.0.8-alpha.13) (2024-12-30)
|
|
75
|
+
|
|
76
|
+
**Note:** Version bump only for package @common-stack/generate-plugin
|
|
77
|
+
|
|
78
|
+
## [6.0.8-alpha.12](https://github.com/cdmbase/common-stack/compare/v6.0.8-alpha.11...v6.0.8-alpha.12) (2024-12-29)
|
|
79
|
+
|
|
80
|
+
**Note:** Version bump only for package @common-stack/generate-plugin
|
|
81
|
+
|
|
82
|
+
## [6.0.8-alpha.11](https://github.com/cdmbase/common-stack/compare/v6.0.8-alpha.10...v6.0.8-alpha.11) (2024-12-29)
|
|
83
|
+
|
|
84
|
+
**Note:** Version bump only for package @common-stack/generate-plugin
|
|
85
|
+
|
|
86
|
+
## [6.0.8-alpha.10](https://github.com/cdmbase/common-stack/compare/v6.0.8-alpha.9...v6.0.8-alpha.10) (2024-12-20)
|
|
87
|
+
|
|
88
|
+
**Note:** Version bump only for package @common-stack/generate-plugin
|
|
89
|
+
|
|
90
|
+
## [6.0.8-alpha.9](https://github.com/cdmbase/common-stack/compare/v6.0.8-alpha.8...v6.0.8-alpha.9) (2024-12-20)
|
|
91
|
+
|
|
92
|
+
**Note:** Version bump only for package @common-stack/generate-plugin
|
|
93
|
+
|
|
94
|
+
## [6.0.8-alpha.8](https://github.com/cdmbase/common-stack/compare/v6.0.8-alpha.7...v6.0.8-alpha.8) (2024-12-19)
|
|
95
|
+
|
|
96
|
+
**Note:** Version bump only for package @common-stack/generate-plugin
|
|
97
|
+
|
|
98
|
+
## [6.0.8-alpha.7](https://github.com/cdmbase/common-stack/compare/v6.0.8-alpha.6...v6.0.8-alpha.7) (2024-12-19)
|
|
99
|
+
|
|
100
|
+
**Note:** Version bump only for package @common-stack/generate-plugin
|
|
101
|
+
|
|
102
|
+
## [6.0.8-alpha.6](https://github.com/cdmbase/common-stack/compare/v6.0.8-alpha.5...v6.0.8-alpha.6) (2024-12-19)
|
|
103
|
+
|
|
104
|
+
**Note:** Version bump only for package @common-stack/generate-plugin
|
|
105
|
+
|
|
106
|
+
## [6.0.8-alpha.5](https://github.com/cdmbase/common-stack/compare/v6.0.8-alpha.4...v6.0.8-alpha.5) (2024-12-19)
|
|
107
|
+
|
|
108
|
+
**Note:** Version bump only for package @common-stack/generate-plugin
|
|
109
|
+
|
|
110
|
+
## [6.0.8-alpha.4](https://github.com/cdmbase/common-stack/compare/v6.0.8-alpha.3...v6.0.8-alpha.4) (2024-12-19)
|
|
111
|
+
|
|
112
|
+
**Note:** Version bump only for package @common-stack/generate-plugin
|
|
113
|
+
|
|
6
114
|
## [6.0.8-alpha.3](https://github.com/cdmbase/common-stack/compare/v6.0.8-alpha.2...v6.0.8-alpha.3) (2024-12-19)
|
|
7
115
|
|
|
8
116
|
**Note:** Version bump only for package @common-stack/generate-plugin
|
|
@@ -253,18 +361,18 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
253
361
|
|
|
254
362
|
### Bug Fixes
|
|
255
363
|
|
|
256
|
-
-
|
|
364
|
+
- **server-stack:** apollo server redis cache ([2ef1df3](https://github.com/cdmbase/common-stack/commit/2ef1df30176616baf9816c47168687577f7aa8ff))
|
|
257
365
|
|
|
258
366
|
### Features
|
|
259
367
|
|
|
260
|
-
-
|
|
368
|
+
- enable docker layer caching ([ce2c742](https://github.com/cdmbase/common-stack/commit/ce2c74271a107d5c73580523a4e1822b80e04c8d))
|
|
261
369
|
|
|
262
370
|
## [6.0.6-alpha.0](https://github.com/cdmbase/common-stack/compare/v0.0.251...v6.0.6-alpha.0) (2024-12-16)
|
|
263
371
|
|
|
264
372
|
### Bug Fixes
|
|
265
373
|
|
|
266
|
-
-
|
|
374
|
+
- **server-stack:** apollo server redis cache ([2ef1df3](https://github.com/cdmbase/common-stack/commit/2ef1df30176616baf9816c47168687577f7aa8ff))
|
|
267
375
|
|
|
268
376
|
### Features
|
|
269
377
|
|
|
270
|
-
-
|
|
378
|
+
- enable docker layer caching ([ce2c742](https://github.com/cdmbase/common-stack/commit/ce2c74271a107d5c73580523a4e1822b80e04c8d))
|
|
@@ -70,12 +70,12 @@
|
|
|
70
70
|
"@cdm-logger/client": "^9.0.3",
|
|
71
71
|
"@cdm-logger/server": "^9.0.3",
|
|
72
72
|
"@cdmbase/graphql-type-uri": "^4.0.0",
|
|
73
|
-
"@common-stack/cache-api-server": "6.0.8-alpha.
|
|
74
|
-
"@common-stack/client-core": "6.0.8-alpha.
|
|
75
|
-
"@common-stack/core": "6.0.8-alpha.
|
|
76
|
-
"@common-stack/server-core": "6.0.8-alpha.
|
|
77
|
-
"@common-stack/server-stack": "6.0.8-alpha.
|
|
78
|
-
"@common-stack/store-mongo": "6.0.8-alpha.
|
|
73
|
+
"@common-stack/cache-api-server": "6.0.8-alpha.29",
|
|
74
|
+
"@common-stack/client-core": "6.0.8-alpha.29",
|
|
75
|
+
"@common-stack/core": "6.0.8-alpha.29",
|
|
76
|
+
"@common-stack/server-core": "6.0.8-alpha.29",
|
|
77
|
+
"@common-stack/server-stack": "6.0.8-alpha.29",
|
|
78
|
+
"@common-stack/store-mongo": "6.0.8-alpha.29",
|
|
79
79
|
"@graphql-tools/links": "~9.0.1",
|
|
80
80
|
"@graphql-tools/schema": "~10.0.6",
|
|
81
81
|
"@graphql-tools/stitch": "~9.2.10",
|
|
@@ -95,7 +95,6 @@
|
|
|
95
95
|
"express": "^4.17.1",
|
|
96
96
|
"graphql": "^16.0.0",
|
|
97
97
|
"graphql-bigint": "^1.0.0",
|
|
98
|
-
"graphql-iso-date": "^3.6.1",
|
|
99
98
|
"graphql-middleware": "^6.1.33",
|
|
100
99
|
"graphql-nats-subscriptions": "^1.5.0",
|
|
101
100
|
"graphql-playground-middleware-express": "^1.7.3",
|
|
@@ -63,13 +63,13 @@
|
|
|
63
63
|
"@apollo/client": "^3.9.0",
|
|
64
64
|
"@cdm-logger/client": "^9.0.3",
|
|
65
65
|
"@cdm-logger/server": "^9.0.3",
|
|
66
|
-
"@common-stack/cache-api-server": "6.0.8-alpha.
|
|
67
|
-
"@common-stack/client-core": "6.0.8-alpha.
|
|
68
|
-
"@common-stack/client-react": "6.0.8-alpha.
|
|
69
|
-
"@common-stack/components-pro": "6.0.8-alpha.
|
|
70
|
-
"@common-stack/core": "6.0.8-alpha.
|
|
71
|
-
"@common-stack/remix-router-redux": "6.0.8-alpha.
|
|
72
|
-
"@common-stack/server-core": "6.0.8-alpha.
|
|
66
|
+
"@common-stack/cache-api-server": "6.0.8-alpha.29",
|
|
67
|
+
"@common-stack/client-core": "6.0.8-alpha.29",
|
|
68
|
+
"@common-stack/client-react": "6.0.8-alpha.29",
|
|
69
|
+
"@common-stack/components-pro": "6.0.8-alpha.29",
|
|
70
|
+
"@common-stack/core": "6.0.8-alpha.29",
|
|
71
|
+
"@common-stack/remix-router-redux": "6.0.8-alpha.29",
|
|
72
|
+
"@common-stack/server-core": "6.0.8-alpha.29",
|
|
73
73
|
"@reduxjs/toolkit": "^2.2.6",
|
|
74
74
|
"@remix-run/express": "~2.10.1",
|
|
75
75
|
"@remix-run/node": "~2.10.1",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"dependencies": {
|
|
63
63
|
"@apollo/client": "^3.9.0",
|
|
64
64
|
"@babel/runtime": "^7.20.1",
|
|
65
|
-
"@common-stack/server-stack": "6.0.8-alpha.
|
|
65
|
+
"@common-stack/server-stack": "6.0.8-alpha.29",
|
|
66
66
|
"@remix-run/node": "~2.10.1",
|
|
67
67
|
"lodash": "^4.17.15",
|
|
68
68
|
"react": "18.2.0"
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
if (process.env.ENV_FILE) {
|
|
2
|
+
require('dotenv').config({ path: process.env.ENV_FILE });
|
|
3
|
+
}
|
|
2
4
|
const webpack = require('webpack');
|
|
3
5
|
const path = require('path');
|
|
4
6
|
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
|
@@ -32,6 +32,7 @@ import clientModules from '@app/frontend-stack-react/modules.js';
|
|
|
32
32
|
import createEmotionCache from '@app/frontend-stack-react/entries/common/createEmotionCache.js';
|
|
33
33
|
// @ts-ignore
|
|
34
34
|
import config from '@app/cde-webconfig.json';
|
|
35
|
+
import { LocaleContext } from './context';
|
|
35
36
|
|
|
36
37
|
const { apolloClient: client, container, serviceFunc } = createClientContainer();
|
|
37
38
|
const { store } = createReduxStore(client, serviceFunc(), container);
|
|
@@ -42,6 +43,12 @@ const cache = createEmotionCache();
|
|
|
42
43
|
(window as any).__remixStore = store;
|
|
43
44
|
removeUniversalPortals((window as any).__SLOT_FILLS__ || []);
|
|
44
45
|
|
|
46
|
+
function LocaleProvider({ children }: any) {
|
|
47
|
+
const locale = (window as any).__LOCALE__ || '';
|
|
48
|
+
|
|
49
|
+
return <LocaleContext.Provider value={locale}>{children}</LocaleContext.Provider>;
|
|
50
|
+
}
|
|
51
|
+
|
|
45
52
|
async function hydrate() {
|
|
46
53
|
if (!i18next.isInitialized && config.i18n.enabled) {
|
|
47
54
|
await i18next
|
|
@@ -66,7 +73,7 @@ async function hydrate() {
|
|
|
66
73
|
document,
|
|
67
74
|
(
|
|
68
75
|
<I18nextProvider i18n={i18next}>
|
|
69
|
-
<
|
|
76
|
+
<LocaleProvider>
|
|
70
77
|
<CacheProvider value={cache}>
|
|
71
78
|
<StyleProvider cache={antCache}>
|
|
72
79
|
<ReduxProvider store={store}>
|
|
@@ -84,7 +91,7 @@ async function hydrate() {
|
|
|
84
91
|
</ReduxProvider>
|
|
85
92
|
</StyleProvider>
|
|
86
93
|
</CacheProvider>
|
|
87
|
-
</
|
|
94
|
+
</LocaleProvider>
|
|
88
95
|
</I18nextProvider>
|
|
89
96
|
) as any,
|
|
90
97
|
);
|
|
@@ -31,6 +31,9 @@ import config from '@app/cde-webconfig.json';
|
|
|
31
31
|
// @ts-ignore
|
|
32
32
|
import createEmotionCache from '@app/frontend-stack-react/entries/common/createEmotionCache';
|
|
33
33
|
import type { IAppLoadContext } from '@common-stack/client-core';
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
import publicEnv from '@src/config/public-config';
|
|
36
|
+
import { LocaleContext } from './context';
|
|
34
37
|
|
|
35
38
|
const ABORT_DELAY = 5_000;
|
|
36
39
|
const antdCache = createAntdCache();
|
|
@@ -41,18 +44,23 @@ class ConstantsTransform extends Transform {
|
|
|
41
44
|
_apolloState: any;
|
|
42
45
|
_reduxState: any;
|
|
43
46
|
_styleSheet: string;
|
|
47
|
+
_lng: string;
|
|
44
48
|
|
|
45
|
-
constructor(fills: string[], apolloState: any, reduxState: any, styleSheet: any) {
|
|
49
|
+
constructor(fills: string[], apolloState: any, reduxState: any, styleSheet: any, lng: string) {
|
|
46
50
|
super();
|
|
47
51
|
this._fills = fills;
|
|
48
52
|
this._apolloState = apolloState;
|
|
49
53
|
this._reduxState = reduxState;
|
|
50
54
|
this._styleSheet = styleSheet;
|
|
55
|
+
this._lng = lng;
|
|
51
56
|
}
|
|
52
57
|
|
|
53
58
|
_transform(chunk, encoding, callback) {
|
|
54
59
|
let transformedChunk = chunk.toString();
|
|
55
60
|
|
|
61
|
+
if (transformedChunk.includes('[__ENV__]')) {
|
|
62
|
+
transformedChunk = transformedChunk.replace('[__ENV__]', JSON.stringify(publicEnv));
|
|
63
|
+
}
|
|
56
64
|
if (transformedChunk.includes('[__APOLLO_STATE__]')) {
|
|
57
65
|
transformedChunk = transformedChunk.replace(
|
|
58
66
|
'[__APOLLO_STATE__]',
|
|
@@ -71,6 +79,9 @@ class ConstantsTransform extends Transform {
|
|
|
71
79
|
if (transformedChunk.includes('[__STYLESHEET__]')) {
|
|
72
80
|
transformedChunk = transformedChunk.replace('[__STYLESHEET__]', this._styleSheet);
|
|
73
81
|
}
|
|
82
|
+
if (transformedChunk.includes('[__LOCALE__]')) {
|
|
83
|
+
transformedChunk = transformedChunk.replace('[__LOCALE__]', `"${this._lng}"`);
|
|
84
|
+
}
|
|
74
85
|
|
|
75
86
|
callback(null, transformedChunk);
|
|
76
87
|
}
|
|
@@ -86,32 +97,9 @@ export default async function handleRequest(
|
|
|
86
97
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
87
98
|
loadContext: IAppLoadContext,
|
|
88
99
|
) {
|
|
89
|
-
const instance = createInstance();
|
|
90
|
-
const lng = await i18next.getLocale(request);
|
|
91
|
-
const ns = i18next.getRouteNamespaces(remixContext);
|
|
92
|
-
|
|
93
|
-
// First, we create a new instance of i18next so every request will have a
|
|
94
|
-
// completely unique instance and not share any state.
|
|
95
|
-
if (config.i18n.enabled) {
|
|
96
|
-
await instance
|
|
97
|
-
.use(initReactI18next) // Tell our instance to use react-i18next
|
|
98
|
-
.use(Backend) // Setup our backend.init({
|
|
99
|
-
.init({
|
|
100
|
-
fallbackLng: config.i18n.fallbackLng,
|
|
101
|
-
defaultNS: config.i18n.defaultNS,
|
|
102
|
-
react: config.i18n.react,
|
|
103
|
-
supportedLngs: config.i18n.supportedLngs,
|
|
104
|
-
lng, // The locale we detected above
|
|
105
|
-
ns, // The namespaces the routes about to render want to use
|
|
106
|
-
backend: {
|
|
107
|
-
loadPath: resolve(config.i18n.backend.loadServerPath),
|
|
108
|
-
},
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
|
|
112
100
|
return isbot(request.headers.get('user-agent') || '')
|
|
113
|
-
? handleBotRequest(request, responseStatusCode, responseHeaders, remixContext, loadContext
|
|
114
|
-
: handleBrowserRequest(request, responseStatusCode, responseHeaders, remixContext, loadContext
|
|
101
|
+
? handleBotRequest(request, responseStatusCode, responseHeaders, remixContext, loadContext)
|
|
102
|
+
: handleBrowserRequest(request, responseStatusCode, responseHeaders, remixContext, loadContext);
|
|
115
103
|
}
|
|
116
104
|
|
|
117
105
|
function handleBotRequest(
|
|
@@ -120,14 +108,11 @@ function handleBotRequest(
|
|
|
120
108
|
responseHeaders: Headers,
|
|
121
109
|
remixContext: EntryContext,
|
|
122
110
|
loadContext: IAppLoadContext,
|
|
123
|
-
i18nInstance: i18next,
|
|
124
111
|
) {
|
|
125
112
|
return new Promise((resolve, reject) => {
|
|
126
113
|
let shellRendered = false;
|
|
127
114
|
const { pipe, abort } = renderToPipeableStream(
|
|
128
|
-
<
|
|
129
|
-
<RemixServer context={remixContext} url={request.url} abortDelay={ABORT_DELAY} />
|
|
130
|
-
</I18nextProvider>,
|
|
115
|
+
<RemixServer context={remixContext} url={request.url} abortDelay={ABORT_DELAY} />,
|
|
131
116
|
{
|
|
132
117
|
onAllReady() {
|
|
133
118
|
shellRendered = true;
|
|
@@ -164,14 +149,36 @@ function handleBotRequest(
|
|
|
164
149
|
});
|
|
165
150
|
}
|
|
166
151
|
|
|
167
|
-
function handleBrowserRequest(
|
|
152
|
+
async function handleBrowserRequest(
|
|
168
153
|
request: Request,
|
|
169
154
|
responseStatusCode: number,
|
|
170
155
|
responseHeaders: Headers,
|
|
171
156
|
remixContext: EntryContext,
|
|
172
157
|
loadContext: IAppLoadContext,
|
|
173
|
-
i18nInstance: i18next,
|
|
174
158
|
) {
|
|
159
|
+
const instance = createInstance();
|
|
160
|
+
const lng = await i18next.getLocale(request);
|
|
161
|
+
const ns = i18next.getRouteNamespaces(remixContext);
|
|
162
|
+
|
|
163
|
+
// First, we create a new instance of i18next so every request will have a
|
|
164
|
+
// completely unique instance and not share any state.
|
|
165
|
+
if (config.i18n.enabled) {
|
|
166
|
+
await instance
|
|
167
|
+
.use(initReactI18next) // Tell our instance to use react-i18next
|
|
168
|
+
.use(Backend) // Setup our backend.init({
|
|
169
|
+
.init({
|
|
170
|
+
fallbackLng: config.i18n.fallbackLng,
|
|
171
|
+
defaultNS: config.i18n.defaultNS,
|
|
172
|
+
react: config.i18n.react,
|
|
173
|
+
supportedLngs: config.i18n.supportedLngs,
|
|
174
|
+
lng, // The locale we detected above
|
|
175
|
+
ns, // The namespaces the routes about to render want to use
|
|
176
|
+
backend: {
|
|
177
|
+
loadPath: resolve(config.i18n.backend.loadServerPath),
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
175
182
|
return new Promise((resolve, reject) => {
|
|
176
183
|
let shellRendered = false;
|
|
177
184
|
const slotFillContext = { fills: {} };
|
|
@@ -190,24 +197,26 @@ function handleBrowserRequest(
|
|
|
190
197
|
|
|
191
198
|
const { pipe, abort } = renderToPipeableStream(
|
|
192
199
|
(
|
|
193
|
-
<I18nextProvider i18n={
|
|
194
|
-
<
|
|
195
|
-
<
|
|
196
|
-
<
|
|
197
|
-
<
|
|
198
|
-
<
|
|
199
|
-
<
|
|
200
|
-
<
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
200
|
+
<I18nextProvider i18n={instance}>
|
|
201
|
+
<LocaleContext.Provider value={lng}>
|
|
202
|
+
<CacheProvider value={cache}>
|
|
203
|
+
<StyleProvider cache={antdCache}>
|
|
204
|
+
<ReduxProvider store={store}>
|
|
205
|
+
<SlotFillProvider context={slotFillContext}>
|
|
206
|
+
<InversifyProvider container={container} modules={clientModules as any}>
|
|
207
|
+
<ApolloProvider client={client}>
|
|
208
|
+
<RemixServer
|
|
209
|
+
context={remixContext}
|
|
210
|
+
url={request.url}
|
|
211
|
+
abortDelay={ABORT_DELAY}
|
|
212
|
+
/>
|
|
213
|
+
</ApolloProvider>
|
|
214
|
+
</InversifyProvider>
|
|
215
|
+
</SlotFillProvider>
|
|
216
|
+
</ReduxProvider>
|
|
217
|
+
</StyleProvider>
|
|
218
|
+
</CacheProvider>
|
|
219
|
+
</LocaleContext.Provider>
|
|
211
220
|
</I18nextProvider>
|
|
212
221
|
) as any,
|
|
213
222
|
{
|
|
@@ -220,7 +229,7 @@ function handleBrowserRequest(
|
|
|
220
229
|
const fills = Object.keys(slotFillContext.fills);
|
|
221
230
|
const styleSheet = extractStyle(antdCache);
|
|
222
231
|
|
|
223
|
-
const transform = new ConstantsTransform(fills, apolloState, reduxState, styleSheet);
|
|
232
|
+
const transform = new ConstantsTransform(fills, apolloState, reduxState, styleSheet, lng);
|
|
224
233
|
|
|
225
234
|
responseHeaders.set('Content-Type', 'text/html');
|
|
226
235
|
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { Links, Meta, Outlet, Scripts, ScrollRestoration, useRouteLoaderData, useRouteError, json } from '@remix-run/react';
|
|
4
|
-
// @ts-ignore
|
|
5
|
-
import publicEnv from '@src/config/public-config';
|
|
6
4
|
import { PluginArea } from '@common-stack/client-react';
|
|
7
5
|
import { subscribeReduxRouter } from '@common-stack/remix-router-redux';
|
|
8
6
|
import { ApplicationErrorHandler } from '@admin-layout/ant-ui';
|
|
@@ -16,7 +14,8 @@ import { useTranslation } from 'react-i18next';
|
|
|
16
14
|
import { i18nextInstance as i18next } from '@app/frontend-stack-react/i18n-localization/i18next.server.js';
|
|
17
15
|
// @ts-ignore
|
|
18
16
|
import { ErrorBoundary } from '@app/frontend-stack-react/entries/antui/components/ErrorBoundary';
|
|
19
|
-
|
|
17
|
+
import { LocaleContext } from './context';
|
|
18
|
+
/*
|
|
20
19
|
export const loader = async ({ request }) => {
|
|
21
20
|
const locale = await i18next.getLocale(request);
|
|
22
21
|
return json({
|
|
@@ -24,7 +23,7 @@ export const loader = async ({ request }) => {
|
|
|
24
23
|
locale,
|
|
25
24
|
});
|
|
26
25
|
};
|
|
27
|
-
|
|
26
|
+
*/
|
|
28
27
|
export const handle = {
|
|
29
28
|
i18n: 'common',
|
|
30
29
|
};
|
|
@@ -34,8 +33,8 @@ export function shouldRevalidate(params: any) {
|
|
|
34
33
|
}
|
|
35
34
|
|
|
36
35
|
export function Layout({ children }: { children: React.ReactNode }) {
|
|
37
|
-
const data = useRouteLoaderData<{ locale: any }>('root');
|
|
38
|
-
const locale =
|
|
36
|
+
// const data = useRouteLoaderData<{ locale: any }>('root');
|
|
37
|
+
const locale: any = React.useContext(LocaleContext);
|
|
39
38
|
|
|
40
39
|
const { i18n } = useTranslation();
|
|
41
40
|
|
|
@@ -49,11 +48,7 @@ export function Layout({ children }: { children: React.ReactNode }) {
|
|
|
49
48
|
if (typeof window === 'undefined') {
|
|
50
49
|
return (
|
|
51
50
|
<>
|
|
52
|
-
<script
|
|
53
|
-
dangerouslySetInnerHTML={{
|
|
54
|
-
__html: `window.__ENV__ = ${JSON.stringify((data as any)?.__ENV__)}`,
|
|
55
|
-
}}
|
|
56
|
-
/>
|
|
51
|
+
<script>window.__ENV__=[__ENV__]</script>
|
|
57
52
|
<script
|
|
58
53
|
src="https://cdnjs.cloudflare.com/ajax/libs/reflect-metadata/0.1.13/Reflect.min.js"
|
|
59
54
|
integrity="sha512-jvbPH2TH5BSZumEfOJZn9IV+5bSwwN+qG4dvthYe3KCGC3/9HmxZ4phADbt9Pfcp+XSyyfc2vGZ/RMsSUZ9tbQ=="
|
|
@@ -68,6 +63,7 @@ export function Layout({ children }: { children: React.ReactNode }) {
|
|
|
68
63
|
__html: `if (global === undefined) { var global = window; }`,
|
|
69
64
|
}}
|
|
70
65
|
/>
|
|
66
|
+
<script>window.__LOCALE__=[__LOCALE__]</script>
|
|
71
67
|
</>
|
|
72
68
|
);
|
|
73
69
|
}
|
|
@@ -18,3 +18,9 @@ export interface ClientStyleContextData {
|
|
|
18
18
|
export const ClientStyleContext = createContext<ClientStyleContextData | null>(
|
|
19
19
|
null,
|
|
20
20
|
);
|
|
21
|
+
|
|
22
|
+
export interface LocaleContextData {
|
|
23
|
+
locale: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const LocaleContext = createContext<LocaleContextData | null>(null);
|
|
@@ -27,8 +27,7 @@ import Backend from 'i18next-http-backend';
|
|
|
27
27
|
import { getInitialNamespaces } from 'remix-i18next/client';
|
|
28
28
|
import config from '@app/cde-webconfig.json';
|
|
29
29
|
// @ts-ignore
|
|
30
|
-
|
|
31
|
-
import { ClientStyleContext } from './context';
|
|
30
|
+
import { ClientStyleContext, LocaleContext } from './context';
|
|
32
31
|
|
|
33
32
|
const { apolloClient: client, container, serviceFunc } = createClientContainer();
|
|
34
33
|
const { store } = createReduxStore(client, serviceFunc(), container);
|
|
@@ -60,6 +59,13 @@ function ClientCacheProvider({ children }: ClientCacheProviderProps) {
|
|
|
60
59
|
);
|
|
61
60
|
}
|
|
62
61
|
|
|
62
|
+
function LocaleProvider({ children }: ClientCacheProviderProps) {
|
|
63
|
+
const el = (document as any).querySelector('html');
|
|
64
|
+
const locale = el?.getAttribute('lng') || '';
|
|
65
|
+
|
|
66
|
+
return <LocaleContext.Provider value={locale}>{children}</LocaleContext.Provider>;
|
|
67
|
+
}
|
|
68
|
+
|
|
63
69
|
async function hydrate() {
|
|
64
70
|
if (!i18next.isInitialized && config.i18n.enabled) {
|
|
65
71
|
await i18next
|
|
@@ -83,19 +89,21 @@ async function hydrate() {
|
|
|
83
89
|
document.getElementById('root')!,
|
|
84
90
|
// <StrictMode>
|
|
85
91
|
<I18nextProvider i18n={i18next}>
|
|
86
|
-
<
|
|
87
|
-
<
|
|
88
|
-
<
|
|
89
|
-
<
|
|
90
|
-
<
|
|
91
|
-
<
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
92
|
+
<LocaleProvider>
|
|
93
|
+
<ClientCacheProvider>
|
|
94
|
+
<ApolloProvider client={client}>
|
|
95
|
+
<ReduxProvider store={store}>
|
|
96
|
+
<SlotFillProvider>
|
|
97
|
+
<InversifyProvider container={container} modules={clientModules}>
|
|
98
|
+
<PersistGate loading={null} persistor={persistor}>
|
|
99
|
+
{() => <RemixBrowser />}
|
|
100
|
+
</PersistGate>
|
|
101
|
+
</InversifyProvider>
|
|
102
|
+
</SlotFillProvider>
|
|
103
|
+
</ReduxProvider>
|
|
104
|
+
</ApolloProvider>
|
|
105
|
+
</ClientCacheProvider>
|
|
106
|
+
</LocaleProvider>
|
|
99
107
|
</I18nextProvider>,
|
|
100
108
|
// </StrictMode>,
|
|
101
109
|
);
|