create-catalyst-app 0.0.3-canary.9 → 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.
@@ -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('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")
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('-p, --path <path>', 'Path for the new route')
13
- .option('-c, --component <component>', 'Component name for the new route')
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 : 'text',
35
- name: 'routePath',
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 : 'text',
41
- name: 'componentName',
42
- message: 'Enter the component name for new route',
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 = '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 }
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, 'utf8');
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, 'utf8');
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, 'utf8');
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).get('body', 0).insertBefore(`import { ${reducerName}Reducer } from '@containers/${componentName}/reducer.js'`);
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: 'combineReducers'
15
- }
16
- }).forEach(path => {
17
- const args = path.value.arguments;
18
- if (args.length > 0 && args[0].type === 'ObjectExpression') {
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
- 'init',
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).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
-
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('child_process');
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 /^[A-Z][a-zA-Z0-9]*$/.test(name) || "Component name should start with an uppercase letter and may contain alphanumeric characters";
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: 'inherit' });
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: 'inherit' });
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, 'utf8')
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 = { validatePath, validateComponentName, discardChanges, createReducerEntryInStore, createNewRoute, createDirectory, toCamelCase, checkIfRoutePathExist }
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.0.3-canary.9",
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()
@@ -93,11 +94,8 @@ const program = new Commander.Command()
93
94
  const commonCodeDirectory = "package/templates/common"
94
95
  const selectedTemplateCode = `package/templates/${repositorySuffixes[stateManagement]}-${repositorySuffixes[language]}`
95
96
  const tailwindCodeDirectory = "package/templates/tailwind"
96
- const mcpCodeDirectory = "package/templates/mcp-root"
97
-
98
97
  const subDirectoriesToExtract = [commonCodeDirectory, selectedTemplateCode]
99
98
  if (tailWindSupport) subDirectoriesToExtract.push(tailwindCodeDirectory)
100
- if (mcpSupport) subDirectoriesToExtract.push(mcpCodeDirectory)
101
99
 
102
100
  const extractionDestination = `/${projectName}/`
103
101
  let tempDir
@@ -121,10 +119,6 @@ const program = new Commander.Command()
121
119
  })
122
120
  }
123
121
 
124
- if (mcpSupport) {
125
- execSync(`cd ${projectName} && npm i @modelcontextprotocol/sdk`, { stdio: "inherit" })
126
- }
127
-
128
122
  execSync(
129
123
  `cd ${projectName} && git add . && git commit -m "initial commit from Create Catalyst App"`,
130
124
  {
@@ -146,6 +140,17 @@ const program = new Commander.Command()
146
140
 
147
141
  console.log("\nWe suggest you to begin, by running")
148
142
  console.log(` ${cyan("cd")} ${projectName} && ${cyan("npm start")} \n\n`)
143
+
144
+ if (mcpSupport) {
145
+ const newMcpDir = path.join(
146
+ process.cwd(),
147
+ projectName,
148
+ "node_modules",
149
+ "catalyst-core",
150
+ "mcp_v2"
151
+ )
152
+ runMcpSetup(newMcpDir, path.join(process.cwd(), projectName))
153
+ }
149
154
  } catch (error) {
150
155
  console.error(`Error: ${error.message}`)
151
156
  process.exit(1)
@@ -158,14 +163,15 @@ const program = new Commander.Command()
158
163
  const tarballFilePath = path.join(tempDir, tarballFileName)
159
164
 
160
165
  try {
161
- execSync(`npm pack ${packageName}@${packageVersion} --silent`, {
162
- cwd: tempDir,
163
- })
164
-
165
- // to test locally, comment the upper execSync and uncomment this one.
166
- // execSync(`npm pack --pack-destination=${tempDir} --silent`, {
167
- // cwd: process.cwd(),
168
- // })
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
+ }
169
175
 
170
176
  return tarballFilePath
171
177
  } catch (error) {
@@ -203,9 +209,6 @@ const program = new Commander.Command()
203
209
  if (entry.path.startsWith(tailwindCodeDirectory)) {
204
210
  entry.path = entry.path.replace(tailwindCodeDirectory, extractionDestination)
205
211
  }
206
- if (entry.path.startsWith(mcpCodeDirectory)) {
207
- entry.path = entry.path.replace(mcpCodeDirectory, extractionDestination)
208
- }
209
212
  },
210
213
  })
