create-catalyst-app-internal 0.0.1-beta.27 → 0.0.1-beta.29
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/package.json
CHANGED
|
@@ -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 = path.join(__dirname, "../", '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
|
+
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
"serve": "catalyst serve",
|
|
8
8
|
"lint": "eslint .",
|
|
9
9
|
"devBuild": "catalyst devBuild",
|
|
10
|
-
"devServe": "catalyst devServe"
|
|
10
|
+
"devServe": "catalyst devServe",
|
|
11
|
+
"create-route": "node codemod/createNewRoute.js"
|
|
11
12
|
},
|
|
12
13
|
"_moduleAliases": {
|
|
13
14
|
"@api": "api.js",
|
|
@@ -19,8 +20,11 @@
|
|
|
19
20
|
},
|
|
20
21
|
"dependencies": {
|
|
21
22
|
"@loadable/component": "^5.16.3",
|
|
22
|
-
"@tata1mg/router": "^0.0.
|
|
23
|
-
"catalyst-core-internal": "^0.0.1-beta.
|
|
23
|
+
"@tata1mg/router": "^0.0.2-test.2",
|
|
24
|
+
"catalyst-core-internal": "^0.0.1-beta.23",
|
|
25
|
+
"commander": "^12.1.0",
|
|
26
|
+
"jscodeshift": "^0.16.0",
|
|
27
|
+
"prompts": "^2.4.2"
|
|
24
28
|
},
|
|
25
29
|
"devDependencies": {
|
|
26
30
|
"eslint": "^8.26.0",
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
"serve": "catalyst serve",
|
|
8
8
|
"lint": "eslint .",
|
|
9
9
|
"devBuild": "catalyst devBuild",
|
|
10
|
-
"devServe": "catalyst devServe"
|
|
10
|
+
"devServe": "catalyst devServe",
|
|
11
|
+
"create-route": "node codemod/createNewRoute.js"
|
|
11
12
|
},
|
|
12
13
|
"_moduleAliases": {
|
|
13
14
|
"@api": "api.js",
|
|
@@ -20,10 +21,13 @@
|
|
|
20
21
|
},
|
|
21
22
|
"dependencies": {
|
|
22
23
|
"@loadable/component": "^5.16.3",
|
|
23
|
-
"@tata1mg/router": "^0.0.
|
|
24
|
-
"catalyst-core-internal": "^0.0.1-beta.
|
|
24
|
+
"@tata1mg/router": "^0.0.2-test.2",
|
|
25
|
+
"catalyst-core-internal": "^0.0.1-beta.23",
|
|
25
26
|
"@reduxjs/toolkit": "1.9.3",
|
|
26
|
-
"react-redux": "^8.1.3"
|
|
27
|
+
"react-redux": "^8.1.3",
|
|
28
|
+
"commander": "^12.1.0",
|
|
29
|
+
"jscodeshift": "^0.16.0",
|
|
30
|
+
"prompts": "^2.4.2"
|
|
27
31
|
},
|
|
28
32
|
"devDependencies": {
|
|
29
33
|
"eslint": "^8.26.0",
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
"serve": "catalyst serve",
|
|
8
8
|
"lint": "eslint .",
|
|
9
9
|
"devBuild": "catalyst devBuild",
|
|
10
|
-
"devServe": "catalyst devServe"
|
|
10
|
+
"devServe": "catalyst devServe",
|
|
11
|
+
"create-route": "node codemod/createNewRoute.js"
|
|
11
12
|
},
|
|
12
13
|
"_moduleAliases": {
|
|
13
14
|
"@api": "api.js",
|
|
@@ -20,10 +21,13 @@
|
|
|
20
21
|
},
|
|
21
22
|
"dependencies": {
|
|
22
23
|
"@loadable/component": "^5.16.3",
|
|
23
|
-
"@tata1mg/router": "^0.0.
|
|
24
|
-
"catalyst-core-internal": "^0.0.1-beta.
|
|
24
|
+
"@tata1mg/router": "^0.0.2-test.2",
|
|
25
|
+
"catalyst-core-internal": "^0.0.1-beta.23",
|
|
25
26
|
"@reduxjs/toolkit": "1.9.3",
|
|
26
|
-
"react-redux": "^8.1.3"
|
|
27
|
+
"react-redux": "^8.1.3",
|
|
28
|
+
"commander": "^12.1.0",
|
|
29
|
+
"jscodeshift": "^0.16.0",
|
|
30
|
+
"prompts": "^2.4.2"
|
|
27
31
|
},
|
|
28
32
|
"devDependencies": {
|
|
29
33
|
"eslint": "^8.26.0",
|