create-catalyst-app-internal 0.0.1-beta.9 → 0.0.2-canary.2
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/Readme.md +56 -0
- package/codemod/new-route/index.js +98 -0
- package/codemod/new-route/template.js +119 -0
- package/codemod/new-route/transformers/createReducer.js +38 -0
- package/codemod/new-route/transformers/createRoute.js +33 -0
- package/codemod/new-route/utils.js +90 -0
- package/license +10 -0
- package/package.json +7 -8
- package/scripts/cli.cjs +58 -37
- package/templates/common/.eslintignore +1 -0
- package/templates/common/.eslintrc +28 -0
- package/templates/common/README.md +2 -2
- package/templates/common/api.js +12 -23
- package/templates/common/client/styles.js +1 -12
- package/templates/common/config/config.json +2 -23
- package/templates/common/public/favicon.ico +0 -0
- package/templates/common/server/{document.js → document.jsx} +2 -4
- package/templates/common/server/index.js +1 -0
- package/templates/common/server/server.js +13 -1
- package/templates/common/src/js/containers/Home/{Home.js → Home.jsx} +1 -1
- package/templates/common/src/js/routes/index.jsx +11 -0
- package/templates/common/src/static/css/resources/index.scss +1 -0
- package/templates/none-js/client/index.jsx +18 -0
- package/templates/none-js/package.json +11 -5
- package/templates/{redux-js/src/js/containers/App/index.js → none-js/src/js/containers/App/index.jsx} +2 -2
- package/templates/none-js/src/js/routes/utils.jsx +54 -0
- package/templates/redux-js/client/index.jsx +23 -0
- package/templates/redux-js/package.json +11 -5
- package/templates/{none-js/src/js/containers/App/index.js → redux-js/src/js/containers/App/index.jsx} +2 -2
- package/templates/redux-js/src/js/containers/App/reducer.js +1 -2
- package/templates/redux-js/src/js/routes/utils.jsx +54 -0
- package/templates/redux-js/src/js/store/index.js +2 -2
- package/templates/rtk-js/client/index.jsx +24 -0
- package/templates/rtk-js/package.json +11 -5
- package/templates/rtk-js/src/js/containers/App/{index.js → index.jsx} +2 -2
- package/templates/rtk-js/src/js/containers/App/reducer.js +1 -1
- package/templates/rtk-js/src/js/routes/utils.jsx +54 -0
- package/templates/rtk-js/src/js/store/index.js +2 -2
- package/templates/common/.babelrc +0 -26
- package/templates/common/src/js/routes/index.js +0 -17
- package/templates/common/src/js/routes/utils.js +0 -29
- package/templates/none-js/client/index.js +0 -23
- package/templates/redux-js/client/index.js +0 -28
- package/templates/rtk-js/client/index.js +0 -28
- /package/templates/common/src/js/containers/Home/{Home.scss → Home.module.scss} +0 -0
package/templates/common/api.js
CHANGED
|
@@ -1,27 +1,16 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
let finalUrl = baseURL + url
|
|
1
|
+
const fetchFunction = (url, options) => {
|
|
2
|
+
let baseURL = process.env.API_URL
|
|
3
|
+
let finalUrl = baseURL + url
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
// Request Interceptor - modify request here
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const parsedResponse = await response.json()
|
|
15
|
-
// Response Interceptor - you can modify response here
|
|
16
|
-
return parsedResponse
|
|
7
|
+
return fetch(finalUrl, options)
|
|
8
|
+
.then(response => {
|
|
9
|
+
return response.json().then(parsedResponse => {
|
|
10
|
+
// Response Interceptor - modify response here
|
|
11
|
+
return parsedResponse
|
|
12
|
+
})
|
|
17
13
|
})
|
|
18
|
-
}
|
|
19
|
-
return {
|
|
20
|
-
get: fetchFunction,
|
|
21
|
-
post: fetchFunction,
|
|
22
|
-
delete: fetchFunction,
|
|
23
|
-
patch: fetchFunction,
|
|
24
|
-
put: fetchFunction,
|
|
25
|
-
}
|
|
26
14
|
}
|
|
27
|
-
|
|
15
|
+
|
|
16
|
+
export default fetchFunction
|
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
* Anything imported in here will either be added to the vendor CSS chunk, or
|
|
4
|
-
* the main app CSS chunk. Where they will go depends on its location or its
|
|
5
|
-
* extension.
|
|
6
|
-
*
|
|
7
|
-
* Files will be added to the vendor.css chunk if:
|
|
8
|
-
* - they are located inside `node_modules`, or
|
|
9
|
-
* - they are plain .css files.
|
|
10
|
-
* Otherwise, files will be added to the main app.css chunk.
|
|
11
|
-
*/
|
|
1
|
+
// Include initial base styles. Global styles will come here.
|
|
12
2
|
|
|
13
|
-
// Include initial base styles.
|
|
14
3
|
import "@css/base/index.scss"
|
|
@@ -5,29 +5,8 @@
|
|
|
5
5
|
"WEBPACK_DEV_SERVER_PORT": 3006,
|
|
6
6
|
"BUILD_OUTPUT_PATH": "build",
|
|
7
7
|
"PUBLIC_STATIC_ASSET_PATH": "/assets/",
|
|
8
|
-
"PUBLIC_STATIC_ASSET_URL": "http://localhost:
|
|
9
|
-
"NODE_ENV": "development",
|
|
10
|
-
"BUILD_ENV": "localBuild",
|
|
8
|
+
"PUBLIC_STATIC_ASSET_URL": "http://localhost:3005",
|
|
11
9
|
"API_URL": "",
|
|
12
10
|
"ANALYZE_BUNDLE": false,
|
|
13
|
-
"CLIENT_ENV_VARIABLES": [
|
|
14
|
-
"NODE_SERVER_HOSTNAME",
|
|
15
|
-
"NODE_SERVER_PORT",
|
|
16
|
-
"WEBPACK_DEV_SERVER_HOSTNAME",
|
|
17
|
-
"WEBPACK_DEV_SERVER_PORT",
|
|
18
|
-
"BUILD_OUTPUT_PATH",
|
|
19
|
-
"PUBLIC_STATIC_ASSET_PATH",
|
|
20
|
-
"PUBLIC_STATIC_ASSET_URL",
|
|
21
|
-
"NODE_ENV",
|
|
22
|
-
"BUILD_ENV",
|
|
23
|
-
"API_URL",
|
|
24
|
-
"ANALYZE_BUNDLE",
|
|
25
|
-
"ENABLE_DEBUG_LOGS",
|
|
26
|
-
"ENABLE_FILE_LOGGING",
|
|
27
|
-
"ENABLE_CONSOLE_LOGGING",
|
|
28
|
-
"ANALYZE_BUNDLE",
|
|
29
|
-
"ENABLE_DEBUG_LOGS",
|
|
30
|
-
"ENABLE_FILE_LOGGING",
|
|
31
|
-
"ENABLE_CONSOLE_LOGGING"
|
|
32
|
-
]
|
|
11
|
+
"CLIENT_ENV_VARIABLES": ["API_URL"]
|
|
33
12
|
}
|
|
Binary file
|
|
@@ -3,10 +3,8 @@ import { Head, Body } from "catalyst-core-internal"
|
|
|
3
3
|
|
|
4
4
|
function Document(props) {
|
|
5
5
|
return (
|
|
6
|
-
<html lang=
|
|
7
|
-
<Head {...props}>
|
|
8
|
-
<meta charset="final-order" />
|
|
9
|
-
</Head>
|
|
6
|
+
<html lang="en">
|
|
7
|
+
<Head {...props}></Head>
|
|
10
8
|
<Body {...props} />
|
|
11
9
|
</html>
|
|
12
10
|
)
|
|
@@ -1 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import express from "express"
|
|
2
|
+
import path from "path"
|
|
3
|
+
import { fileURLToPath } from "node:url"
|
|
4
|
+
import { dirname } from "node:path"
|
|
5
|
+
|
|
6
|
+
const __filename = fileURLToPath(import.meta.url)
|
|
7
|
+
const __dirname = dirname(__filename)
|
|
8
|
+
|
|
9
|
+
// Server middlewares are added here.
|
|
10
|
+
|
|
11
|
+
export function addMiddlewares(app) {
|
|
12
|
+
app.use("/favicon.ico", express.static(path.join(__dirname, "../public/favicon.ico")))
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import "./variables.scss";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from "react"
|
|
2
|
+
import "./styles"
|
|
3
|
+
import { hydrateRoot } from "react-dom/client"
|
|
4
|
+
import { RouterProvider } from "catalyst-core-internal"
|
|
5
|
+
import clientRouter from "catalyst-core-internal/router/ClientRouter"
|
|
6
|
+
|
|
7
|
+
const { __ROUTER_INITIAL_DATA__: routerInitialData } = window
|
|
8
|
+
|
|
9
|
+
const router = clientRouter({ routerInitialState: routerInitialData })
|
|
10
|
+
|
|
11
|
+
const Application = (
|
|
12
|
+
<React.StrictMode>
|
|
13
|
+
<RouterProvider router={router} />
|
|
14
|
+
</React.StrictMode>
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
const container = document.getElementById("app")
|
|
18
|
+
hydrateRoot(container, Application)
|
|
@@ -4,7 +4,10 @@
|
|
|
4
4
|
"scripts": {
|
|
5
5
|
"start": "catalyst start",
|
|
6
6
|
"build": "catalyst build",
|
|
7
|
-
"serve": "catalyst serve"
|
|
7
|
+
"serve": "catalyst serve",
|
|
8
|
+
"lint": "eslint .",
|
|
9
|
+
"devBuild": "catalyst devBuild",
|
|
10
|
+
"devServe": "catalyst devServe"
|
|
8
11
|
},
|
|
9
12
|
"_moduleAliases": {
|
|
10
13
|
"@api": "api.js",
|
|
@@ -14,9 +17,12 @@
|
|
|
14
17
|
"@css": "src/static/css",
|
|
15
18
|
"@routes": "src/js/routes/"
|
|
16
19
|
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"eslint": "^8.26.0",
|
|
22
|
+
"eslint-plugin-react": "^7.34.1",
|
|
23
|
+
"eslint-plugin-react-hooks": "^4.6.0"
|
|
24
|
+
},
|
|
17
25
|
"dependencies": {
|
|
18
|
-
"
|
|
19
|
-
"@tata1mg/router": "^0.0.1-beta.0",
|
|
20
|
-
"catalyst-core-internal": "^0.0.1-beta.3"
|
|
26
|
+
"catalyst-core-internal": "^0.0.2-canary.4"
|
|
21
27
|
}
|
|
22
|
-
}
|
|
28
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from "react"
|
|
2
|
-
import { Outlet } from "
|
|
2
|
+
import { Outlet } from "catalyst-core-internal"
|
|
3
3
|
|
|
4
4
|
const App = () => {
|
|
5
5
|
return (
|
|
@@ -9,7 +9,7 @@ const App = () => {
|
|
|
9
9
|
)
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
App.serverSideFunction = (
|
|
12
|
+
App.serverSideFunction = () => {
|
|
13
13
|
return new Promise((resolve) => resolve())
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import React, { Suspense } from "react"
|
|
2
|
+
import { RouterDataProvider, MetaTag } from "catalyst-core-internal"
|
|
3
|
+
import App from "@containers/App/index.jsx"
|
|
4
|
+
import routes from "./index.jsx"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Making the routes array compatible with the format accepted by createBrowserRouter
|
|
8
|
+
* API on the client side
|
|
9
|
+
* https://reactrouter.com/en/main/routers/create-browser-router
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export const preparedRoutes = ({ routerInitialState }) => {
|
|
13
|
+
const getPreparedRoutes = (routes) => {
|
|
14
|
+
return routes.map((route, index) => {
|
|
15
|
+
let element = null
|
|
16
|
+
const Component = route.component
|
|
17
|
+
|
|
18
|
+
if (typeof Component === "object" && route.fallback) {
|
|
19
|
+
element = (
|
|
20
|
+
<Suspense fallback={route.fallback}>
|
|
21
|
+
<Component key={index} />
|
|
22
|
+
</Suspense>
|
|
23
|
+
)
|
|
24
|
+
} else {
|
|
25
|
+
element = <Component key={index} />
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const routeToRender = {
|
|
29
|
+
...route,
|
|
30
|
+
element: element,
|
|
31
|
+
}
|
|
32
|
+
if (route.children) {
|
|
33
|
+
routeToRender.children = getPreparedRoutes(route.children)
|
|
34
|
+
}
|
|
35
|
+
return routeToRender
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return [
|
|
40
|
+
{
|
|
41
|
+
element: (
|
|
42
|
+
<RouterDataProvider config={{}} initialState={routerInitialState}>
|
|
43
|
+
<MetaTag />
|
|
44
|
+
<App />
|
|
45
|
+
</RouterDataProvider>
|
|
46
|
+
),
|
|
47
|
+
children: getPreparedRoutes(routes),
|
|
48
|
+
},
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const getRoutes = () => {
|
|
53
|
+
return routes
|
|
54
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from "react"
|
|
2
|
+
import "./styles"
|
|
3
|
+
import { hydrateRoot } from "react-dom/client"
|
|
4
|
+
import { Provider } from "react-redux"
|
|
5
|
+
import { RouterProvider } from "catalyst-core-internal"
|
|
6
|
+
import clientRouter from "catalyst-core-internal/router/ClientRouter"
|
|
7
|
+
import configureStore from "@store"
|
|
8
|
+
|
|
9
|
+
const { __ROUTER_INITIAL_DATA__: routerInitialData, __INITIAL_STATE__ } = window
|
|
10
|
+
const store = configureStore(__INITIAL_STATE__ || {})
|
|
11
|
+
|
|
12
|
+
const router = clientRouter({ store, routerInitialState: routerInitialData })
|
|
13
|
+
|
|
14
|
+
const Application = (
|
|
15
|
+
<Provider store={store} serverState={__INITIAL_STATE__}>
|
|
16
|
+
<React.StrictMode>
|
|
17
|
+
<RouterProvider router={router} />
|
|
18
|
+
</React.StrictMode>
|
|
19
|
+
</Provider>
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
const container = document.getElementById("app")
|
|
23
|
+
hydrateRoot(container, Application)
|
|
@@ -4,7 +4,10 @@
|
|
|
4
4
|
"scripts": {
|
|
5
5
|
"start": "catalyst start",
|
|
6
6
|
"build": "catalyst build",
|
|
7
|
-
"serve": "catalyst serve"
|
|
7
|
+
"serve": "catalyst serve",
|
|
8
|
+
"lint": "eslint .",
|
|
9
|
+
"devBuild": "catalyst devBuild",
|
|
10
|
+
"devServe": "catalyst devServe"
|
|
8
11
|
},
|
|
9
12
|
"_moduleAliases": {
|
|
10
13
|
"@api": "api.js",
|
|
@@ -16,10 +19,13 @@
|
|
|
16
19
|
"@store": "src/js/store/index.js"
|
|
17
20
|
},
|
|
18
21
|
"dependencies": {
|
|
19
|
-
"@loadable/component": "^5.16.3",
|
|
20
|
-
"@tata1mg/router": "^0.0.1-beta.0",
|
|
21
|
-
"catalyst-core-internal": "^0.0.1-beta.3",
|
|
22
22
|
"@reduxjs/toolkit": "1.9.3",
|
|
23
|
+
"catalyst-core-internal": "^0.0.2-canary.4",
|
|
23
24
|
"react-redux": "^8.1.3"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"eslint": "^8.26.0",
|
|
28
|
+
"eslint-plugin-react": "^7.34.1",
|
|
29
|
+
"eslint-plugin-react-hooks": "^4.6.0"
|
|
24
30
|
}
|
|
25
|
-
}
|
|
31
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from "react"
|
|
2
|
-
import { Outlet } from "
|
|
2
|
+
import { Outlet } from "catalyst-core-internal"
|
|
3
3
|
|
|
4
4
|
const App = () => {
|
|
5
5
|
return (
|
|
@@ -9,7 +9,7 @@ const App = () => {
|
|
|
9
9
|
)
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
App.serverSideFunction = (
|
|
12
|
+
App.serverSideFunction = () => {
|
|
13
13
|
return new Promise((resolve) => resolve())
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ShellActions } from "./actions"
|
|
1
|
+
import { ShellActions } from "./actions.js"
|
|
2
2
|
|
|
3
3
|
export const defaultState = {
|
|
4
4
|
testActionDispatched: false,
|
|
@@ -17,4 +17,3 @@ export const shellReducer = (state = defaultState, action) => {
|
|
|
17
17
|
return state
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
-
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import React, { Suspense } from "react"
|
|
2
|
+
import { RouterDataProvider, MetaTag } from "catalyst-core-internal"
|
|
3
|
+
import App from "@containers/App/index.jsx"
|
|
4
|
+
import routes from "./index.jsx"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Making the routes array compatible with the format accepted by createBrowserRouter
|
|
8
|
+
* API on the client side
|
|
9
|
+
* https://reactrouter.com/en/main/routers/create-browser-router
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export const preparedRoutes = ({ store, routerInitialState }) => {
|
|
13
|
+
const getPreparedRoutes = (routes) => {
|
|
14
|
+
return routes.map((route, index) => {
|
|
15
|
+
let element = null
|
|
16
|
+
const Component = route.component
|
|
17
|
+
|
|
18
|
+
if (typeof Component === "object" && route.fallback) {
|
|
19
|
+
element = (
|
|
20
|
+
<Suspense fallback={route.fallback}>
|
|
21
|
+
<Component key={index} />
|
|
22
|
+
</Suspense>
|
|
23
|
+
)
|
|
24
|
+
} else {
|
|
25
|
+
element = <Component key={index} />
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const routeToRender = {
|
|
29
|
+
...route,
|
|
30
|
+
element: element,
|
|
31
|
+
}
|
|
32
|
+
if (route.children) {
|
|
33
|
+
routeToRender.children = getPreparedRoutes(route.children)
|
|
34
|
+
}
|
|
35
|
+
return routeToRender
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return [
|
|
40
|
+
{
|
|
41
|
+
element: (
|
|
42
|
+
<RouterDataProvider config={{}} initialState={routerInitialState} fetcherArgs={{ store }}>
|
|
43
|
+
<MetaTag />
|
|
44
|
+
<App />
|
|
45
|
+
</RouterDataProvider>
|
|
46
|
+
),
|
|
47
|
+
children: getPreparedRoutes(routes),
|
|
48
|
+
},
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const getRoutes = () => {
|
|
53
|
+
return routes
|
|
54
|
+
}
|
|
@@ -6,11 +6,11 @@ import fetchInstance from "@api"
|
|
|
6
6
|
/**
|
|
7
7
|
* Function that initializes the store with the initialstate and adds middlewares that can be used during action dispatch
|
|
8
8
|
* @param {object} initialState Default state
|
|
9
|
-
* @param {object} request Request object that we recieve on server, this is only recieved when store is
|
|
9
|
+
* @param {object} request Request object that we recieve on server, this is only recieved when store is initialized on the server.
|
|
10
10
|
* @return {object} The store itself
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
const configureStore = (initialState
|
|
13
|
+
const configureStore = (initialState) => {
|
|
14
14
|
const api = fetchInstance
|
|
15
15
|
const store = createStore({
|
|
16
16
|
reducer: combineReducers({ shellReducer }),
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
import React from "react"
|
|
3
|
+
import "./styles"
|
|
4
|
+
import { hydrateRoot } from "react-dom/client"
|
|
5
|
+
import { Provider } from "react-redux"
|
|
6
|
+
import { RouterProvider } from "catalyst-core-internal"
|
|
7
|
+
import clientRouter from "catalyst-core-internal/router/ClientRouter"
|
|
8
|
+
import configureStore from "@store"
|
|
9
|
+
|
|
10
|
+
const { __ROUTER_INITIAL_DATA__: routerInitialData, __INITIAL_STATE__ } = window
|
|
11
|
+
const store = configureStore(__INITIAL_STATE__ || {})
|
|
12
|
+
|
|
13
|
+
const router = clientRouter({ store, routerInitialState: routerInitialData })
|
|
14
|
+
|
|
15
|
+
const Application = (
|
|
16
|
+
<Provider store={store} serverState={__INITIAL_STATE__}>
|
|
17
|
+
<React.StrictMode>
|
|
18
|
+
<RouterProvider router={router} />
|
|
19
|
+
</React.StrictMode>
|
|
20
|
+
</Provider>
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
const container = document.getElementById("app")
|
|
24
|
+
hydrateRoot(container, Application)
|
|
@@ -4,7 +4,10 @@
|
|
|
4
4
|
"scripts": {
|
|
5
5
|
"start": "catalyst start",
|
|
6
6
|
"build": "catalyst build",
|
|
7
|
-
"serve": "catalyst serve"
|
|
7
|
+
"serve": "catalyst serve",
|
|
8
|
+
"lint": "eslint .",
|
|
9
|
+
"devBuild": "catalyst devBuild",
|
|
10
|
+
"devServe": "catalyst devServe"
|
|
8
11
|
},
|
|
9
12
|
"_moduleAliases": {
|
|
10
13
|
"@api": "api.js",
|
|
@@ -16,10 +19,13 @@
|
|
|
16
19
|
"@store": "src/js/store/index.js"
|
|
17
20
|
},
|
|
18
21
|
"dependencies": {
|
|
19
|
-
"@loadable/component": "^5.16.3",
|
|
20
|
-
"@tata1mg/router": "^0.0.1-beta.0",
|
|
21
|
-
"catalyst-core-internal": "^0.0.1-beta.3",
|
|
22
22
|
"@reduxjs/toolkit": "1.9.3",
|
|
23
|
+
"catalyst-core-internal": "^0.0.2-canary.4",
|
|
23
24
|
"react-redux": "^8.1.3"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"eslint": "^8.26.0",
|
|
28
|
+
"eslint-plugin-react": "^7.34.1",
|
|
29
|
+
"eslint-plugin-react-hooks": "^4.6.0"
|
|
24
30
|
}
|
|
25
|
-
}
|
|
31
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from "react"
|
|
2
|
-
import { Outlet } from "
|
|
2
|
+
import { Outlet } from "catalyst-core-internal"
|
|
3
3
|
|
|
4
4
|
const App = () => {
|
|
5
5
|
return (
|
|
@@ -9,7 +9,7 @@ const App = () => {
|
|
|
9
9
|
)
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
App.serverSideFunction = (
|
|
12
|
+
App.serverSideFunction = () => {
|
|
13
13
|
return new Promise((resolve) => resolve())
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import React, { Suspense } from "react"
|
|
2
|
+
import { RouterDataProvider, MetaTag } from "catalyst-core-internal"
|
|
3
|
+
import App from "@containers/App/index.jsx"
|
|
4
|
+
import routes from "./index.jsx"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Making the routes array compatible with the format accepted by createBrowserRouter
|
|
8
|
+
* API on the client side
|
|
9
|
+
* https://reactrouter.com/en/main/routers/create-browser-router
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export const preparedRoutes = ({ store, routerInitialState }) => {
|
|
13
|
+
const getPreparedRoutes = (routes) => {
|
|
14
|
+
return routes.map((route, index) => {
|
|
15
|
+
let element = null
|
|
16
|
+
const Component = route.component
|
|
17
|
+
|
|
18
|
+
if (typeof Component === "object" && route.fallback) {
|
|
19
|
+
element = (
|
|
20
|
+
<Suspense fallback={route.fallback}>
|
|
21
|
+
<Component key={index} />
|
|
22
|
+
</Suspense>
|
|
23
|
+
)
|
|
24
|
+
} else {
|
|
25
|
+
element = <Component key={index} />
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const routeToRender = {
|
|
29
|
+
...route,
|
|
30
|
+
element: element,
|
|
31
|
+
}
|
|
32
|
+
if (route.children) {
|
|
33
|
+
routeToRender.children = getPreparedRoutes(route.children)
|
|
34
|
+
}
|
|
35
|
+
return routeToRender
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return [
|
|
40
|
+
{
|
|
41
|
+
element: (
|
|
42
|
+
<RouterDataProvider config={{}} initialState={routerInitialState} fetcherArgs={{ store }}>
|
|
43
|
+
<MetaTag />
|
|
44
|
+
<App />
|
|
45
|
+
</RouterDataProvider>
|
|
46
|
+
),
|
|
47
|
+
children: getPreparedRoutes(routes),
|
|
48
|
+
},
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const getRoutes = () => {
|
|
53
|
+
return routes
|
|
54
|
+
}
|
|
@@ -6,11 +6,11 @@ import fetchInstance from "@api"
|
|
|
6
6
|
/**
|
|
7
7
|
* Function that initializes the store with the initialstate and adds middlewares that can be used during action dispatch
|
|
8
8
|
* @param {object} initialState Default state
|
|
9
|
-
* @param {object} request Request object that we recieve on server, this is only recieved when store is
|
|
9
|
+
* @param {object} request Request object that we recieve on server, this is only recieved when store is initialized on the server.
|
|
10
10
|
* @return {object} The store itself
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
const configureStore = (initialState
|
|
13
|
+
const configureStore = (initialState) => {
|
|
14
14
|
const api = fetchInstance
|
|
15
15
|
const store = createStore({
|
|
16
16
|
reducer: combineReducers({ shellReducer }),
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"presets": [
|
|
3
|
-
[
|
|
4
|
-
"@babel/preset-env",
|
|
5
|
-
{
|
|
6
|
-
"targets": {
|
|
7
|
-
"node": "current"
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
],
|
|
11
|
-
"@babel/preset-react"
|
|
12
|
-
],
|
|
13
|
-
"plugins": [
|
|
14
|
-
"@babel/plugin-proposal-object-rest-spread",
|
|
15
|
-
"transform-es2015-modules-commonjs",
|
|
16
|
-
"transform-class-properties",
|
|
17
|
-
"dynamic-import-node",
|
|
18
|
-
"@loadable/babel-plugin"
|
|
19
|
-
],
|
|
20
|
-
"env": {
|
|
21
|
-
"test": {
|
|
22
|
-
"presets": ["@babel/preset-react"]
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
"ignore": ["__TEST__"]
|
|
26
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import Home from "@containers/Home/Home"
|
|
2
|
-
|
|
3
|
-
const routes = [
|
|
4
|
-
{
|
|
5
|
-
path: "/",
|
|
6
|
-
end: true,
|
|
7
|
-
component: Home,
|
|
8
|
-
},
|
|
9
|
-
]
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Making the routes array compatible with the format accepted by createBrowserRouter
|
|
13
|
-
* API on the client side
|
|
14
|
-
* https://reactrouter.com/en/main/routers/create-browser-router
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
export default routes
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import React from "react"
|
|
2
|
-
import { RouterDataProvider, MetaTag } from "@tata1mg/router"
|
|
3
|
-
import App from "@containers/App"
|
|
4
|
-
import routes from "./index.js"
|
|
5
|
-
|
|
6
|
-
export const preparedRoutes = ({ store, routerInitialState }) => {
|
|
7
|
-
return [
|
|
8
|
-
{
|
|
9
|
-
element: (
|
|
10
|
-
<RouterDataProvider config={{}} initialState={routerInitialState} fetcherArgs={{ store }}>
|
|
11
|
-
<MetaTag />
|
|
12
|
-
<App />
|
|
13
|
-
</RouterDataProvider>
|
|
14
|
-
),
|
|
15
|
-
children: getRoutes()?.map((route, index) => {
|
|
16
|
-
const Component = route.component
|
|
17
|
-
// const pageType = route.staticPageType ? route.staticPageType : null
|
|
18
|
-
return {
|
|
19
|
-
...route,
|
|
20
|
-
element: <Component key={index} />,
|
|
21
|
-
}
|
|
22
|
-
}),
|
|
23
|
-
},
|
|
24
|
-
]
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export const getRoutes = () => {
|
|
28
|
-
return routes
|
|
29
|
-
}
|