create-catalyst-app-internal 0.0.1-beta.3 → 0.0.1-beta.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.
Files changed (35) hide show
  1. package/Readme.md +56 -0
  2. package/codemod/createNewRoute.js +110 -0
  3. package/codemod/createRoute.js +39 -0
  4. package/license +10 -0
  5. package/package.json +6 -7
  6. package/scripts/cli.cjs +50 -15
  7. package/templates/common/.eslintignore +1 -0
  8. package/templates/common/.eslintrc +13 -38
  9. package/templates/common/README.md +2 -2
  10. package/templates/common/api.js +12 -23
  11. package/templates/common/client/styles.js +1 -12
  12. package/templates/common/config/config.json +3 -25
  13. package/templates/common/public/favicon.ico +0 -0
  14. package/templates/common/server/document.js +2 -4
  15. package/templates/common/server/index.js +1 -0
  16. package/templates/common/server/server.js +8 -1
  17. package/templates/common/src/js/containers/Home/Home.js +2 -2
  18. package/templates/common/src/js/routes/index.js +0 -6
  19. package/templates/none-js/client/index.js +4 -6
  20. package/templates/none-js/package.json +12 -5
  21. package/templates/none-js/src/js/containers/App/index.js +9 -7
  22. package/templates/none-js/src/js/routes/utils.js +42 -0
  23. package/templates/redux-js/package.json +11 -3
  24. package/templates/redux-js/src/js/containers/App/index.js +8 -6
  25. package/templates/redux-js/src/js/containers/App/reducer.js +1 -3
  26. package/templates/redux-js/src/js/routes/utils.js +42 -0
  27. package/templates/redux-js/src/js/store/index.js +2 -2
  28. package/templates/rtk-js/package.json +11 -3
  29. package/templates/rtk-js/src/js/containers/App/index.js +8 -6
  30. package/templates/rtk-js/src/js/containers/App/reducer.js +1 -1
  31. package/templates/rtk-js/src/js/routes/utils.js +42 -0
  32. package/templates/rtk-js/src/js/store/index.js +2 -2
  33. package/templates/common/.babelrc +0 -26
  34. package/templates/common/.prettierrc.json +0 -7
  35. 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).
