create-catalyst-app-internal 0.0.1-beta.2 → 0.0.1-beta.21

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.
Files changed (33) hide show
  1. package/Readme.md +56 -0
  2. package/license +10 -0
  3. package/package.json +6 -8
  4. package/scripts/cli.cjs +45 -15
  5. package/templates/common/.eslintignore +1 -0
  6. package/templates/common/.eslintrc +13 -38
  7. package/templates/common/README.md +2 -2
  8. package/templates/common/api.js +12 -23
  9. package/templates/common/client/styles.js +1 -12
  10. package/templates/common/config/config.json +2 -7
  11. package/templates/common/public/favicon.ico +0 -0
  12. package/templates/common/server/document.js +2 -4
  13. package/templates/common/server/index.js +1 -0
  14. package/templates/common/server/server.js +8 -1
  15. package/templates/common/src/js/containers/Home/Home.js +2 -2
  16. package/templates/common/src/js/routes/index.js +0 -6
  17. package/templates/none-js/client/index.js +4 -6
  18. package/templates/none-js/package.json +13 -6
  19. package/templates/none-js/src/js/containers/App/index.js +9 -7
  20. package/templates/none-js/src/js/routes/utils.js +42 -0
  21. package/templates/redux-js/package.json +12 -4
  22. package/templates/redux-js/src/js/containers/App/index.js +8 -6
  23. package/templates/redux-js/src/js/containers/App/reducer.js +1 -3
  24. package/templates/redux-js/src/js/routes/utils.js +42 -0
  25. package/templates/redux-js/src/js/store/index.js +2 -2
  26. package/templates/rtk-js/package.json +12 -4
  27. package/templates/rtk-js/src/js/containers/App/index.js +8 -6
  28. package/templates/rtk-js/src/js/containers/App/reducer.js +1 -1
  29. package/templates/rtk-js/src/js/routes/utils.js +42 -0
  30. package/templates/rtk-js/src/js/store/index.js +2 -2
  31. package/templates/common/.babelrc +0 -26
  32. package/templates/common/.prettierrc.json +0 -7
  33. package/templates/common/src/js/routes/utils.js +0 -29
package/Readme.md ADDED
@@ -0,0 +1,56 @@
1
+ # Creating a Catalyst App
2
+
3
+ Scaffold your Catalyst app swiftly with `create-catalyst-app`. This tool expedites the process by initializing your project with predefined configurations. To kickstart your project, execute the following command:
4
+
5
+ ```bash
6
+ npx create-catalyst-app@latest
7
+ ```
8
+
9
+ Upon execution, you'll be prompted to name your project. Once named, a template will be cloned into the specified directory.
10
+
11
+ ```bash
12
+ ✔ What is your project named? my-app
13
+ ```
14
+
15
+ Next, select your preferred state management tool from the provided options.
16
+
17
+ ```bash
18
+ ? Choose state management: › - Use arrow-keys. Return to submit .
19
+ ❯ Redux
20
+ Redux Toolkit (RTK)
21
+ None
22
+ ```
23
+
24
+ Following your selection, a default template will be cloned into the directory, and all necessary packages will be installed.
25
+
26
+ ## Getting Started
27
+
28
+ Commence development by initiating the application in development mode with the following commands:
29
+
30
+ Navigate into the directory
31
+
32
+ ```bash
33
+ cd my-app
34
+ ```
35
+
36
+ For running the application in development mode, run:
37
+
38
+ ```bash
39
+ npm run start
40
+ ```
41
+
42
+ For a production build, change NODE_ENV to "production" in config/config.json, and then run :
43
+
44
+ ```bash
45
+ npm run build
46
+ ```
47
+
48
+ To serve the production build, execute:
49
+
50
+ ```bash
51
+ npm run serve
52
+ ```
53
+
54
+ ## Documentation
55
+
56
+ Explore the complete documentation at [https://catalyst.1mg.com](https://catalyst.1mg.com).
package/license ADDED
@@ -0,0 +1,10 @@
1
+ MIT License
2
+
3
+ Copyright (c) 1mg Healthcare Solutions Private Limited.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10
+
package/package.json CHANGED
@@ -1,21 +1,19 @@
1
1
  {
2
2
  "name": "create-catalyst-app-internal",
3
3
  "bin": "scripts/cli.cjs",
4
- "version": "0.0.1-beta.2",
4
+ "version": "0.0.1-beta.21",
5
5
  "description": "cli package to scaffold Catalyst application",
6
- "main": "index.js",
7
- "scripts": {
8
- "start": "node index.js"
9
- },
10
6
  "dependencies": {
11
7
  "commander": "^8.2.0",
12
8
  "fs": "^0.0.1-security",
13
9
  "https": "^1.0.0",
14
10
  "picocolors": "^0.1.0",
15
11
  "prompts": "^2.4.0",
16
- "tar": "6.1.15"
12
+ "tar": "^6.2.1",
13
+ "validate-npm-package-name": "^5.0.0"
17
14
  },
18
15
  "devDependencies": {
19
16
  "prettier": "^3.2.5"
20
- }
21
- }
17
+ },
18
+ "license": "MIT"
19
+ }
package/scripts/cli.cjs CHANGED
@@ -3,14 +3,13 @@ const { execSync } = require("child_process")
3
3
  const Commander = require("commander")
