@codebolt/codeboltjs 1.1.79 → 1.1.81

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.
@@ -51,14 +51,13 @@ const cbcodeutils = {
51
51
  if (response.type === "getProjectPathResponse") {
52
52
  // resolve(response);
53
53
  try {
54
- let pathInput = response.projectPath;
54
+ let pathInput = filePath || response.projectPath;
55
55
  let parser = new tree_sitter_1.default();
56
56
  // Initialize the parser with the JavaScript language
57
57
  parser.setLanguage(tree_sitter_javascript_1.default);
58
58
  const trees = [];
59
59
  const functionNodes = [];
60
60
  const processDirectory = (directory) => {
61
- console.log("isdir");
62
61
  // Read all files in the directory
63
62
  const files = fs.readdirSync(directory, { withFileTypes: true });
64
63
  files.forEach(file => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codebolt/codeboltjs",
3
- "version": "1.1.79",
3
+ "version": "1.1.81",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "author": "",
@@ -22,6 +22,7 @@
22
22
  "js-yaml": "^4.1.0",
23
23
  "tree-sitter": "^0.21.1",
24
24
  "tree-sitter-javascript": "^0.23.1",
25
+ "tree-sitter-typescript": "^0.23.2",
25
26
  "typedoc-plugin-missing-exports": "^2.2.0",
26
27
  "ws": "^8.17.0"
27
28
  },
@@ -1,8 +1,9 @@
1
1
  import cbws from './websocket';
2
2
  import * as fs from 'fs';
3
3
  import path from 'path';
4
- import Parser from 'tree-sitter';
5
- import JavaScript from 'tree-sitter-javascript';
4
+ import Parser from 'tree-sitter';
5
+ import JavaScript from 'tree-sitter-javascript';
6
+ import typescript from "tree-sitter-typescript"; // TypeScript and TSX grammar
6
7
 
7
8
  import { GetJsTreeResponse, MatchProblemResponse, GetMatcherListTreeResponse, getMatchDetail } from '@codebolt/types';
8
9
 
@@ -17,7 +18,7 @@ const cbcodeutils = {
17
18
  * @returns {Promise<GetJsTreeResponse>} A promise that resolves with the JS tree response.
18
19
  */
19
20
  getJsTree: (filePath?: string) => {
20
- return new Promise( async (resolve, reject) => {
21
+ return new Promise(async (resolve, reject) => {
21
22
  cbws.getWebsocket.send(JSON.stringify({
22
23
  "type": "settingEvent",
23
24
  "action": "getProjectPath"
@@ -27,18 +28,16 @@ const cbcodeutils = {
27
28
  if (response.type === "getProjectPathResponse") {
28
29
  // resolve(response);
29
30
  try {
30
- let pathInput= response.projectPath;
31
- let parser= new Parser();
31
+ let pathInput = filePath || response.projectPath;
32
+ let parser = new Parser();
32
33
  // Initialize the parser with the JavaScript language
33
34
  parser.setLanguage(JavaScript);
34
35
  const trees = [];
35
36
  const functionNodes = [];
36
-
37
- const processDirectory = (directory:any) => {
38
- console.log("isdir")
37
+ const processDirectory = (directory: any) => {
39
38
  // Read all files in the directory
40
39
  const files = fs.readdirSync(directory, { withFileTypes: true });
41
-
40
+
42
41
  files.forEach(file => {
43
42
  if (file.isDirectory()) {
44
43
  if (file.name !== 'node_modules') { // Ignore node_modules directory
@@ -47,33 +46,33 @@ const cbcodeutils = {
47
46
  } else if (path.extname(file.name) === '.js') {
48
47
  const code = fs.readFileSync(path.join(directory, file.name), 'utf-8');
49
48
  console.log(code);
50
- let tree:any = parser.parse(code);
49
+ let tree: any = parser.parse(code);
51
50
  tree.rootNode.path = path.join(directory, file.name); // Set file path for t
52
51
  trees.push(tree);
53
52
  }
54
53
  });
55
54
  };
56
-
55
+
57
56
  if (fs.lstatSync(pathInput).isDirectory()) {
58
57
  processDirectory(pathInput);
59
58
  } else if (path.extname(pathInput) === '.js') {
60
59
  // Read a single JavaScript file
61
60
  const code = fs.readFileSync(pathInput, 'utf-8');
62
- let tree:any = parser.parse(code);
61
+ let tree: any = parser.parse(code);
63
62
  tree.rootNode.path = pathInput; // Set file path for t
64
-
63
+
65
64
  trees.push(tree);
66
65
  }
67
-
68
- resolve({ event: 'GetJsTreeResponse',payload:trees}); // Return an array of abstract syntax trees (ASTs)
66
+
67
+ resolve({ event: 'GetJsTreeResponse', payload: trees }); // Return an array of abstract syntax trees (ASTs)
69
68
  } catch (error) {
70
69
  console.error('An error occurred:', error);
71
- return { event: 'GetJsTreeResponse',payload:null}; // Return null in case of error
70
+ return { event: 'GetJsTreeResponse', payload: null }; // Return null in case of error
72
71
  }
73
72
  }
74
73
  });
75
74
 
76
-
75
+
77
76
  });
78
77
  // return new Promise(async (resolve, reject) => {
79
78
  // cbws.getWebsocket.send(JSON.stringify({