create-catalyst-app-internal 0.0.1-beta.6 → 0.0.1-beta.60
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 +6 -7
- package/scripts/cli.cjs +58 -40
- 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 +2 -4
- package/templates/common/server/index.js +1 -0
- package/templates/common/server/server.js +8 -1
- package/templates/common/src/js/containers/Home/Home.js +2 -2
- package/templates/common/src/js/routes/index.js +0 -6
- package/templates/common/webpackConfig.js +1 -0
- package/templates/none-js/client/index.js +4 -6
- package/templates/none-js/package.json +12 -5
- package/templates/none-js/src/js/containers/App/index.js +1 -1
- package/templates/none-js/src/js/routes/utils.js +42 -0
- package/templates/redux-js/package.json +11 -3
- package/templates/redux-js/src/js/containers/App/index.js +1 -1
- package/templates/redux-js/src/js/containers/App/reducer.js +1 -3
- package/templates/redux-js/src/js/routes/utils.js +42 -0
- package/templates/redux-js/src/js/store/index.js +2 -2
- package/templates/rtk-js/package.json +11 -3
- package/templates/rtk-js/src/js/containers/App/index.js +1 -1
- package/templates/rtk-js/src/js/containers/App/reducer.js +1 -1
- package/templates/rtk-js/src/js/routes/utils.js +42 -0
- package/templates/rtk-js/src/js/store/index.js +2 -2
- package/templates/common/.babelrc +0 -26
- 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,98 @@
|
|
|
1
|
+
const fs = require("fs")
|
|
2
|
+
const path = require("path")
|
|
3
|
+
const pc = require("picocolors")
|
|
4
|
+
const prompts = require('prompts');
|
|
5
|
+
const { program } = require('commander');
|
|
6
|
+
|
|
7
|
+
const { createNewComponent, createRTKReducerFile, createReduxActionFile, createReduxReducerFile } = require("./template")
|
|
8
|
+
const { validateComponentName, validatePath, discardChanges, createDirectory, createReducerEntryInStore, createNewRoute, toCamelCase, checkIfRoutePathExist } = require("./utils")
|
|
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
|
+
let { routePath, templateType, componentName } = program;
|
|
19
|
+
|
|
20
|
+
// If all options are not provided, prompt the user for input
|
|
21
|
+
if (!routePath || !componentName || !templateType) {
|
|
22
|
+
const response = await prompts([
|
|
23
|
+
{
|
|
24
|
+
type: "select",
|
|
25
|
+
name: "templateType",
|
|
26
|
+
message: "Choose state management template being used:",
|
|
27
|
+
choices: [
|
|
28
|
+
{ title: "Redux", value: "redux" },
|
|
29
|
+
{ title: "Redux Toolkit (RTK)", value: "rtk" },
|
|
30
|
+
{ title: "None", value: "none" },
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
type: routePath ? null : 'text',
|
|
35
|
+
name: 'routePath',
|
|
36
|
+
message: "Enter the route path",
|
|
37
|
+
validate: validatePath
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
type: componentName ? null : 'text',
|
|
41
|
+
name: 'componentName',
|
|
42
|
+
message: 'Enter the component name for new route',
|
|
43
|
+
validate: validateComponentName
|
|
44
|
+
}
|
|
45
|
+
]);
|
|
46
|
+
|
|
47
|
+
routePath = routePath || response.routePath;
|
|
48
|
+
templateType = templateType || response.templateType
|
|
49
|
+
componentName = componentName || response.componentName;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
// Code transformations
|
|
54
|
+
if (componentName && routePath && templateType) {
|
|
55
|
+
|
|
56
|
+
const reducerName = toCamelCase(componentName)
|
|
57
|
+
const containersDir = 'src/js/containers';
|
|
58
|
+
const routeTransformerPath = path.join(__dirname, "./", 'transformers/createRoute.js')
|
|
59
|
+
const reducerTransformerPath = path.join(__dirname, "./", 'transformers/createReducer.js');
|
|
60
|
+
|
|
61
|
+
const funcArgs = { containersDir, componentName, routePath, reducerName, templateType, reducerTransformerPath, routeTransformerPath }
|
|
62
|
+
|
|
63
|
+
// create directory
|
|
64
|
+
if (createDirectory(funcArgs)) {
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
|
|
68
|
+
checkIfRoutePathExist(funcArgs)
|
|
69
|
+
|
|
70
|
+
if (templateType === "none") {
|
|
71
|
+
createNewComponent(funcArgs)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (templateType === "redux") {
|
|
75
|
+
createNewComponent(funcArgs)
|
|
76
|
+
createReduxActionFile(funcArgs)
|
|
77
|
+
createReduxReducerFile(funcArgs)
|
|
78
|
+
createReducerEntryInStore(funcArgs)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (templateType === "rtk") {
|
|
82
|
+
createNewComponent(funcArgs)
|
|
83
|
+
createRTKReducerFile(funcArgs)
|
|
84
|
+
createReducerEntryInStore(funcArgs)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
createNewRoute(funcArgs);
|
|
88
|
+
|
|
89
|
+
} catch (e) {
|
|
90
|
+
discardChanges(funcArgs)
|
|
91
|
+
console.log(pc.red(`\n${e}`))
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
main();
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
const fs = require("fs")
|
|
2
|
+
const path = require("path")
|
|
3
|
+
const pc = require("picocolors")
|
|
4
|
+
|
|
5
|
+
// Function to create component using given input
|
|
6
|
+
function createNewComponent({ componentName, containersDir }) {
|
|
7
|
+
|
|
8
|
+
const componentPath = path.join(containersDir, `${componentName}/${componentName}.js`);
|
|
9
|
+
|
|
10
|
+
// Component template
|
|
11
|
+
const componentTemplate = `import React from 'react';
|
|
12
|
+
|
|
13
|
+
const ${componentName} = () => {
|
|
14
|
+
return (
|
|
15
|
+
<div>
|
|
16
|
+
<h1>${componentName}</h1>
|
|
17
|
+
<p>This is the ${componentName} component.</p>
|
|
18
|
+
</div>
|
|
19
|
+
);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default ${componentName};
|
|
23
|
+
`;
|
|
24
|
+
|
|
25
|
+
fs.writeFileSync(componentPath, componentTemplate, 'utf8');
|
|
26
|
+
console.log(`\n${pc.cyan(componentName)} component created at ${pc.gray(componentPath)}`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
// Function to create rtk reducer file using given input
|
|
31
|
+
function createRTKReducerFile({ componentName, containersDir, reducerName }) {
|
|
32
|
+
const reducerPath = path.join(containersDir, `${componentName}/reducer.js`);
|
|
33
|
+
|
|
34
|
+
// rtk reducer template
|
|
35
|
+
const reducerTemplate = `import { createSlice } from "@reduxjs/toolkit"
|
|
36
|
+
|
|
37
|
+
const initialState = {
|
|
38
|
+
testActionDispatched: false,
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const appSlice = createSlice({
|
|
42
|
+
name: ${reducerName}Reducer,
|
|
43
|
+
initialState: initialState,
|
|
44
|
+
reducers: {
|
|
45
|
+
reduxTest: (state) => {
|
|
46
|
+
state.testActionDispatched = true
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
export const { reduxTest } = appSlice.actions
|
|
52
|
+
export const ${reducerName}Reducer = appSlice.reducer
|
|
53
|
+
`;
|
|
54
|
+
|
|
55
|
+
fs.writeFileSync(reducerPath, reducerTemplate, 'utf8');
|
|
56
|
+
console.log(`\n${pc.cyan("reducer.js")} file created at ${pc.gray(reducerPath)} `);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
// Function to create redux action file using given input
|
|
61
|
+
function createReduxActionFile({ componentName, containersDir, reducerName }) {
|
|
62
|
+
const actionsPath = path.join(containersDir, `${componentName}/actions.js`);
|
|
63
|
+
|
|
64
|
+
// redux action template
|
|
65
|
+
const actionTemplate = `const createActionTypes = (prefix, actionTypeList = []) => {
|
|
66
|
+
const actionTypesObject = {}
|
|
67
|
+
actionTypeList.forEach((item) => {
|
|
68
|
+
actionTypesObject[item] = prefix + "/" + item
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
return actionTypesObject
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export default createActionTypes
|
|
75
|
+
|
|
76
|
+
export const ${reducerName}Actions = createActionTypes(${reducerName}Actions, ["REDUX_TEST"])
|
|
77
|
+
export const reduxTest = () => {
|
|
78
|
+
return {
|
|
79
|
+
type: ${reducerName}Actions.REDUX_TEST,
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
`;
|
|
83
|
+
|
|
84
|
+
fs.writeFileSync(actionsPath, actionTemplate, 'utf8');
|
|
85
|
+
console.log(`\n${pc.cyan("action.js")} file created at ${pc.gray(actionsPath)} `);
|
|
86
|
+
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Function to create redux reducer file using given input
|
|
90
|
+
function createReduxReducerFile({ componentName, containersDir, reducerName }) {
|
|
91
|
+
const reducerPath = path.join(containersDir, `${componentName}/reducer.js`);
|
|
92
|
+
|
|
93
|
+
// redux reducer template
|
|
94
|
+
const reducerTemplate = `import { ${reducerName}Actions } from "./actions"
|
|
95
|
+
|
|
96
|
+
export const defaultState = {
|
|
97
|
+
testActionDispatched: false,
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export const ${reducerName}Reducer = (state = defaultState, action) => {
|
|
101
|
+
switch (action.type) {
|
|
102
|
+
case ${reducerName}Actions.REDUX_TEST: {
|
|
103
|
+
return {
|
|
104
|
+
...state,
|
|
105
|
+
testActionDispatched: true,
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
default:
|
|
110
|
+
return state
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
`;
|
|
114
|
+
|
|
115
|
+
fs.writeFileSync(reducerPath, reducerTemplate, 'utf8');
|
|
116
|
+
console.log(`\n${pc.cyan("reducer.js")} file created at ${pc.gray(reducerPath)} `);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
module.exports = { createNewComponent, createRTKReducerFile, createReduxActionFile, createReduxReducerFile }
|
|
@@ -0,0 +1,38 @@
|
|
|
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 { componentName, reducerName } = options;
|
|
8
|
+
|
|
9
|
+
// Insert the node at the top of the file
|
|
10
|
+
root.find(jscodeshift.Program).get('body', 0).insertBefore(`import { ${reducerName}Reducer } from '@containers/${componentName}/reducer.js'`);
|
|
11
|
+
|
|
12
|
+
root.find(jscodeshift.CallExpression, {
|
|
13
|
+
callee: {
|
|
14
|
+
name: 'combineReducers'
|
|
15
|
+
}
|
|
16
|
+
}).forEach(path => {
|
|
17
|
+
const args = path.value.arguments;
|
|
18
|
+
if (args.length > 0 && args[0].type === 'ObjectExpression') {
|
|
19
|
+
args[0].properties.push(
|
|
20
|
+
jscodeshift.property(
|
|
21
|
+
'init',
|
|
22
|
+
jscodeshift.identifier(`${reducerName}Reducer`),
|
|
23
|
+
jscodeshift.identifier(`${reducerName}Reducer`)
|
|
24
|
+
)
|
|
25
|
+
);
|
|
26
|
+
args[0].properties.forEach(property => {
|
|
27
|
+
if (property.key.name === property.value.name) {
|
|
28
|
+
property.shorthand = true;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
console.log(`\nReducer added in ${pc.gray("src/js/store/index.js")}`);
|
|
35
|
+
return root.toSource();
|
|
36
|
+
|
|
37
|
+
};
|
|
38
|
+
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
// Insert the node at the top of the file
|
|
19
|
+
root.find(jscodeshift.Program).get('body', 0).insertBefore(`import ${componentName} from '@containers/${componentName}/${componentName}'`);
|
|
20
|
+
|
|
21
|
+
root.find(jscodeshift.VariableDeclarator, { id: { name: 'routes' } })
|
|
22
|
+
.forEach(path => {
|
|
23
|
+
// Ensure we are modifying the top-level array expression
|
|
24
|
+
if (path.value.init.type === 'ArrayExpression') {
|
|
25
|
+
path.value.init.elements.push(newObject);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
console.log(pc.green('\nNew route added successfully.'));
|
|
30
|
+
return root.toSource();
|
|
31
|
+
|
|
32
|
+
};
|
|
33
|
+
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
const fs = require("fs")
|
|
2
|
+
const path = require("path")
|
|
3
|
+
const pc = require("picocolors")
|
|
4
|
+
const { execSync } = require('child_process');
|
|
5
|
+
|
|
6
|
+
// validates router path
|
|
7
|
+
function validatePath(path) {
|
|
8
|
+
const pathPattern = /^\/[a-zA-Z0-9-_]+(?:\/:[a-zA-Z0-9-_]+)?(?:\?[a-zA-Z0-9-_=]*)?$/;
|
|
9
|
+
|
|
10
|
+
if (!path.startsWith('/')) {
|
|
11
|
+
return "The path must start with a forward slash (`/`).";
|
|
12
|
+
}
|
|
13
|
+
if (!pathPattern.test(path)) {
|
|
14
|
+
if (!/^[\/a-zA-Z0-9-_]+/.test(path)) {
|
|
15
|
+
s
|
|
16
|
+
return "Only letters, digits, hyphens, and underscores are allowed after the initial slash.";
|
|
17
|
+
}
|
|
18
|
+
if (/\/[^:][a-zA-Z0-9-_]+/.test(path)) {
|
|
19
|
+
return "Parameters must start with a slash and a colon, followed by valid characters.";
|
|
20
|
+
}
|
|
21
|
+
if (/\?[^a-zA-Z0-9-_=]*$/.test(path)) {
|
|
22
|
+
return "Query strings must start with a question mark and contain valid characters.";
|
|
23
|
+
}
|
|
24
|
+
return "The path is incorrectly formatted.";
|
|
25
|
+
}
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// validates component name
|
|
30
|
+
function validateComponentName(name) {
|
|
31
|
+
return /^[A-Z][a-zA-Z0-9]*$/.test(name) || "Component name should start with an uppercase letter and may contain alphanumeric characters";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
// discard changes if anything breaks
|
|
36
|
+
function discardChanges({ componentName, containersDir }) {
|
|
37
|
+
if (fs.existsSync(`${containersDir}/${componentName}`)) {
|
|
38
|
+
fs.rmSync(`${containersDir}/${componentName}`, { recursive: true, force: true });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// creates directory using given input
|
|
43
|
+
function createDirectory({ componentName, containersDir }) {
|
|
44
|
+
try {
|
|
45
|
+
// directory check
|
|
46
|
+
if (fs.existsSync(`${containersDir}/${componentName}`)) {
|
|
47
|
+
throw new Error("directory with similar name already exist");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
fs.mkdirSync(`${containersDir}/${componentName}`)
|
|
51
|
+
console.log(`\n${pc.cyan(componentName)} directory created at ${pc.gray(containersDir)}`);
|
|
52
|
+
|
|
53
|
+
return true
|
|
54
|
+
|
|
55
|
+
} catch (e) {
|
|
56
|
+
console.log(pc.red(`\nError: ${e}`))
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// adds route object inside src/js/route/index.js file
|
|
61
|
+
function createNewRoute({ componentName, routePath, routeTransformerPath }) {
|
|
62
|
+
const command = `jscodeshift --silent -t ${routeTransformerPath} --routePath ${routePath} --componentName ${componentName} src/js/routes/index.js`;
|
|
63
|
+
execSync(command, { stdio: 'inherit' });
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// adds newly created reducer into src/js/store/index.js file
|
|
67
|
+
function createReducerEntryInStore({ componentName, routePath, reducerTransformerPath, reducerName }) {
|
|
68
|
+
const command = `jscodeshift --silent -t ${reducerTransformerPath} --reducerName ${reducerName} --routePath ${routePath} --componentName ${componentName} src/js/store/index.js`;
|
|
69
|
+
execSync(command, { stdio: 'inherit' });
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// converts string to camel case
|
|
73
|
+
function toCamelCase(str) {
|
|
74
|
+
return str.toLowerCase().replace(/[^a-zA-Z0-9]+(.)/g, (match, chr) => chr.toUpperCase());
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function checkIfRoutePathExist({routePath, componentName}) {
|
|
78
|
+
const routeIndexPath = "src/js/routes/index.js";
|
|
79
|
+
const data = fs.readFileSync(routeIndexPath, 'utf8')
|
|
80
|
+
// Check if the file content includes routePath
|
|
81
|
+
if (data.includes(routePath)) {
|
|
82
|
+
throw new Error(`${routePath} path already exist in src/js/routes/index.js`)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (data.includes(`@containers/${componentName}/${componentName}`)) {
|
|
86
|
+
throw new Error(`${componentName} component path already exist in src/js/routes/index.js`)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
module.exports = { validatePath, validateComponentName, discardChanges, createReducerEntryInStore, createNewRoute, createDirectory, toCamelCase, checkIfRoutePathExist }
|
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.
|
|
4
|
+
"version": "0.0.1-beta.60",
|
|
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
|
|
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,14 +27,30 @@ 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
|
+
const createRoutePath = path.join(__dirname, "../codemod/new-route/index.js")
|
|
32
|
+
execSync(`node ${createRoutePath}`, { stdio: "inherit" })
|
|
33
|
+
return
|
|
34
|
+
}
|
|
35
|
+
|
|
31
36
|
// Use options provided through commander or prompt the user
|
|
32
37
|
validateOptions(cmd)
|
|
33
38
|
const projectName = folderName || (await promptProjectName())
|
|
39
|
+
let isNameValid = validate(projectName)
|
|
40
|
+
if (!isNameValid.validForNewPackages) {
|
|
41
|
+
isNameValid?.warnings?.forEach?.((item) => console.log(red(item)))
|
|
42
|
+
isNameValid?.errors?.forEach?.((item) => console.log(red(item)))
|
|
43
|
+
process.exit(1)
|
|
44
|
+
}
|
|
45
|
+
let projectPath = path.join(process.cwd(), projectName)
|
|
46
|
+
if (fs.existsSync(projectPath)) {
|
|
47
|
+
console.log(red(`${projectName} already exists, try again.`))
|
|
48
|
+
process.exit(1)
|
|
49
|
+
}
|
|
34
50
|
const language = "js"
|
|
35
51
|
const projectDescription = await promptDescription()
|
|
36
52
|
const stateManagement = cmd.stateManagement || (await promptStateManagement())
|
|
37
53
|
|
|
38
|
-
|
|
39
54
|
// Define mapping of options to repository suffixes
|
|
40
55
|
const repositorySuffixes = {
|
|
41
56
|
js: "js",
|
|
@@ -53,31 +68,41 @@ const program = new Commander.Command()
|
|
|
53
68
|
const subDirectoriesToExtract = [commonCodeDirectory, selectedTemplateCode]
|
|
54
69
|
const extractionDestination = `/${projectName}/`
|
|
55
70
|
let tempDir
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
71
|
+
;(() => {
|
|
72
|
+
try {
|
|
73
|
+
tempDir = createTempDir()
|
|
74
|
+
|
|
75
|
+
const packageFilePath = packNpmPackage(packageName, packageVersion, tempDir)
|
|
59
76
|
|
|
60
|
-
|
|
77
|
+
extractSubdirectory(packageFilePath)
|
|
78
|
+
createGitignore(projectName)
|
|
61
79
|
|
|
62
|
-
|
|
63
|
-
|
|
80
|
+
execSync(
|
|
81
|
+
`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"`,
|
|
82
|
+
{ stdio: "inherit" }
|
|
83
|
+
)
|
|
64
84
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
} && git init --quiet`,
|
|
68
|
-
{ stdio: "inherit" }
|
|
69
|
-
)
|
|
85
|
+
console.log(`\n${green(bold("Success!"))} created ${projectName} at ${projectPath}`)
|
|
86
|
+
console.log("Inside this directory, you can run the following commands.")
|
|
70
87
|
|
|
71
|
-
|
|
88
|
+
console.log(cyan(bold(" \n npm run start")))
|
|
89
|
+
console.log(" Starts the development server ")
|
|
72
90
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
deleteDirectory(tempDir)
|
|
76
|
-
console.error(`Error: ${error.message}`)
|
|
77
|
-
process.exit(1)
|
|
78
|
-
}
|
|
79
|
-
})()
|
|
91
|
+
console.log(cyan(bold("\n npm run build")))
|
|
92
|
+
console.log(" Bundles the app for production ")
|
|
80
93
|
|
|
94
|
+
console.log(cyan(bold("\n npm run serve")))
|
|
95
|
+
console.log(" Serves the production build ")
|
|
96
|
+
|
|
97
|
+
console.log("\nWe suggest you to begin, by running")
|
|
98
|
+
console.log(` ${cyan("cd")} ${projectName} && ${cyan("npm start")} \n\n`)
|
|
99
|
+
} catch (error) {
|
|
100
|
+
console.error(`Error: ${error.message}`)
|
|
101
|
+
process.exit(1)
|
|
102
|
+
} finally {
|
|
103
|
+
deleteDirectory(tempDir)
|
|
104
|
+
}
|
|
105
|
+
})()
|
|
81
106
|
function packNpmPackage(packageName, packageVersion, tempDir) {
|
|
82
107
|
const tarballFileName = `${packageName}-${packageVersion}.tgz`
|
|
83
108
|
const tarballFilePath = path.join(tempDir, tarballFileName)
|
|
@@ -172,10 +197,10 @@ async function promptProjectName() {
|
|
|
172
197
|
if (!res.path || projectName === "") {
|
|
173
198
|
console.log(
|
|
174
199
|
"\nPlease specify the project directory:\n" +
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
200
|
+
` ${cyan(program.name())} ${green("<project-directory>")}\n` +
|
|
201
|
+
"For example:\n" +
|
|
202
|
+
` ${cyan(program.name())} ${green("my-next-app")}\n\n` +
|
|
203
|
+
`Run ${cyan(`${program.name()} --help`)} to see all options.`
|
|
179
204
|
)
|
|
180
205
|
process.exit(1)
|
|
181
206
|
}
|
|
@@ -221,21 +246,14 @@ function deleteDirectory(dirPath) {
|
|
|
221
246
|
|
|
222
247
|
// Function to create a .gitignore file with the hardcoded patterns
|
|
223
248
|
function createGitignore(projectName) {
|
|
249
|
+
const gitiIgnorePatterns = ["node_modules", "build", "logs"]
|
|
224
250
|
|
|
225
|
-
const
|
|
226
|
-
'node_modules/*',
|
|
227
|
-
'build/*',
|
|
228
|
-
'logs/*'
|
|
229
|
-
];
|
|
230
|
-
|
|
231
|
-
const gitignorePath = path.join(process.cwd(), projectName, '.gitignore');
|
|
251
|
+
const gitignorePath = path.join(process.cwd(), projectName, ".gitignore")
|
|
232
252
|
|
|
233
253
|
if (fs.existsSync(gitignorePath)) {
|
|
234
|
-
console.log(
|
|
235
|
-
return
|
|
254
|
+
console.log(".gitignore already exists. Please rename or remove it before running the script.")
|
|
255
|
+
return
|
|
236
256
|
}
|
|
237
257
|
|
|
238
|
-
fs.writeFileSync(gitignorePath, gitiIgnorePatterns.join(
|
|
258
|
+
fs.writeFileSync(gitignorePath, gitiIgnorePatterns.join("\n"))
|
|
239
259
|
}
|
|
240
|
-
|
|
241
|
-
// Create .gitignore with hardcoded patterns
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
**/build/*
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"rules": {
|
|
3
|
+
"react-hooks/exhaustive-deps": "error" // Checks effect dependencies
|
|
4
|
+
},
|
|
5
|
+
"env": {
|
|
6
|
+
"browser": true,
|
|
7
|
+
"es6": true,
|
|
8
|
+
"node": true
|
|
9
|
+
},
|
|
10
|
+
"extends": [
|
|
11
|
+
"eslint:recommended",
|
|
12
|
+
"plugin:react/recommended",
|
|
13
|
+
],
|
|
14
|
+
"parserOptions": {
|
|
15
|
+
"sourceType": "module",
|
|
16
|
+
"ecmaVersion": "latest"
|
|
17
|
+
},
|
|
18
|
+
"plugins": [
|
|
19
|
+
"react",
|
|
20
|
+
"react-hooks"
|
|
21
|
+
],
|
|
22
|
+
"settings": {
|
|
23
|
+
"react": {
|
|
24
|
+
"pragma": "React",
|
|
25
|
+
"version": "detect"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
## Getting Started
|
|
2
2
|
|
|
3
|
-
Commence development by initiating the
|
|
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,
|
|
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
|
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,8 @@
|
|
|
1
|
-
|
|
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
|
|
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
|
|
23
|
+
export default Home
|
|
@@ -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
|
|
10
|
+
const { __ROUTER_INITIAL_DATA__: routerInitialData } = window
|
|
11
11
|
|
|
12
12
|
const router = clientRouter({ routerInitialState: routerInitialData })
|
|
13
13
|
|
|
14
14
|
const Application = (
|
|
15
|
-
<
|
|
16
|
-
<
|
|
17
|
-
|
|
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-beta.
|
|
21
|
-
"catalyst-core-internal": "
|
|
22
|
+
"@tata1mg/router": "^0.0.1-beta.7",
|
|
23
|
+
"catalyst-core-internal": "0.0.1-beta.60"
|
|
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
|
}
|
|
@@ -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-beta.
|
|
21
|
-
"catalyst-core-internal": "
|
|
23
|
+
"@tata1mg/router": "^0.0.1-beta.7",
|
|
24
|
+
"catalyst-core-internal": "0.0.1-beta.60",
|
|
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
|
}
|
|
@@ -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
|
|
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 }),
|
|
@@ -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-beta.
|
|
21
|
-
"catalyst-core-internal": "
|
|
23
|
+
"@tata1mg/router": "^0.0.1-beta.7",
|
|
24
|
+
"catalyst-core-internal": "0.0.1-beta.60",
|
|
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
|
}
|
|
@@ -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
|
|
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,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
|
-
}
|