@@ -0,0 +1,110 @@
1
+ const fs = require("fs");
2
+ const path = require('path');
3
+ const prompts = require('prompts');
4
+ const pc = require("picocolors")
5
+
6
+ const { program } = require('commander');
7
+ const { execSync } = require('child_process');
8
+
9
+
10
+ // Configure commander to accept CLI options
11
+ program
12
+ .option('-p, --path <path>', 'Path for the new route')
13
+ .option('-c, --component <component>', 'Component name for the new route')
14
+ .parse(process.argv);
15
+
16
+
17
+ async function main() {
18
+ const { path: routePath, component } = program;
19
+
20
+ // If both options are not provided, prompt the user for input
21
+ if (!routePath || !component) {
22
+ const response = await prompts([
23
+ {
24
+ type: routePath ? null : 'text',
25
+ name: 'path',
26
+ message: 'Enter the route path',
27
+ validate: value => (value ? true : 'Route path is required')
28
+ },
29
+ {
30
+ type: component ? null : 'text',
31
+ name: 'component',
32
+ message: 'Enter the component name for new route',
33
+ validate: value => {
34
+ const componentNameRegex = /^[A-Z][a-zA-Z0-9]*$/;
35
+
36
+ return componentNameRegex.test(value) || "Component name should start with an uppercase letter and may contain alphanumeric characters";
37
+ }
38
+ },
39
+ ]);
40
+
41
+
42
+ routePathName = routePath || response.path;
43
+ componentName = component || response.component;
44
+ }
45
+
46
+ if (componentName) {
47
+ // Add new component
48
+ const isCreated = addNewComponent(componentName)
49
+
50
+ // Add the new route
51
+ if (isCreated) addNewRoute(componentName, routePathName);
52
+ }
53
+ }
54
+
55
+ // Function to create component using given inputs
56
+ function addNewComponent(componentName) {
57
+
58
+ const componentDir = "src/js/containers"
59
+ const componentPath = path.join(componentDir, `${componentName}/${componentName}.js`);
60
+
61
+ // Create the new component file
62
+ const componentTemplate = `import React from 'react';
63
+
64
+ const ${componentName} = () => {
65
+ return (
66
+ <div>
67
+ <h1>${componentName}</h1>
68
+ <p>This is the ${componentName} component.</p>
69
+ </div>
70
+ );
71
+ };
72
+
73
+ export default ${componentName};
74
+ `;
75
+
76
+ try {
77
+ // directory check
78
+ if (fs.existsSync(`${componentDir}/${componentName}`)) {
79
+ throw new Error("directory with similar name already exist");
80
+ }
81
+
82
+ // component check
83
+ if (fs.existsSync(componentPath)) {
84
+ throw new Error("component with similar name already exist");
85
+ }
86
+
87
+ fs.mkdirSync(`${componentDir}/${componentName}`)
88
+ fs.writeFileSync(componentPath, componentTemplate, 'utf8');
89
+ console.log(`\nComponent ${componentName} created at ${componentPath}`);
90
+
91
+ return true
92
+
93
+ } catch (e) {
94
+ console.log(pc.red(`\nError: ${e}`))
95
+ }
96
+ }
97
+
98
+ // Function to run the codemod with the provided inputs
99
+ function addNewRoute(componentName, routePath) {
100
+ const codemodPath = path.join(__dirname, 'createRoute.js');
101
+ const command = `jscodeshift --silent -t ${codemodPath} --routePath ${routePath} --componentName ${componentName} src/js/routes/index.js`;
102
+
103
+ try {
104
+ execSync(command, { stdio: 'inherit' });
105
+ } catch (error) {
106
+ console.log(pc.red(`\nError running codemod: ${e}`))
107
+ }
108
+ }
109
+
110
+ main();
@@ -0,0 +1,39 @@
1
+ const pc = require("picocolors")
2
+
3
+ module.exports = function (fileInfo, api, options) {
4
+ const jscodeshift = api.jscodeshift;
5
+ const root = jscodeshift(fileInfo.source);
6
+
7
+ const { routePath, componentName } = options;
8
+
9
+ // Create a new route object using a template expression
10
+ const newObject = jscodeshift.template.expression`
11
+ {
12
+ path: ${JSON.stringify(routePath)},
13
+ end: true,
14
+ component: ${componentName}
15
+ }
16
+ `;
17
+
18
+
19
+ const result = root.find(jscodeshift.ImportDeclaration, { source: { value: `@containers/${componentName}/${componentName}` } })
20
+
21
+ if (result.__paths.length > 0) {
22
+ console.log(pc.red("\nError: Route with similar name already exist!"))
23
+ return
24
+ } else {
25
+
26
+ // Insert the node at the top of the file
27
+ root.find(jscodeshift.Program).get('body', 0).insertBefore(`import ${componentName} from '@containers/${componentName}/${componentName}'`);
28
+
29
+ root.find(jscodeshift.VariableDeclarator, { id: { name: 'routes' } })
30
+ .find(jscodeshift.ArrayExpression)
31
+ .forEach(p => p.get('elements').push(newObject))
32
+
33
+
34
+ console.log(pc.green('\nNew route added successfully.'));
35
+ return root.toSource();
36
+ }
37
+
38
+ };
39
+
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,20 @@
1
1
  {
2
2
  "name": "create-catalyst-app-internal",
3
3
  "bin": "scripts/cli.cjs",
4
- "version": "0.0.1-beta.3",
4
+ "version": "0.0.1-beta.30",
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",
14
+ "jscodeshift": "^0.16.0"
17
15
  },
18
16
  "devDependencies": {
19
17
  "prettier": "^3.2.5"
20
- }
18
+ },
19
+ "license": "MIT"
21
20
  }
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)
@@ -28,17 +27,29 @@ const program = new Commander.Command()
28
27
  )