211
214
  } catch (e) {
@@ -221,8 +224,69 @@ const program = new Commander.Command()
221
224
  })
222
225
  .allowUnknownOption()
223
226
 
227
+ program
228
+ .command("catalyst-mcp")
229
+ .description("Set up MCP server in an existing catalyst project")
230
+ .action(() => {
231
+ try {
232
+ const mcpDir = path.join(process.cwd(), "node_modules", "catalyst-core", "mcp_v2")
233
+ const setupPath = path.join(mcpDir, "setup.js")
234
+
235
+ if (!fs.existsSync(setupPath)) {
236
+ console.log(cyan("mcp_v2 not found in catalyst-core. Downloading from GitHub..."))
237
+ const catalystCoreDir = path.join(process.cwd(), "node_modules", "catalyst-core")
238
+ const tarballUrl = "https://github.com/tata1mg/catalyst-core/archive/refs/heads/main.tar.gz"
239
+ const tarballPath = path.join(catalystCoreDir, "_mcp_v2_tarball.tar.gz")
240
+ const repoMcpDir = "catalyst-core-main/packages/catalyst-core/mcp_v2"
241
+ execSync(`curl -fsSL "${tarballUrl}" -o "${tarballPath}"`, { stdio: "inherit" })
242
+ fs.mkdirSync(mcpDir, { recursive: true })
243
+ tar.extract({
244
+ file: tarballPath,
245
+ cwd: mcpDir,
246
+ sync: true,
247
+ strip: 4,
248
+ filter: (entryPath) => entryPath === repoMcpDir || entryPath.startsWith(`${repoMcpDir}/`),
249
+ })
250
+ fs.unlinkSync(tarballPath)
251
+ console.log(cyan("mcp_v2 downloaded successfully."))
252
+ }
253
+
254
+ runMcpSetup(mcpDir)
255
+ } catch (error) {
256
+ console.error(red("An error occurred:"), error.message)
257
+ process.exit(1)
258
+ }
259
+ })
260
+
224
261
  program.parse(process.argv)
225
262
 
263
+ function runMcpSetup(mcpDir, cwd = process.cwd()) {
264
+ const pkgPath = path.join(mcpDir, "package.json")
265
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"))
266
+ pkg.dependencies["better-sqlite3"] = "^12.8.0"
267
+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2))
268
+
269
+ const mcpNodeModules = path.join(mcpDir, "node_modules")
270
+ let needsInstall = !fs.existsSync(mcpNodeModules)
271
+
272
+ if (!needsInstall) {
273
+ try {
274
+ execSync(`node -e "require('better-sqlite3')"`, { cwd: mcpDir, stdio: "pipe" })
275
+ } catch {
276
+ console.log(cyan("Detected incompatible better-sqlite3 build. Reinstalling..."))
277
+ fs.rmSync(mcpNodeModules, { recursive: true, force: true })
278
+ needsInstall = true
279
+ }
280
+ }
281
+
282
+ if (needsInstall) {
283
+ console.log(cyan("Installing mcp_v2 dependencies..."))
284
+ execSync("npm install", { cwd: mcpDir, stdio: "inherit" })
285
+ }
286
+
287
+ execSync(`node ${path.join(mcpDir, "setup.js")}`, { cwd, stdio: "inherit" })
288
+ }
289
+
226
290
  async function promptStateManagement() {
227
291
  const response = await prompts({
228
292
  type: "select",
@@ -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(response => {
9
- return response.json().then(parsedResponse => {
10
- // Response Interceptor - modify response here
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
@@ -10,12 +10,14 @@
10
10
  "ANALYZE_BUNDLE": false,
11
11
  "CLIENT_ENV_VARIABLES": ["API_URL"],
12
12
  "WEBVIEW_CONFIG": {
13
+ "LOCAL_IP": "localhost",
13
14
  "port": "3005",
15
+ "appInfo": "",
14
16
  "android": {
15
- "buildType": "debug"
17
+ "buildType": "debug"
16
18
  },
17
19
  "ios": {
18
- "buildType": "debug"
20
+ "buildType": "debug"
19
21
  }
20
- }
22
+ }
21
23
  }