4
4
  const { Option } = require("commander")
5
5
  const prompts = require("prompts")
6
- const { red, green, cyan } = require("picocolors")
7
-
8
- const packageJson = require("../package.json")
6
+ const { red, green, cyan, bold } = require("picocolors")
9
7
  const tar = require("tar")
10
8
  const path = require("path")
11
9
  const fs = require("fs")
10
+ var validate = require("validate-npm-package-name")
11
+ const packageJson = require("../package.json")
12
12
 
13
- // Hardcoded branch
14
13
  let projectName = null
15
14
  const program = new Commander.Command()
16
15
  .version(packageJson.version)
@@ -31,14 +30,21 @@ const program = new Commander.Command()
31
30
  // Use options provided through commander or prompt the user
32
31
  validateOptions(cmd)
33
32
  const projectName = folderName || (await promptProjectName())
33
+ let isNameValid = validate(projectName)
34
+ if (!isNameValid.validForNewPackages) {
35
+ isNameValid?.warnings?.forEach?.((item) => console.log(red(item)))
36
+ isNameValid?.errors?.forEach?.((item) => console.log(red(item)))
37
+ process.exit(1)
38
+ }
39
+ let projectPath = path.join(process.cwd(), projectName)
40
+ if (fs.existsSync(projectPath)) {
41
+ console.log(red(`${projectName} already exists, try again.`))
42
+ process.exit(1)
43
+ }
34
44
  const language = "js"
35
45
  const projectDescription = await promptDescription()
36
46
  const stateManagement = cmd.stateManagement || (await promptStateManagement())
37
47
 
38
- const resolvedProjectPath = path.resolve(projectName.trim())
39
- const projectPath = path.basename(resolvedProjectPath)
40
- const root = path.resolve(projectPath)
41
-
42
48
  // Define mapping of options to repository suffixes
43
49
  const repositorySuffixes = {
44
50
  js: "js",
@@ -63,24 +69,34 @@ const program = new Commander.Command()
63
69
  const packageFilePath = packNpmPackage(packageName, packageVersion, tempDir)
64
70
 
65
71
  extractSubdirectory(packageFilePath)
72
+ createGitignore(projectName)
66
73
 
67
74
  execSync(
68
- `cd ${projectName} && npm i && npm pkg set name=${projectName} ${
69
- projectDescription ? `description=${projectDescription}` : ""
70
- } && git init --quiet`,
75
+ `cd ${projectName} && npm i && npm pkg set name=${projectName} ${projectDescription ? `description="${projectDescription}"` : ""} && git init --quiet && git add . && git commit -m "initial commit from Create Catalyst App"`,
71
76
  { stdio: "inherit" }
72
77
  )
73
78
 
74
- console.log(cyan(`Installing Packages`))
79
+ console.log(`\n${green(bold("Success!"))} created ${projectName} at ${projectPath}`)
80
+ console.log("Inside this directory, you can run the following commands.")
75
81
 
76
- deleteDirectory(tempDir)
82
+ console.log(cyan(bold(" \n npm run start")))
83
+ console.log(" Starts the development server ")
84
+
85
+ console.log(cyan(bold("\n npm run build")))
86
+ console.log(" Bundles the app for production ")
87
+
88
+ console.log(cyan(bold("\n npm run serves")))
89
+ console.log(" Serves the production build ")
90
+
91
+ console.log("\nWe suggest you to begin, by running")
92
+ console.log(` ${cyan("cd")} ${projectName} && ${cyan("npm start")} \n\n`)
77
93
  } catch (error) {
78
- deleteDirectory(tempDir)
79
94
  console.error(`Error: ${error.message}`)
80
95
  process.exit(1)
96
+ } finally {
97
+ deleteDirectory(tempDir)
81
98
  }
