create-catalyst-app 0.1.0-beta.1 → 0.1.0-beta.2
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/codemod/new-route/index.js +50 -35
- package/codemod/new-route/template.js +17 -21
- package/codemod/new-route/transformers/createReducer.js +19 -19
- package/codemod/new-route/transformers/createRoute.js +18 -19
- package/codemod/new-route/utils.js +34 -24
- package/package.json +11 -3
- package/scripts/cli.cjs +27 -15
- package/templates/common/api.js +5 -6
- package/templates/none-js/package.json +1 -1
- package/templates/none-ts/package.json +1 -1
- package/templates/redux-js/package.json +2 -2
- package/templates/redux-ts/package.json +2 -2
- package/templates/rtk-js/package.json +2 -2
- package/templates/rtk-ts/package.json +2 -2
|
@@ -1,21 +1,34 @@
|
|
|
1
1
|
const fs = require("fs")
|
|
2
2
|
const path = require("path")
|
|
3
3
|
const pc = require("picocolors")
|
|
4
|
-
const prompts = require(
|
|
5
|
-
const { program } = require(
|
|
6
|
-
|
|
7
|
-
const {
|
|
8
|
-
|
|
4
|
+
const prompts = require("prompts")
|
|
5
|
+
const { program } = require("commander")
|
|
6
|
+
|
|
7
|
+
const {
|
|
8
|
+
createNewComponent,
|
|
9
|
+
createRTKReducerFile,
|
|
10
|
+
createReduxActionFile,
|
|
11
|
+
createReduxReducerFile,
|
|
12
|
+
} = require("./template")
|
|
13
|
+
const {
|
|
14
|
+
validateComponentName,
|
|
15
|
+
validatePath,
|
|
16
|
+
discardChanges,
|
|
17
|
+
createDirectory,
|
|
18
|
+
createReducerEntryInStore,
|
|
19
|
+
createNewRoute,
|
|
20
|
+
toCamelCase,
|
|
21
|
+
checkIfRoutePathExist,
|
|
22
|
+
} = require("./utils")
|
|
9
23
|
|
|
10
24
|
// Configure commander to accept CLI options
|
|
11
25
|
program
|
|
12
|
-
.option(
|
|
13
|
-
.option(
|
|
14
|
-
.parse(process.argv)
|
|
15
|
-
|
|
26
|
+
.option("-p, --path <path>", "Path for the new route")
|
|
27
|
+
.option("-c, --component <component>", "Component name for the new route")
|
|
28
|
+
.parse(process.argv)
|
|
16
29
|
|
|
17
30
|
async function main() {
|
|
18
|
-
let { routePath, templateType, componentName } = program
|
|
31
|
+
let { routePath, templateType, componentName } = program
|
|
19
32
|
|
|
20
33
|
// If all options are not provided, prompt the user for input
|
|
21
34
|
if (!routePath || !componentName || !templateType) {
|
|
@@ -31,40 +44,44 @@ async function main() {
|
|
|
31
44
|
],
|
|
32
45
|
},
|
|
33
46
|
{
|
|
34
|
-
type: routePath ? null :
|
|
35
|
-
name:
|
|
47
|
+
type: routePath ? null : "text",
|
|
48
|
+
name: "routePath",
|
|
36
49
|
message: "Enter the route path",
|
|
37
|
-
validate: validatePath
|
|
50
|
+
validate: validatePath,
|
|
38
51
|
},
|
|
39
52
|
{
|
|
40
|
-
type: componentName ? null :
|
|
41
|
-
name:
|
|
42
|
-
message:
|
|
43
|
-
validate: validateComponentName
|
|
44
|
-
}
|
|
45
|
-
])
|
|
53
|
+
type: componentName ? null : "text",
|
|
54
|
+
name: "componentName",
|
|
55
|
+
message: "Enter the component name for new route",
|
|
56
|
+
validate: validateComponentName,
|
|
57
|
+
},
|
|
58
|
+
])
|
|
46
59
|
|
|
47
|
-
routePath = routePath || response.routePath
|
|
60
|
+
routePath = routePath || response.routePath
|
|
48
61
|
templateType = templateType || response.templateType
|
|
49
|
-
componentName = componentName || response.componentName
|
|
62
|
+
componentName = componentName || response.componentName
|
|
50
63
|
}
|
|
51
64
|
|
|
52
|
-
|
|
53
65
|
// Code transformations
|
|
54
66
|
if (componentName && routePath && templateType) {
|
|
55
|
-
|
|
56
67
|
const reducerName = toCamelCase(componentName)
|
|
57
|
-
const containersDir =
|
|
58
|
-
const routeTransformerPath = path.join(__dirname, "./",
|
|
59
|
-
const reducerTransformerPath = path.join(__dirname, "./",
|
|
60
|
-
|
|
61
|
-
const funcArgs = {
|
|
68
|
+
const containersDir = "src/js/containers"
|
|
69
|
+
const routeTransformerPath = path.join(__dirname, "./", "transformers/createRoute.js")
|
|
70
|
+
const reducerTransformerPath = path.join(__dirname, "./", "transformers/createReducer.js")
|
|
71
|
+
|
|
72
|
+
const funcArgs = {
|
|
73
|
+
containersDir,
|
|
74
|
+
componentName,
|
|
75
|
+
routePath,
|
|
76
|
+
reducerName,
|
|
77
|
+
templateType,
|
|
78
|
+
reducerTransformerPath,
|
|
79
|
+
routeTransformerPath,
|
|
80
|
+
}
|
|
62
81
|
|
|
63
|
-
// create directory
|
|
82
|
+
// create directory
|
|
64
83
|
if (createDirectory(funcArgs)) {
|
|
65
|
-
|
|
66
84
|
try {
|
|
67
|
-
|
|
68
85
|
checkIfRoutePathExist(funcArgs)
|
|
69
86
|
|
|
70
87
|
if (templateType === "none") {
|
|
@@ -84,15 +101,13 @@ async function main() {
|
|
|
84
101
|
createReducerEntryInStore(funcArgs)
|
|
85
102
|
}
|
|
86
103
|
|
|
87
|
-
createNewRoute(funcArgs)
|
|
88
|
-
|
|
104
|
+
createNewRoute(funcArgs)
|
|
89
105
|
} catch (e) {
|
|
90
106
|
discardChanges(funcArgs)
|
|
91
107
|
console.log(pc.red(`\n${e}`))
|
|
92
108
|
}
|
|
93
109
|
}
|
|
94
|
-
|
|
95
110
|
}
|
|
96
111
|
}
|
|
97
112
|
|
|
98
|
-
main()
|
|
113
|
+
main()
|
|
@@ -4,8 +4,7 @@ const pc = require("picocolors")
|
|
|
4
4
|
|
|
5
5
|
// Function to create component using given input
|
|
6
6
|
function createNewComponent({ componentName, containersDir }) {
|
|
7
|
-
|
|
8
|
-
const componentPath = path.join(containersDir, `${componentName}/${componentName}.js`);
|
|
7
|
+
const componentPath = path.join(containersDir, `${componentName}/${componentName}.js`)
|
|
9
8
|
|
|
10
9
|
// Component template
|
|
11
10
|
const componentTemplate = `import React from 'react';
|
|
@@ -20,16 +19,15 @@ function createNewComponent({ componentName, containersDir }) {
|
|
|
20
19
|
};
|
|
21
20
|
|
|
22
21
|
export default ${componentName};
|
|
23
|
-
|
|
22
|
+
`
|
|
24
23
|
|
|
25
|
-
fs.writeFileSync(componentPath, componentTemplate,
|
|
26
|
-
console.log(`\n${pc.cyan(componentName)} component created at ${pc.gray(componentPath)}`)
|
|
24
|
+
fs.writeFileSync(componentPath, componentTemplate, "utf8")
|
|
25
|
+
console.log(`\n${pc.cyan(componentName)} component created at ${pc.gray(componentPath)}`)
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
|
|
30
28
|
// Function to create rtk reducer file using given input
|
|
31
29
|
function createRTKReducerFile({ componentName, containersDir, reducerName }) {
|
|
32
|
-
const reducerPath = path.join(containersDir, `${componentName}/reducer.js`)
|
|
30
|
+
const reducerPath = path.join(containersDir, `${componentName}/reducer.js`)
|
|
33
31
|
|
|
34
32
|
// rtk reducer template
|
|
35
33
|
const reducerTemplate = `import { createSlice } from "@reduxjs/toolkit"
|
|
@@ -50,16 +48,15 @@ export const appSlice = createSlice({
|
|
|
50
48
|
|
|
51
49
|
export const { reduxTest } = appSlice.actions
|
|
52
50
|
export const ${reducerName}Reducer = appSlice.reducer
|
|
53
|
-
|
|
51
|
+
`
|
|
54
52
|
|
|
55
|
-
fs.writeFileSync(reducerPath, reducerTemplate,
|
|
56
|
-
console.log(`\n${pc.cyan("reducer.js")} file created at ${pc.gray(reducerPath)} `)
|
|
53
|
+
fs.writeFileSync(reducerPath, reducerTemplate, "utf8")
|
|
54
|
+
console.log(`\n${pc.cyan("reducer.js")} file created at ${pc.gray(reducerPath)} `)
|
|
57
55
|
}
|
|
58
56
|
|
|
59
|
-
|
|
60
57
|
// Function to create redux action file using given input
|
|
61
58
|
function createReduxActionFile({ componentName, containersDir, reducerName }) {
|
|
62
|
-
const actionsPath = path.join(containersDir, `${componentName}/actions.js`)
|
|
59
|
+
const actionsPath = path.join(containersDir, `${componentName}/actions.js`)
|
|
63
60
|
|
|
64
61
|
// redux action template
|
|
65
62
|
const actionTemplate = `const createActionTypes = (prefix, actionTypeList = []) => {
|
|
@@ -79,16 +76,15 @@ export const reduxTest = () => {
|
|
|
79
76
|
type: ${reducerName}Actions.REDUX_TEST,
|
|
80
77
|
}
|
|
81
78
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
fs.writeFileSync(actionsPath, actionTemplate, 'utf8');
|
|
85
|
-
console.log(`\n${pc.cyan("action.js")} file created at ${pc.gray(actionsPath)} `);
|
|
79
|
+
`
|
|
86
80
|
|
|
81
|
+
fs.writeFileSync(actionsPath, actionTemplate, "utf8")
|
|
82
|
+
console.log(`\n${pc.cyan("action.js")} file created at ${pc.gray(actionsPath)} `)
|
|
87
83
|
}
|
|
88
84
|
|
|
89
85
|
// Function to create redux reducer file using given input
|
|
90
86
|
function createReduxReducerFile({ componentName, containersDir, reducerName }) {
|
|
91
|
-
const reducerPath = path.join(containersDir, `${componentName}/reducer.js`)
|
|
87
|
+
const reducerPath = path.join(containersDir, `${componentName}/reducer.js`)
|
|
92
88
|
|
|
93
89
|
// redux reducer template
|
|
94
90
|
const reducerTemplate = `import { ${reducerName}Actions } from "./actions"
|
|
@@ -110,10 +106,10 @@ export const ${reducerName}Reducer = (state = defaultState, action) => {
|
|
|
110
106
|
return state
|
|
111
107
|
}
|
|
112
108
|
}
|
|
113
|
-
|
|
109
|
+
`
|
|
114
110
|
|
|
115
|
-
fs.writeFileSync(reducerPath, reducerTemplate,
|
|
116
|
-
console.log(`\n${pc.cyan("reducer.js")} file created at ${pc.gray(reducerPath)} `)
|
|
111
|
+
fs.writeFileSync(reducerPath, reducerTemplate, "utf8")
|
|
112
|
+
console.log(`\n${pc.cyan("reducer.js")} file created at ${pc.gray(reducerPath)} `)
|
|
117
113
|
}
|
|
118
114
|
|
|
119
|
-
module.exports = { createNewComponent, createRTKReducerFile, createReduxActionFile, createReduxReducerFile }
|
|
115
|
+
module.exports = { createNewComponent, createRTKReducerFile, createReduxActionFile, createReduxReducerFile }
|
|
@@ -1,38 +1,38 @@
|
|
|
1
1
|
const pc = require("picocolors")
|
|
2
2
|
|
|
3
3
|
module.exports = function (fileInfo, api, options) {
|
|
4
|
-
const jscodeshift = api.jscodeshift
|
|
5
|
-
const root = jscodeshift(fileInfo.source)
|
|
4
|
+
const jscodeshift = api.jscodeshift
|
|
5
|
+
const root = jscodeshift(fileInfo.source)
|
|
6
6
|
|
|
7
|
-
const { componentName, reducerName } = options
|
|
7
|
+
const { componentName, reducerName } = options
|
|
8
8
|
|
|
9
9
|
// Insert the node at the top of the file
|
|
10
|
-
root.find(jscodeshift.Program)
|
|
10
|
+
root.find(jscodeshift.Program)
|
|
11
|
+
.get("body", 0)
|
|
12
|
+
.insertBefore(`import { ${reducerName}Reducer } from '@containers/${componentName}/reducer.js'`)
|
|
11
13
|
|
|
12
14
|
root.find(jscodeshift.CallExpression, {
|
|
13
15
|
callee: {
|
|
14
|
-
name:
|
|
15
|
-
}
|
|
16
|
-
}).forEach(path => {
|
|
17
|
-
const args = path.value.arguments
|
|
18
|
-
if (args.length > 0 && args[0].type ===
|
|
16
|
+
name: "combineReducers",
|
|
17
|
+
},
|
|
18
|
+
}).forEach((path) => {
|
|
19
|
+
const args = path.value.arguments
|
|
20
|
+
if (args.length > 0 && args[0].type === "ObjectExpression") {
|
|
19
21
|
args[0].properties.push(
|
|
20
22
|
jscodeshift.property(
|
|
21
|
-
|
|
23
|
+
"init",
|
|
22
24
|
jscodeshift.identifier(`${reducerName}Reducer`),
|
|
23
25
|
jscodeshift.identifier(`${reducerName}Reducer`)
|
|
24
26
|
)
|
|
25
|
-
)
|
|
26
|
-
args[0].properties.forEach(property => {
|
|
27
|
+
)
|
|
28
|
+
args[0].properties.forEach((property) => {
|
|
27
29
|
if (property.key.name === property.value.name) {
|
|
28
|
-
property.shorthand = true
|
|
30
|
+
property.shorthand = true
|
|
29
31
|
}
|
|
30
|
-
})
|
|
32
|
+
})
|
|
31
33
|
}
|
|
32
34
|
})
|
|
33
35
|
|
|
34
|
-
console.log(`\nReducer added in ${pc.gray("src/js/store/index.js")}`)
|
|
35
|
-
return root.toSource()
|
|
36
|
-
|
|
37
|
-
};
|
|
38
|
-
|
|
36
|
+
console.log(`\nReducer added in ${pc.gray("src/js/store/index.js")}`)
|
|
37
|
+
return root.toSource()
|
|
38
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
const pc = require("picocolors")
|
|
2
2
|
|
|
3
3
|
module.exports = function (fileInfo, api, options) {
|
|
4
|
-
const jscodeshift = api.jscodeshift
|
|
5
|
-
const root = jscodeshift(fileInfo.source)
|
|
4
|
+
const jscodeshift = api.jscodeshift
|
|
5
|
+
const root = jscodeshift(fileInfo.source)
|
|
6
6
|
|
|
7
|
-
const { routePath, componentName } = options
|
|
7
|
+
const { routePath, componentName } = options
|
|
8
8
|
|
|
9
9
|
// Create a new route object using a template expression
|
|
10
10
|
const newObject = jscodeshift.template.expression`
|
|
@@ -13,21 +13,20 @@ module.exports = function (fileInfo, api, options) {
|
|
|
13
13
|
end: true,
|
|
14
14
|
component: ${componentName}
|
|
15
15
|
}
|
|
16
|
-
|
|
16
|
+
`
|
|
17
17
|
|
|
18
18
|
// Insert the node at the top of the file
|
|
19
|
-
root.find(jscodeshift.Program)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
19
|
+
root.find(jscodeshift.Program)
|
|
20
|
+
.get("body", 0)
|
|
21
|
+
.insertBefore(`import ${componentName} from '@containers/${componentName}/${componentName}'`)
|
|
22
|
+
|
|
23
|
+
root.find(jscodeshift.VariableDeclarator, { id: { name: "routes" } }).forEach((path) => {
|
|
24
|
+
// Ensure we are modifying the top-level array expression
|
|
25
|
+
if (path.value.init.type === "ArrayExpression") {
|
|
26
|
+
path.value.init.elements.push(newObject)
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
console.log(pc.green("\nNew route added successfully."))
|
|
31
|
+
return root.toSource()
|
|
32
|
+
}
|
|
@@ -1,41 +1,43 @@
|
|
|
1
1
|
const fs = require("fs")
|
|
2
2
|
const path = require("path")
|
|
3
3
|
const pc = require("picocolors")
|
|
4
|
-
const { execSync } = require(
|
|
4
|
+
const { execSync } = require("child_process")
|
|
5
5
|
|
|
6
6
|
// validates router path
|
|
7
7
|
function validatePath(path) {
|
|
8
|
-
const pathPattern = /^\/[a-zA-Z0-9-_]+(?:\/:[a-zA-Z0-9-_]+)?(?:\?[a-zA-Z0-9-_=]*)
|
|
8
|
+
const pathPattern = /^\/[a-zA-Z0-9-_]+(?:\/:[a-zA-Z0-9-_]+)?(?:\?[a-zA-Z0-9-_=]*)?$/
|
|
9
9
|
|
|
10
|
-
if (!path.startsWith(
|
|
11
|
-
return "The path must start with a forward slash (`/`)."
|
|
10
|
+
if (!path.startsWith("/")) {
|
|
11
|
+
return "The path must start with a forward slash (`/`)."
|
|
12
12
|
}
|
|
13
13
|
if (!pathPattern.test(path)) {
|
|
14
14
|
if (!/^[\/a-zA-Z0-9-_]+/.test(path)) {
|
|
15
15
|
s
|
|
16
|
-
return "Only letters, digits, hyphens, and underscores are allowed after the initial slash."
|
|
16
|
+
return "Only letters, digits, hyphens, and underscores are allowed after the initial slash."
|
|
17
17
|
}
|
|
18
18
|
if (/\/[^:][a-zA-Z0-9-_]+/.test(path)) {
|
|
19
|
-
return "Parameters must start with a slash and a colon, followed by valid characters."
|
|
19
|
+
return "Parameters must start with a slash and a colon, followed by valid characters."
|
|
20
20
|
}
|
|
21
21
|
if (/\?[^a-zA-Z0-9-_=]*$/.test(path)) {
|
|
22
|
-
return "Query strings must start with a question mark and contain valid characters."
|
|
22
|
+
return "Query strings must start with a question mark and contain valid characters."
|
|
23
23
|
}
|
|
24
|
-
return "The path is incorrectly formatted."
|
|
24
|
+
return "The path is incorrectly formatted."
|
|
25
25
|
}
|
|
26
|
-
return true
|
|
26
|
+
return true
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
// validates component name
|
|
30
30
|
function validateComponentName(name) {
|
|
31
|
-
return
|
|
31
|
+
return (
|
|
32
|
+
/^[A-Z][a-zA-Z0-9]*$/.test(name) ||
|
|
33
|
+
"Component name should start with an uppercase letter and may contain alphanumeric characters"
|
|
34
|
+
)
|
|
32
35
|
}
|
|
33
36
|
|
|
34
|
-
|
|
35
37
|
// discard changes if anything breaks
|
|
36
38
|
function discardChanges({ componentName, containersDir }) {
|
|
37
39
|
if (fs.existsSync(`${containersDir}/${componentName}`)) {
|
|
38
|
-
fs.rmSync(`${containersDir}/${componentName}`, { recursive: true, force: true })
|
|
40
|
+
fs.rmSync(`${containersDir}/${componentName}`, { recursive: true, force: true })
|
|
39
41
|
}
|
|
40
42
|
}
|
|
41
43
|
|
|
@@ -44,14 +46,13 @@ function createDirectory({ componentName, containersDir }) {
|
|
|
44
46
|
try {
|
|
45
47
|
// directory check
|
|
46
48
|
if (fs.existsSync(`${containersDir}/${componentName}`)) {
|
|
47
|
-
throw new Error("directory with similar name already exist")
|
|
49
|
+
throw new Error("directory with similar name already exist")
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
fs.mkdirSync(`${containersDir}/${componentName}`)
|
|
51
|
-
console.log(`\n${pc.cyan(componentName)} directory created at ${pc.gray(containersDir)}`)
|
|
53
|
+
console.log(`\n${pc.cyan(componentName)} directory created at ${pc.gray(containersDir)}`)
|
|
52
54
|
|
|
53
55
|
return true
|
|
54
|
-
|
|
55
56
|
} catch (e) {
|
|
56
57
|
console.log(pc.red(`\nError: ${e}`))
|
|
57
58
|
}
|
|
@@ -59,24 +60,24 @@ function createDirectory({ componentName, containersDir }) {
|
|
|
59
60
|
|
|
60
61
|
// adds route object inside src/js/route/index.js file
|
|
61
62
|
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:
|
|
63
|
+
const command = `jscodeshift --silent -t ${routeTransformerPath} --routePath ${routePath} --componentName ${componentName} src/js/routes/index.js`
|
|
64
|
+
execSync(command, { stdio: "inherit" })
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
// adds newly created reducer into src/js/store/index.js file
|
|
67
68
|
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:
|
|
69
|
+
const command = `jscodeshift --silent -t ${reducerTransformerPath} --reducerName ${reducerName} --routePath ${routePath} --componentName ${componentName} src/js/store/index.js`
|
|
70
|
+
execSync(command, { stdio: "inherit" })
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
// converts string to camel case
|
|
73
74
|
function toCamelCase(str) {
|
|
74
|
-
return str.toLowerCase().replace(/[^a-zA-Z0-9]+(.)/g, (match, chr) => chr.toUpperCase())
|
|
75
|
+
return str.toLowerCase().replace(/[^a-zA-Z0-9]+(.)/g, (match, chr) => chr.toUpperCase())
|
|
75
76
|
}
|
|
76
77
|
|
|
77
|
-
function checkIfRoutePathExist({routePath, componentName}) {
|
|
78
|
-
const routeIndexPath = "src/js/routes/index.js"
|
|
79
|
-
const data = fs.readFileSync(routeIndexPath,
|
|
78
|
+
function checkIfRoutePathExist({ routePath, componentName }) {
|
|
79
|
+
const routeIndexPath = "src/js/routes/index.js"
|
|
80
|
+
const data = fs.readFileSync(routeIndexPath, "utf8")
|
|
80
81
|
// Check if the file content includes routePath
|
|
81
82
|
if (data.includes(routePath)) {
|
|
82
83
|
throw new Error(`${routePath} path already exist in src/js/routes/index.js`)
|
|
@@ -87,4 +88,13 @@ function checkIfRoutePathExist({routePath, componentName}) {
|
|
|
87
88
|
}
|
|
88
89
|
}
|
|
89
90
|
|
|
90
|
-
module.exports = {
|
|
91
|
+
module.exports = {
|
|
92
|
+
validatePath,
|
|
93
|
+
validateComponentName,
|
|
94
|
+
discardChanges,
|
|
95
|
+
createReducerEntryInStore,
|
|
96
|
+
createNewRoute,
|
|
97
|
+
createDirectory,
|
|
98
|
+
toCamelCase,
|
|
99
|
+
checkIfRoutePathExist,
|
|
100
|
+
}
|
package/package.json
CHANGED
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-catalyst-app",
|
|
3
3
|
"bin": "scripts/cli.cjs",
|
|
4
|
-
"version": "0.1.0-beta.
|
|
4
|
+
"version": "0.1.0-beta.2",
|
|
5
5
|
"description": "cli package to scaffold Catalyst application",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/tata1mg/catalyst-core.git",
|
|
9
|
+
"directory": "packages/create-catalyst-app"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"prettify": "prettier . --write"
|
|
13
|
+
},
|
|
6
14
|
"dependencies": {
|
|
7
15
|
"commander": "^8.2.0",
|
|
8
16
|
"fs": "^0.0.1-security",
|
|
9
17
|
"https": "^1.0.0",
|
|
18
|
+
"jscodeshift": "^0.16.0",
|
|
10
19
|
"picocolors": "^0.1.0",
|
|
11
20
|
"prompts": "^2.4.0",
|
|
12
21
|
"tar": "^6.2.1",
|
|
13
|
-
"validate-npm-package-name": "^5.0.0"
|
|
14
|
-
"jscodeshift": "^0.16.0"
|
|
22
|
+
"validate-npm-package-name": "^5.0.0"
|
|
15
23
|
},
|
|
16
24
|
"devDependencies": {
|
|
17
25
|
"prettier": "^3.2.5"
|
package/scripts/cli.cjs
CHANGED
|
@@ -9,6 +9,7 @@ const path = require("path")
|
|
|
9
9
|
const fs = require("fs")
|
|
10
10
|
var validate = require("validate-npm-package-name")
|
|
11
11
|
const packageJson = require("../package.json")
|
|
12
|
+
const packageRoot = path.join(__dirname, "..")
|
|
12
13
|
|
|
13
14
|
let projectName = null
|
|
14
15
|
const program = new Commander.Command()
|
|
@@ -141,7 +142,13 @@ const program = new Commander.Command()
|
|
|
141
142
|
console.log(` ${cyan("cd")} ${projectName} && ${cyan("npm start")} \n\n`)
|
|
142
143
|
|
|
143
144
|
if (mcpSupport) {
|
|
144
|
-
const newMcpDir = path.join(
|
|
145
|
+
const newMcpDir = path.join(
|
|
146
|
+
process.cwd(),
|
|
147
|
+
projectName,
|
|
148
|
+
"node_modules",
|
|
149
|
+
"catalyst-core",
|
|
150
|
+
"mcp_v2"
|
|
151
|
+
)
|
|
145
152
|
runMcpSetup(newMcpDir, path.join(process.cwd(), projectName))
|
|
146
153
|
}
|
|
147
154
|
} catch (error) {
|
|
@@ -156,14 +163,15 @@ const program = new Commander.Command()
|
|
|
156
163
|
const tarballFilePath = path.join(tempDir, tarballFileName)
|
|
157
164
|
|
|
158
165
|
try {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
166
|
+
if (process.env.CREATE_CATALYST_APP_PACK_SOURCE === "local") {
|
|
167
|
+
execSync(`npm pack --pack-destination="${tempDir}" --silent`, {
|
|
168
|
+
cwd: packageRoot,
|
|
169
|
+
})
|
|
170
|
+
} else {
|
|
171
|
+
execSync(`npm pack ${packageName}@${packageVersion} --silent`, {
|
|
172
|
+
cwd: tempDir,
|
|
173
|
+
})
|
|
174
|
+
}
|
|
167
175
|
|
|
168
176
|
return tarballFilePath
|
|
169
177
|
} catch (error) {
|
|
@@ -221,20 +229,24 @@ program
|
|
|
221
229
|
.description("Set up MCP server in an existing catalyst project")
|
|
222
230
|
.action(() => {
|
|
223
231
|
try {
|
|
224
|
-
const mcpDir = path.join(process.cwd(), "node_modules
|
|
232
|
+
const mcpDir = path.join(process.cwd(), "node_modules", "catalyst-core", "mcp_v2")
|
|
225
233
|
const setupPath = path.join(mcpDir, "setup.js")
|
|
226
234
|
|
|
227
235
|
if (!fs.existsSync(setupPath)) {
|
|
228
236
|
console.log(cyan("mcp_v2 not found in catalyst-core. Downloading from GitHub..."))
|
|
229
|
-
const catalystCoreDir = path.join(process.cwd(), "node_modules
|
|
237
|
+
const catalystCoreDir = path.join(process.cwd(), "node_modules", "catalyst-core")
|
|
230
238
|
const tarballUrl = "https://github.com/tata1mg/catalyst-core/archive/refs/heads/main.tar.gz"
|
|
231
239
|
const tarballPath = path.join(catalystCoreDir, "_mcp_v2_tarball.tar.gz")
|
|
240
|
+
const repoMcpDir = "catalyst-core-main/packages/catalyst-core/mcp_v2"
|
|
232
241
|
execSync(`curl -fsSL "${tarballUrl}" -o "${tarballPath}"`, { stdio: "inherit" })
|
|
233
242
|
fs.mkdirSync(mcpDir, { recursive: true })
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
243
|
+
tar.extract({
|
|
244
|
+
file: tarballPath,
|
|
245
|
+
cwd: mcpDir,
|
|
246
|
+
sync: true,
|
|
247
|
+
strip: 4,
|
|
248
|
+
filter: (entryPath) => entryPath === repoMcpDir || entryPath.startsWith(`${repoMcpDir}/`),
|
|
249
|
+
})
|
|
238
250
|
fs.unlinkSync(tarballPath)
|
|
239
251
|
console.log(cyan("mcp_v2 downloaded successfully."))
|
|
240
252
|
}
|
package/templates/common/api.js
CHANGED
|
@@ -4,13 +4,12 @@ const fetchFunction = (url, options) => {
|
|
|
4
4
|
|
|
5
5
|
// Request Interceptor - modify request here
|
|
6
6
|
|
|
7
|
-
return fetch(finalUrl, options)
|
|
8
|
-
.then(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return parsedResponse
|
|
12
|
-
})
|
|
7
|
+
return fetch(finalUrl, options).then((response) => {
|
|
8
|
+
return response.json().then((parsedResponse) => {
|
|
9
|
+
// Response Interceptor - modify response here
|
|
10
|
+
return parsedResponse
|
|
13
11
|
})
|
|
12
|
+
})
|
|
14
13
|
}
|
|
15
14
|
|
|
16
15
|
export default fetchFunction
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@loadable/component": "^5.16.3",
|
|
29
29
|
"@tata1mg/router": "0.0.1-beta.7",
|
|
30
|
-
"catalyst-core": "0.1.0-beta.1",
|
|
31
30
|
"@reduxjs/toolkit": "1.9.3",
|
|
32
|
-
"react-redux": "^8.1.3"
|
|
31
|
+
"react-redux": "^8.1.3",
|
|
32
|
+
"catalyst-core": "0.1.0-beta.2"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"eslint": "^8.26.0",
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@loadable/component": "^5.16.3",
|
|
30
30
|
"@tata1mg/router": "0.0.1-beta.7",
|
|
31
|
-
"catalyst-core": "0.1.0-beta.1",
|
|
32
31
|
"@reduxjs/toolkit": "1.9.3",
|
|
33
|
-
"react-redux": "^8.1.3"
|
|
32
|
+
"react-redux": "^8.1.3",
|
|
33
|
+
"catalyst-core": "0.1.0-beta.2"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"eslint": "^8.26.0",
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@loadable/component": "^5.16.3",
|
|
29
29
|
"@tata1mg/router": "0.0.1-beta.7",
|
|
30
|
-
"catalyst-core": "0.1.0-beta.1",
|
|
31
30
|
"@reduxjs/toolkit": "1.9.3",
|
|
32
|
-
"react-redux": "^8.1.3"
|
|
31
|
+
"react-redux": "^8.1.3",
|
|
32
|
+
"catalyst-core": "0.1.0-beta.2"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"eslint": "^8.26.0",
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@loadable/component": "^5.16.3",
|
|
30
30
|
"@tata1mg/router": "0.0.1-beta.7",
|
|
31
|
-
"catalyst-core": "0.1.0-beta.1",
|
|
32
31
|
"@reduxjs/toolkit": "1.9.3",
|
|
33
|
-
"react-redux": "^8.1.3"
|
|
32
|
+
"react-redux": "^8.1.3",
|
|
33
|
+
"catalyst-core": "0.1.0-beta.2"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"eslint": "^8.26.0",
|