create-catalyst-app-internal 0.0.1-beta.7 → 0.0.1-beta.70
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/my-app/.eslintignore +1 -0
- package/my-app/.eslintrc +28 -0
- package/my-app/README.md +25 -0
- package/my-app/api.js +16 -0
- package/my-app/client/index.js +23 -0
- package/my-app/client/styles.js +3 -0
- package/my-app/config/config.json +12 -0
- package/my-app/mcp/context.md +509 -0
- package/my-app/mcp/mcp.js +36 -0
- package/my-app/package-lock.json +11723 -0
- package/my-app/package.json +34 -0
- package/my-app/postcss.config.js +5 -0
- package/my-app/public/favicon.ico +0 -0
- package/my-app/server/document.js +12 -0
- package/my-app/server/index.js +2 -0
- package/my-app/server/server.js +8 -0
- package/my-app/src/js/containers/App/index.js +16 -0
- package/my-app/src/js/containers/Home/Home.js +23 -0
- package/my-app/src/js/containers/Home/Home.scss +34 -0
- package/my-app/src/js/routes/index.js +11 -0
- package/my-app/src/js/routes/utils.js +42 -0
- package/my-app/src/static/css/base/index.scss +2 -0
- package/my-app/src/static/css/base/styles.scss +3 -0
- package/my-app/src/static/css/resources/_variables.scss +0 -0
- package/my-app/webpackConfig.js +6 -0
- package/package.json +6 -7
- package/scripts/cli.cjs +163 -42
- 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 +3 -5
- package/templates/common/server/index.js +1 -0
- package/templates/common/server/server.js +8 -1
- package/templates/common/src/js/routes/index.js +0 -6
- package/templates/common/webpackConfig.js +1 -0
- package/templates/mcp-root/mcp/context.md +509 -0
- package/templates/mcp-root/mcp/mcp.js +36 -0
- package/templates/none-js/client/index.js +5 -7
- 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/none-ts/client/index.js +23 -0
- package/templates/none-ts/package.json +34 -0
- package/templates/none-ts/src/js/containers/App/index.js +16 -0
- package/templates/none-ts/src/js/routes/utils.js +42 -0
- package/templates/none-ts/tsconfig.json +13 -0
- package/templates/none-ts/types.d.ts +4 -0
- package/templates/redux-js/client/index.js +1 -1
- 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 +0 -1
- package/templates/redux-js/src/js/routes/utils.js +42 -0
- package/templates/redux-js/src/js/store/index.js +2 -2
- package/templates/redux-ts/client/index.js +28 -0
- package/templates/redux-ts/package.json +37 -0
- package/templates/redux-ts/src/js/containers/App/actions.js +17 -0
- package/templates/redux-ts/src/js/containers/App/index.js +16 -0
- package/templates/redux-ts/src/js/containers/App/reducer.js +19 -0
- package/templates/redux-ts/src/js/routes/utils.js +42 -0
- package/templates/redux-ts/src/js/store/index.js +28 -0
- package/templates/redux-ts/tsconfig.json +13 -0
- package/templates/redux-ts/types.d.ts +4 -0
- package/templates/rtk-js/client/index.js +1 -1
- 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/rtk-ts/client/index.js +28 -0
- package/templates/rtk-ts/package.json +37 -0
- package/templates/rtk-ts/src/js/containers/App/index.js +16 -0
- package/templates/rtk-ts/src/js/containers/App/reducer.js +18 -0
- package/templates/rtk-ts/src/js/routes/utils.js +42 -0
- package/templates/rtk-ts/src/js/store/index.js +28 -0
- package/templates/rtk-ts/tsconfig.json +13 -0
- package/templates/rtk-ts/types.d.ts +4 -0
- package/templates/tailwind/postcss.config.js +5 -0
- package/templates/tailwind/src/static/css/base/index.scss +2 -0
- 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
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
**/build/*
|
package/my-app/.eslintrc
ADDED
|
@@ -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
|
+
}
|
package/my-app/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
## Getting Started
|
|
2
|
+
|
|
3
|
+
Commence development by initiating the the following commands:
|
|
4
|
+
|
|
5
|
+
For running the application in development mode, run:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm run start
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
For a production build, change NODE_ENV to "production" in config/config.json, then run :
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm run build
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
To serve the production build, execute:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm run serve
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Documentation
|
|
24
|
+
|
|
25
|
+
Explore the complete documentation at [https://catalyst.1mg.com](https://catalyst.1mg.com).
|
package/my-app/api.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const fetchFunction = (url, options) => {
|
|
2
|
+
let baseURL = process.env.API_URL
|
|
3
|
+
let finalUrl = baseURL + url
|
|
4
|
+
|
|
5
|
+
// Request Interceptor - modify request here
|
|
6
|
+
|
|
7
|
+
return fetch(finalUrl, options)
|
|
8
|
+
.then(response => {
|
|
9
|
+
return response.json().then(parsedResponse => {
|
|
10
|
+
// Response Interceptor - modify response here
|
|
11
|
+
return parsedResponse
|
|
12
|
+
})
|
|
13
|
+
})
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default fetchFunction
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from "react"
|
|
2
|
+
import "./styles"
|
|
3
|
+
import { hydrateRoot } from "react-dom/client"
|
|
4
|
+
import { loadableReady } from "@loadable/component"
|
|
5
|
+
import { RouterProvider } from "@tata1mg/router"
|
|
6
|
+
import clientRouter from "catalyst-core/router/ClientRouter"
|
|
7
|
+
|
|
8
|
+
window.addEventListener("load", () => {
|
|
9
|
+
loadableReady(() => {
|
|
10
|
+
const { __ROUTER_INITIAL_DATA__: routerInitialData } = window
|
|
11
|
+
|
|
12
|
+
const router = clientRouter({ routerInitialState: routerInitialData })
|
|
13
|
+
|
|
14
|
+
const Application = (
|
|
15
|
+
<React.StrictMode>
|
|
16
|
+
<RouterProvider router={router} />
|
|
17
|
+
</React.StrictMode>
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
const container = document.getElementById("app")
|
|
21
|
+
hydrateRoot(container, Application)
|
|
22
|
+
})
|
|
23
|
+
})
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"NODE_SERVER_HOSTNAME": "localhost",
|
|
3
|
+
"NODE_SERVER_PORT": 3005,
|
|
4
|
+
"WEBPACK_DEV_SERVER_HOSTNAME": "localhost",
|
|
5
|
+
"WEBPACK_DEV_SERVER_PORT": 3006,
|
|
6
|
+
"BUILD_OUTPUT_PATH": "build",
|
|
7
|
+
"PUBLIC_STATIC_ASSET_PATH": "/assets/",
|
|
8
|
+
"PUBLIC_STATIC_ASSET_URL": "http://localhost:3005",
|
|
9
|
+
"API_URL": "",
|
|
10
|
+
"ANALYZE_BUNDLE": false,
|
|
11
|
+
"CLIENT_ENV_VARIABLES": ["API_URL"]
|
|
12
|
+
}
|