82
99
  })()
83
-
84
100
  function packNpmPackage(packageName, packageVersion, tempDir) {
85
101
  const tarballFileName = `${packageName}-${packageVersion}.tgz`
86
102
  const tarballFilePath = path.join(tempDir, tarballFileName)
@@ -221,3 +237,17 @@ function deleteDirectory(dirPath) {
221
237
  fs.rmdirSync(dirPath)
222
238
  }
223
239
  }
240
+
241
+ // Function to create a .gitignore file with the hardcoded patterns
242
+ function createGitignore(projectName) {
243
+ const gitiIgnorePatterns = ["node_modules", "build", "logs"]
244
+
245
+ const gitignorePath = path.join(process.cwd(), projectName, ".gitignore")
246
+
247
+ if (fs.existsSync(gitignorePath)) {
248
+ console.log(".gitignore already exists. Please rename or remove it before running the script.")
249
+ return
250
+ }
251
+
252
+ fs.writeFileSync(gitignorePath, gitiIgnorePatterns.join("\n"))
253
+ }
@@ -0,0 +1 @@
1
+ **/build/*
@@ -1,53 +1,28 @@
1
1
  {
2
- "parser": "@babel/eslint-parser",
3
2
  "rules": {
4
- "prettier/prettier": "error",
5
- "no-console": "warn",
6
- "react/prop-types": 1,
7
- "react/display-name": [0, { "ignoreTranspilerName": true }],
8
- "react-hooks/exhaustive-deps": "warn", // Checks effect dependencies
9
- "no-prototype-builtins": "off",
10
- "jam3/no-sanitizer-with-danger": 2,
11
- "react/jsx-no-target-blank": [0, {
12
- "enforceDynamicLinks": "never"
13
- }]
3
+ "react-hooks/exhaustive-deps": "error" // Checks effect dependencies
14
4
  },
15
5
  "env": {
16
6
  "browser": true,
17
7
  "es6": true,
18
- "jest": true,
19
8
  "node": true
20
9
  },
21
- "globals": {
22
- "expect": true,
23
- "__non_webpack_require__": true,
24
- "logger": "readonly",
25
- "AppCallbacks": "readonly"
26
- },
27
- "extends": ["eslint:recommended", "plugin:react/recommended"],
10
+ "extends": [
11
+ "eslint:recommended",
12
+ "plugin:react/recommended",
13
+ ],
28
14
  "parserOptions": {
29
15
  "sourceType": "module",
30
- "ecmaFeatures": {
31
- "experimentalObjectRestSpread": true,
32
- "jsx": true
33
- },
34
- "babelOptions": {
35
- "configFile": "./babel.config.js"
36
- },
37
- "ecmaVersion": 6
16
+ "ecmaVersion": "latest"
38
17
  },
39
- "plugins": ["babel", "react", "react-hooks", "prettier", "jam3"],
40
- "settings": {
18
+ "plugins": [
19
+ "react",
20
+ "react-hooks"
21
+ ],
22
+ "settings": {
41
23
  "react": {
42
- "createClass": "createReactClass",
43
24
  "pragma": "React",
44
25
  "version": "detect"
45
- },
46
- "propWrapperFunctions": [
47
- "forbidExtraProps",
48
- { "property": "freeze", "object": "Object" },
49
- { "property": "myFavoriteWrapper" }
50
- ],
51
- "linkComponents": ["Hyperlink", { "name": "Link", "linkAttribute": "to" }]
26
+ }
52
27
  }
53
- }
28
+ }
@@ -1,6 +1,6 @@
1
1
  ## Getting Started
2
2
 
3
- Commence development by initiating the application in development mode with the following commands:
3
+ Commence development by initiating the the following commands:
4
4
 
5
5
  For running the application in development mode, run:
6
6
 
@@ -8,7 +8,7 @@ For running the application in development mode, run:
8
8
  npm run start
9
9
  ```
10
10
 
11
- For a production build, utilize:
11
+ For a production build, change NODE_ENV to "production" in config/config.json, then run :
12
12
 
13
13
  ```bash
14
14
  npm run build
@@ -1,27 +1,16 @@
1
- const apiInstance = () => {
2
- const fetchFunction = async (url, options) => {
3
- let baseURL = process.env.API_URL
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
- // Request Interceptor - you can modify request here
5
+ // Request Interceptor - modify request here
7
6
 
8
- // Add query params if exist
9
- if (Object.keys(options?.params).length > 0) {
10
- finalUrl = url + "?" + new URLSearchParams(options.params)
11
- }
12
-
13
- return fetch(finalUrl, options).then(async (response) => {
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
- export default { apiInstance }
15
+
16
+ export default fetchFunction
@@ -1,14 +1,3 @@
1
- /* Style Loader
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,13 +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:3006",
9
- "NODE_ENV": "production",
10
- "BUILD_ENV": "localBuild",
8
+ "PUBLIC_STATIC_ASSET_URL": "http://localhost:3005",
11
9
  "API_URL": "",
12
- "CLIENT_EXPOSED_KEYS": [],
13
10
  "ANALYZE_BUNDLE": false,
14
- "ENABLE_DEBUG_LOGS": true,
15
- "ENABLE_FILE_LOGGING": true,
16
- "ENABLE_CONSOLE_LOGGING": true
11
+ "CLIENT_ENV_VARIABLES": ["API_URL"]
17
12
  }
@@ -3,10 +3,8 @@ import { Head, Body } from "catalyst-core-internal"
3
3
 
4
4
  function Document(props) {
5
5
  return (
6
- <html lang={props.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,2 @@
1
+ // This function is executed before server starts.
1
2
  export const preServerInit = () => {}
@@ -1 +1,8 @@
1
- export function addMiddlewares(app) {}
1
+ const express = require("express")
2
+ const path = require("path")
3
+
4
+ // Server middlewares are added here.
5
+
6
+ export function addMiddlewares(app) {
7
+ app.use("/favicon.ico", express.static(path.join(__dirname, "../public/favicon.ico")))
8
+ }
@@ -1,7 +1,7 @@
1
1
  import React from "react"
2
2
  import css from "./Home.scss"
3
3
 
4
- function Landing() {
4
+ function Home() {
5
5
  return (
6
6
  <div className={css.app}>
7
7
  <header className={css.appHeader}>
@@ -20,4 +20,4 @@ function Landing() {
20
20
  )
21
21
  }
22
22
 
23
- export default Landing
23
+ export default Home
@@ -8,10 +8,4 @@ const routes = [
8
8
  },
9
9
  ]
10
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
11
  export default routes
@@ -7,16 +7,14 @@ import clientRouter from "catalyst-core-internal/router/ClientRouter"
7
7
 
8
8
  window.addEventListener("load", () => {
9
9
  loadableReady(() => {
10
- const { __ROUTER_INITIAL_DATA__: routerInitialData, __INITIAL_STATE__ } = window
10
+ const { __ROUTER_INITIAL_DATA__: routerInitialData } = window
11
11
 
12
12
  const router = clientRouter({ routerInitialState: routerInitialData })
13
13
 
14
14
  const Application = (
15
- <Provider serverState={__INITIAL_STATE__}>
16
- <React.StrictMode>
17
- <RouterProvider router={router} />
18
- </React.StrictMode>
19
- </Provider>
15
+ <React.StrictMode>
16
+ <RouterProvider router={router} />
17
+ </React.StrictMode>
20
18
  )
21
19
 
22
20
  const container = document.getElementById("app")
@@ -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",
@@ -12,12 +15,16 @@
12
15
  "@server": "server",
13
16
  "@config": "config",
14
17
  "@css": "src/static/css",
15
- "@routes": "src/js/routes/",
16
- "@store": "src/js/store/index.js"
18
+ "@routes": "src/js/routes/"
17
19
  },
18
20
  "dependencies": {
19
21
  "@loadable/component": "^5.16.3",
20
- "@tata1mg/router": "^0.0.1-alpha.13",
21
- "catalyst-core-internal": "0.0.1-beta.0"
22
+ "@tata1mg/router": "^0.0.1-beta.1",
23
+ "catalyst-core-internal": "^0.0.1-beta.15"
24
+ },
25
+ "devDependencies": {
26
+ "eslint": "^8.26.0",
27
+ "eslint-plugin-react": "^7.34.1",
28
+ "eslint-plugin-react-hooks": "^4.6.0"
22
29
  }
23
- }
30
+ }
@@ -1,13 +1,15 @@
1
- import React, { useState } from "react"
2
- import { useOutlet } from "@tata1mg/router"
3
- const App = () => {
4
- const o = useOutlet()
5
- const [outlet] = useState(o)
1
+ import React from "react"
2
+ import { Outlet } from "@tata1mg/router"
6
3
 
7
- return <>{outlet}</>
4
+ const App = () => {
5
+ return (
6
+ <>
7
+ <Outlet />
8
+ </>
9
+ )
8
10
  }
9
11
 
10
- App.serverSideFunction = ({}) => {
12
+ App.serverSideFunction = () => {
11
13
  return new Promise((resolve) => resolve())
12
14
  }
13
15
 
@@ -0,0 +1,42 @@
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
+ /**
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
+ const Component = route.component
16
+ const routeToRender = {
17
+ ...route,
18
+ element: <Component key={index} />,
19
+ }
20
+ if (route.children) {
21
+ routeToRender.children = getPreparedRoutes(route.children)
22
+ }
23
+ return routeToRender
24
+ })
25
+ }
26
+
27
+ return [
28
+ {
29
+ element: (
30
+ <RouterDataProvider config={{}} initialState={routerInitialState}>
31
+ <MetaTag />
32
+ <App />
33
+ </RouterDataProvider>
34
+ ),
35
+ children: getPreparedRoutes(routes),
36
+ },
37
+ ]
38
+ }
39
+
40
+ export const getRoutes = () => {
41
+ return routes
42
+ }
@@ -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",
@@ -17,9 +20,14 @@
17
20
  },
18
21
  "dependencies": {
19
22
  "@loadable/component": "^5.16.3",
20
- "@tata1mg/router": "^0.0.1-alpha.13",
21
- "catalyst-core-internal": "0.0.1-beta.0",
23
+ "@tata1mg/router": "^0.0.1-beta.1",
24
+ "catalyst-core-internal": "^0.0.1-beta.15",
22
25
  "@reduxjs/toolkit": "1.9.3",
23
26
  "react-redux": "^8.1.3"
27
+ },
28
+ "devDependencies": {
29
+ "eslint": "^8.26.0",
30
+ "eslint-plugin-react": "^7.34.1",
31
+ "eslint-plugin-react-hooks": "^4.6.0"
24
32
  }
25
- }
33
+ }
@@ -1,10 +1,12 @@
1
- import React, { useState } from "react"
2
- import { useOutlet } from "@tata1mg/router"
3
- const App = () => {
4
- const o = useOutlet()
5
- const [outlet] = useState(o)
1
+ import React from "react"
2
+ import { Outlet } from "@tata1mg/router"
6
3
 
7
- return <>{outlet}</>
4
+ const App = () => {
5
+ return (
6
+ <>
7
+ <Outlet />
8
+ </>
9
+ )
8
10
  }
9
11
 
10
12
  App.serverSideFunction = () => {
@@ -4,7 +4,7 @@ export const defaultState = {
4
4
  testActionDispatched: false,
5
5
  }
6
6
 
7
- const shellReducer = (state = defaultState, action) => {
7
+ export const shellReducer = (state = defaultState, action) => {
8
8
  switch (action.type) {
9
9
  case ShellActions.REDUX_TEST: {
10
10
  return {
@@ -17,5 +17,3 @@ const shellReducer = (state = defaultState, action) => {
17
17
  return state
18
18
  }
19
19
  }
20
-
21
- export default shellReducer
@@ -0,0 +1,42 @@
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
+ /**
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
+ const Component = route.component
16
+ const routeToRender = {
17
+ ...route,
18
+ element: <Component key={index} />,
19
+ }
20
+ if (route.children) {
21
+ routeToRender.children = getPreparedRoutes(route.children)
22
+ }
23
+ return routeToRender
24
+ })
25
+ }
26
+
27
+ return [
28
+ {
29
+ element: (
30
+ <RouterDataProvider config={{}} initialState={routerInitialState} fetcherArgs={{ store }}>
31
+ <MetaTag />
32
+ <App />
33
+ </RouterDataProvider>
34
+ ),
35
+ children: getPreparedRoutes(routes),
36
+ },
37
+ ]
38
+ }
39
+
40
+ export const getRoutes = () => {
41
+ return routes
42
+ }
@@ -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 initialised on the server.
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, request) => {
13
+ const configureStore = (initialState) => {
14
14
  const api = fetchInstance
15
15
  const store = createStore({
16
16
  reducer: combineReducers({ shellReducer }),
@@ -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",
@@ -17,9 +20,14 @@
17
20
  },
18
21
  "dependencies": {
19
22
  "@loadable/component": "^5.16.3",
20
- "@tata1mg/router": "^0.0.1-alpha.13",
21
- "catalyst-core-internal": "0.0.1-beta.0",
23
+ "@tata1mg/router": "^0.0.1-beta.1",
24
+ "catalyst-core-internal": "^0.0.1-beta.15",
22
25
  "@reduxjs/toolkit": "1.9.3",
23
26
  "react-redux": "^8.1.3"
27
+ },
28
+ "devDependencies": {
29
+ "eslint": "^8.26.0",
30
+ "eslint-plugin-react": "^7.34.1",
31
+ "eslint-plugin-react-hooks": "^4.6.0"
24
32
  }
25
- }
33
+ }
@@ -1,10 +1,12 @@
1
- import React, { useState } from "react"
2
- import { useOutlet } from "@tata1mg/router"
3
- const App = () => {
4
- const o = useOutlet()
5
- const [outlet] = useState(o)
1
+ import React from "react"
2
+ import { Outlet } from "@tata1mg/router"
6
3
 
7
- return <>{outlet}</>
4
+ const App = () => {
5
+ return (
6
+ <>
7
+ <Outlet />
8
+ </>
9
+ )
8
10
  }
9
11
 
10
12
  App.serverSideFunction = () => {
@@ -8,7 +8,7 @@ export const appSlice = createSlice({
8
8
  name: "shellReducer",
9
9
  initialState: initialState,
10
10
  reducers: {
11
- reduxTest: (state, action) => {
11
+ reduxTest: (state) => {
12
12
  state.testActionDispatched = true
13
13
  },
14
14
  },
@@ -0,0 +1,42 @@
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
+ /**
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
+ const Component = route.component
16
+ const routeToRender = {
17
+ ...route,
18
+ element: <Component key={index} />,
19
+ }
20
+ if (route.children) {
21
+ routeToRender.children = getPreparedRoutes(route.children)
22
+ }
23
+ return routeToRender
24
+ })
25
+ }
26
+
27
+ return [
28
+ {
29
+ element: (
30
+ <RouterDataProvider config={{}} initialState={routerInitialState} fetcherArgs={{ store }}>
31
+ <MetaTag />
32
+ <App />
33
+ </RouterDataProvider>
34
+ ),
35
+ children: getPreparedRoutes(routes),
36
+ },
37
+ ]
38
+ }
39
+
40
+ export const getRoutes = () => {
41
+ return routes
42
+ }
@@ -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 initialised on the server.
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, request) => {
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,7 +0,0 @@
1
- {
2
- "trailingComma": "es5",
3
- "tabWidth": 4,
4
- "semi": false,
5
- "arrowParens": "always",
6
- "printWidth": 110
7
- }
@@ -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
- }