29
28
  .action(async (folderName = null, cmd) => {
30
29
  try {
30
+ if (process.argv.includes("new-route")) {
31
+ execSync(`node codemod/createNewRoute.js`, { stdio: "inherit" })
32
+ return
33
+ }
34
+
31
35
  // Use options provided through commander or prompt the user
32
36
  validateOptions(cmd)
33
37
  const projectName = folderName || (await promptProjectName())
38
+ let isNameValid = validate(projectName)
39
+ if (!isNameValid.validForNewPackages) {
40
+ isNameValid?.warnings?.forEach?.((item) => console.log(red(item)))
41
+ isNameValid?.errors?.forEach?.((item) => console.log(red(item)))
42
+ process.exit(1)
43
+ }
44
+ let projectPath = path.join(process.cwd(), projectName)
45
+ if (fs.existsSync(projectPath)) {
46
+ console.log(red(`${projectName} already exists, try again.`))
47
+ process.exit(1)
48
+ }
34
49
  const language = "js"
35
50
  const projectDescription = await promptDescription()
36
51
  const stateManagement = cmd.stateManagement || (await promptStateManagement())
37
52
 
38
- const resolvedProjectPath = path.resolve(projectName.trim())
39
- const projectPath = path.basename(resolvedProjectPath)
40
- const root = path.resolve(projectPath)
41
-
42
53
  // Define mapping of options to repository suffixes
43
54
  const repositorySuffixes = {
44
55
  js: "js",
@@ -63,24 +74,34 @@ const program = new Commander.Command()
63
74
  const packageFilePath = packNpmPackage(packageName, packageVersion, tempDir)
64
75
 
65
76
  extractSubdirectory(packageFilePath)
77
+ createGitignore(projectName)
66
78
 
67
79
  execSync(
68
- `cd ${projectName} && npm i && npm pkg set name=${projectName} ${
69
- projectDescription ? `description=${projectDescription}` : ""
70
- } && git init --quiet`,
80
+ `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
81
  { stdio: "inherit" }
72
82
  )
73
83
 
74
- console.log(cyan(`Installing Packages`))
84
+ console.log(`\n${green(bold("Success!"))} created ${projectName} at ${projectPath}`)
85
+ console.log("Inside this directory, you can run the following commands.")
75
86
 
76
- deleteDirectory(tempDir)
87
+ console.log(cyan(bold(" \n npm run start")))
88
+ console.log(" Starts the development server ")
89
+
90
+ console.log(cyan(bold("\n npm run build")))
91
+ console.log(" Bundles the app for production ")
92
+
93
+ console.log(cyan(bold("\n npm run serve")))
94
+ console.log(" Serves the production build ")
95
+
96
+ console.log("\nWe suggest you to begin, by running")
97
+ console.log(` ${cyan("cd")} ${projectName} && ${cyan("npm start")} \n\n`)
77
98
  } catch (error) {
78
- deleteDirectory(tempDir)
79
99
  console.error(`Error: ${error.message}`)
80
100
  process.exit(1)
101
+ } finally {
102
+ deleteDirectory(tempDir)
81
103
  }
82
104
  })()
83
-
84
105
  function packNpmPackage(packageName, packageVersion, tempDir) {
85
106
  const tarballFileName = `${packageName}-${packageVersion}.tgz`
86
107
  const tarballFilePath = path.join(tempDir, tarballFileName)
@@ -221,3 +242,17 @@ function deleteDirectory(dirPath) {
221
242
  fs.rmdirSync(dirPath)
222
243
  }
223
244
  }
245
+
246
+ // Function to create a .gitignore file with the hardcoded patterns
247
+ function createGitignore(projectName) {
248
+ const gitiIgnorePatterns = ["node_modules", "build", "logs"]
249
+
250
+ const gitignorePath = path.join(process.cwd(), projectName, ".gitignore")
251
+
252
+ if (fs.existsSync(gitignorePath)) {
253
+ console.log(".gitignore already exists. Please rename or remove it before running the script.")
254
+ return
255
+ }
256
+
257
+ fs.writeFileSync(gitignorePath, gitiIgnorePatterns.join("\n"))
258
+ }
@@ -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,30 +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": "development",
10
- "BUILD_ENV": "localBuild",
8
+ "PUBLIC_STATIC_ASSET_URL": "http://localhost:3005",
11
9
  "API_URL": "",
12
- "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
- "CLIENT_ENV_VARIABLES",
25
- "ANALYZE_BUNDLE",
26
- "ENABLE_DEBUG_LOGS",
27
- "ENABLE_FILE_LOGGING",
28
- "ENABLE_CONSOLE_LOGGING",
29
- "ANALYZE_BUNDLE",
30
- "ENABLE_DEBUG_LOGS",
31
- "ENABLE_FILE_LOGGING",
32
- "ENABLE_CONSOLE_LOGGING"
33
- ]
10
+ "ANALYZE_BUNDLE": false,
11
+ "CLIENT_ENV_VARIABLES": ["API_URL"]
34
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.2-test.2",
23
+ "catalyst-core-internal": "^0.0.1-beta.23"
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.2-test.2",
24
+ "catalyst-core-internal": "^0.0.1-beta.23",
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.2-test.2",
24
+ "catalyst-core-internal": "^0.0.1-beta.23",
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
- }