@codebolt/codeboltjs 1.1.77 → 1.1.79

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/index.d.ts CHANGED
@@ -150,7 +150,7 @@ declare class Codebolt {
150
150
  executeCommandWithStream(command: string, executeInMain?: boolean): EventEmitter<[never]>;
151
151
  };
152
152
  codeutils: {
153
- getJsTree: (filePath?: string | undefined) => void;
153
+ getJsTree: (filePath?: string | undefined) => Promise<unknown>;
154
154
  getAllFilesAsMarkDown: () => Promise<string>;
155
155
  performMatch: (matcherDefinition: object, problemPatterns: any[], problems: any[]) => Promise<import("@codebolt/types").MatchProblemResponse>;
156
156
  getMatcherList: () => Promise<import("@codebolt/types").GetMatcherListTreeResponse>;
@@ -8,7 +8,7 @@ declare const cbcodeutils: {
8
8
  * @param {string} filePath - The path of the file to retrieve the JS tree for.
9
9
  * @returns {Promise<GetJsTreeResponse>} A promise that resolves with the JS tree response.
10
10
  */
11
- getJsTree: (filePath?: string) => void;
11
+ getJsTree: (filePath?: string) => Promise<unknown>;
12
12
  /**
13
13
  * Retrieves all files as Markdown.
14
14
  * @returns {Promise<string>} A promise that resolves with the Markdown content of all files.
@@ -1,9 +1,36 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
5
28
  Object.defineProperty(exports, "__esModule", { value: true });
6
29
  const websocket_1 = __importDefault(require("./websocket"));
30
+ const fs = __importStar(require("fs"));
31
+ const path_1 = __importDefault(require("path"));
32
+ const tree_sitter_1 = __importDefault(require("tree-sitter"));
33
+ const tree_sitter_javascript_1 = __importDefault(require("tree-sitter-javascript"));
7
34
  /**
8
35
  * A utility module for working with code.
9
36
  */
@@ -14,69 +41,74 @@ const cbcodeutils = {
14
41
  * @returns {Promise<GetJsTreeResponse>} A promise that resolves with the JS tree response.
15
42
  */
16
43
  getJsTree: (filePath) => {
17
- // return new Promise( async (resolve, reject) => {
44
+ return new Promise(async (resolve, reject) => {
45
+ websocket_1.default.getWebsocket.send(JSON.stringify({
46
+ "type": "settingEvent",
47
+ "action": "getProjectPath"
48
+ }));
49
+ websocket_1.default.getWebsocket.on('message', (data) => {
50
+ const response = JSON.parse(data);
51
+ if (response.type === "getProjectPathResponse") {
52
+ // resolve(response);
53
+ try {
54
+ let pathInput = response.projectPath;
55
+ let parser = new tree_sitter_1.default();
56
+ // Initialize the parser with the JavaScript language
57
+ parser.setLanguage(tree_sitter_javascript_1.default);
58
+ const trees = [];
59
+ const functionNodes = [];
60
+ const processDirectory = (directory) => {
61
+ console.log("isdir");
62
+ // Read all files in the directory
63
+ const files = fs.readdirSync(directory, { withFileTypes: true });
64
+ files.forEach(file => {
65
+ if (file.isDirectory()) {
66
+ if (file.name !== 'node_modules') { // Ignore node_modules directory
67
+ processDirectory(path_1.default.join(directory, file.name)); // Recursive call for subdirectories
68
+ }
69
+ }
70
+ else if (path_1.default.extname(file.name) === '.js') {
71
+ const code = fs.readFileSync(path_1.default.join(directory, file.name), 'utf-8');
72
+ console.log(code);
73
+ let tree = parser.parse(code);
74
+ tree.rootNode.path = path_1.default.join(directory, file.name); // Set file path for t
75
+ trees.push(tree);
76
+ }
77
+ });
78
+ };
79
+ if (fs.lstatSync(pathInput).isDirectory()) {
80
+ processDirectory(pathInput);
81
+ }
82
+ else if (path_1.default.extname(pathInput) === '.js') {
83
+ // Read a single JavaScript file
84
+ const code = fs.readFileSync(pathInput, 'utf-8');
85
+ let tree = parser.parse(code);
86
+ tree.rootNode.path = pathInput; // Set file path for t
87
+ trees.push(tree);
88
+ }
89
+ resolve({ event: 'GetJsTreeResponse', payload: trees }); // Return an array of abstract syntax trees (ASTs)
90
+ }
91
+ catch (error) {
92
+ console.error('An error occurred:', error);
93
+ return { event: 'GetJsTreeResponse', payload: null }; // Return null in case of error
94
+ }
95
+ }
96
+ });
97
+ });
98
+ // return new Promise(async (resolve, reject) => {
18
99
  // cbws.getWebsocket.send(JSON.stringify({
19
- // "type": "settingEvent",
20
- // "action": "getProjectPath"
100
+ // "type": "codeEvent",
101
+ // "action": "getJsTree",
102
+ // payload: {
103
+ // filePath
104
+ // }
21
105
  // }));
22
106
  // cbws.getWebsocket.on('message', (data: string) => {
23
107
  // const response = JSON.parse(data);
24
- // if (response.type === "getProjectPathResponse") {
25
- // // resolve(response);
26
- // try {
27
- // let pathInput= response.projectPath;
28
- // let parser= new Parser();
29
- // // Initialize the parser with the JavaScript language
30
- // parser.setLanguage(JavaScript);
31
- // const trees = [];
32
- // const functionNodes = [];
33
- // const processDirectory = (directory:any) => {
34
- // console.log("isdir")
35
- // // Read all files in the directory
36
- // const files = fs.readdirSync(directory, { withFileTypes: true });
37
- // files.forEach(file => {
38
- // if (file.isDirectory()) {
39
- // if (file.name !== 'node_modules') { // Ignore node_modules directory
40
- // processDirectory(path.join(directory, file.name)); // Recursive call for subdirectories
41
- // }
42
- // } else if (path.extname(file.name) === '.js') {
43
- // const code = fs.readFileSync(path.join(directory, file.name), 'utf-8');
44
- // console.log(code);
45
- // let tree:any = parser.parse(code);
46
- // tree.rootNode.path = path.join(directory, file.name); // Set file path for t
47
- // trees.push(tree);
48
- // }
49
- // });
50
- // };
51
- // if (fs.lstatSync(pathInput).isDirectory()) {
52
- // processDirectory(pathInput);
53
- // } else if (path.extname(pathInput) === '.js') {
54
- // // Read a single JavaScript file
55
- // const code = fs.readFileSync(pathInput, 'utf-8');
56
- // let tree:any = parser.parse(code);
57
- // tree.rootNode.path = pathInput; // Set file path for t
58
- // trees.push(tree);
59
- // }
60
- // resolve({ event: 'GetJsTreeResponse',payload:trees}); // Return an array of abstract syntax trees (ASTs)
61
- // } catch (error) {
62
- // console.error('An error occurred:', error);
63
- // return { event: 'GetJsTreeResponse',payload:null}; // Return null in case of error
64
- // }
108
+ // if (response.type === "getJsTreeResponse") {
109
+ // resolve(response); // Resolve the Promise with the response data
65
110
  // }
66
111
  // });
67
- // // cbws.getWebsocket.send(JSON.stringify({
68
- // // "type": "codeEvent",
69
- // // "action":"getJsTree",
70
- // // payload:{
71
- // // filePath
72
- // // }
73
- // // }));
74
- // // cbws.getWebsocket.on('message', (data: string) => {
75
- // // const response = JSON.parse(data);
76
- // // if (response.type === "getJsTreeResponse") {
77
- // // resolve(response); // Resolve the Promise with the response data
78
- // // }
79
- // // });
80
112
  // });
81
113
  },
82
114
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codebolt/codeboltjs",
3
- "version": "1.1.77",
3
+ "version": "1.1.79",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "author": "",
@@ -20,6 +20,8 @@
20
20
  "dependencies": {
21
21
  "@codebolt/types": "^1.0.10",
22
22
  "js-yaml": "^4.1.0",
23
+ "tree-sitter": "^0.21.1",
24
+ "tree-sitter-javascript": "^0.23.1",
23
25
  "typedoc-plugin-missing-exports": "^2.2.0",
24
26
  "ws": "^8.17.0"
25
27
  },
@@ -40,4 +42,4 @@
40
42
  "jest": {
41
43
  "testTimeout": 50000
42
44
  }
43
- }
45
+ }
@@ -1,8 +1,8 @@
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
6
 
7
7
  import { GetJsTreeResponse, MatchProblemResponse, GetMatcherListTreeResponse, getMatchDetail } from '@codebolt/types';
8
8
 
@@ -10,82 +10,85 @@ import { GetJsTreeResponse, MatchProblemResponse, GetMatcherListTreeResponse, ge
10
10
  * A utility module for working with code.
11
11
  */
12
12
  const cbcodeutils = {
13
-
13
+
14
14
  /**
15
15
  * Retrieves a JavaScript tree structure for a given file path.
16
16
  * @param {string} filePath - The path of the file to retrieve the JS tree for.
17
17
  * @returns {Promise<GetJsTreeResponse>} A promise that resolves with the JS tree response.
18
18
  */
19
19
  getJsTree: (filePath?: string) => {
20
- // return new Promise( async (resolve, reject) => {
21
- // cbws.getWebsocket.send(JSON.stringify({
22
- // "type": "settingEvent",
23
- // "action": "getProjectPath"
24
- // }));
25
- // cbws.getWebsocket.on('message', (data: string) => {
26
- // const response = JSON.parse(data);
27
- // if (response.type === "getProjectPathResponse") {
28
- // // resolve(response);
29
- // try {
30
- // let pathInput= response.projectPath;
31
- // let parser= new Parser();
32
- // // Initialize the parser with the JavaScript language
33
- // parser.setLanguage(JavaScript);
34
- // const trees = [];
35
- // const functionNodes = [];
20
+ return new Promise( async (resolve, reject) => {
21
+ cbws.getWebsocket.send(JSON.stringify({
22
+ "type": "settingEvent",
23
+ "action": "getProjectPath"
24
+ }));
25
+ cbws.getWebsocket.on('message', (data: string) => {
26
+ const response = JSON.parse(data);
27
+ if (response.type === "getProjectPathResponse") {
28
+ // resolve(response);
29
+ try {
30
+ let pathInput= response.projectPath;
31
+ let parser= new Parser();
32
+ // Initialize the parser with the JavaScript language
33
+ parser.setLanguage(JavaScript);
34
+ const trees = [];
35
+ const functionNodes = [];
36
36
 
37
- // const processDirectory = (directory:any) => {
38
- // console.log("isdir")
39
- // // Read all files in the directory
40
- // const files = fs.readdirSync(directory, { withFileTypes: true });
37
+ const processDirectory = (directory:any) => {
38
+ console.log("isdir")
39
+ // Read all files in the directory
40
+ const files = fs.readdirSync(directory, { withFileTypes: true });
41
41
 
42
- // files.forEach(file => {
43
- // if (file.isDirectory()) {
44
- // if (file.name !== 'node_modules') { // Ignore node_modules directory
45
- // processDirectory(path.join(directory, file.name)); // Recursive call for subdirectories
46
- // }
47
- // } else if (path.extname(file.name) === '.js') {
48
- // const code = fs.readFileSync(path.join(directory, file.name), 'utf-8');
49
- // console.log(code);
50
- // let tree:any = parser.parse(code);
51
- // tree.rootNode.path = path.join(directory, file.name); // Set file path for t
52
- // trees.push(tree);
53
- // }
54
- // });
55
- // };
42
+ files.forEach(file => {
43
+ if (file.isDirectory()) {
44
+ if (file.name !== 'node_modules') { // Ignore node_modules directory
45
+ processDirectory(path.join(directory, file.name)); // Recursive call for subdirectories
46
+ }
47
+ } else if (path.extname(file.name) === '.js') {
48
+ const code = fs.readFileSync(path.join(directory, file.name), 'utf-8');
49
+ console.log(code);
50
+ let tree:any = parser.parse(code);
51
+ tree.rootNode.path = path.join(directory, file.name); // Set file path for t
52
+ trees.push(tree);
53
+ }
54
+ });
55
+ };
56
56
 
57
- // if (fs.lstatSync(pathInput).isDirectory()) {
58
- // processDirectory(pathInput);
59
- // } else if (path.extname(pathInput) === '.js') {
60
- // // Read a single JavaScript file
61
- // const code = fs.readFileSync(pathInput, 'utf-8');
62
- // let tree:any = parser.parse(code);
63
- // tree.rootNode.path = pathInput; // Set file path for t
57
+ if (fs.lstatSync(pathInput).isDirectory()) {
58
+ processDirectory(pathInput);
59
+ } else if (path.extname(pathInput) === '.js') {
60
+ // Read a single JavaScript file
61
+ const code = fs.readFileSync(pathInput, 'utf-8');
62
+ let tree:any = parser.parse(code);
63
+ tree.rootNode.path = pathInput; // Set file path for t
64
64
 
65
- // trees.push(tree);
66
- // }
65
+ trees.push(tree);
66
+ }
67
67
 
68
- // resolve({ event: 'GetJsTreeResponse',payload:trees}); // Return an array of abstract syntax trees (ASTs)
69
- // } catch (error) {
70
- // console.error('An error occurred:', error);
71
- // return { event: 'GetJsTreeResponse',payload:null}; // Return null in case of error
72
- // }
68
+ resolve({ event: 'GetJsTreeResponse',payload:trees}); // Return an array of abstract syntax trees (ASTs)
69
+ } catch (error) {
70
+ console.error('An error occurred:', error);
71
+ return { event: 'GetJsTreeResponse',payload:null}; // Return null in case of error
72
+ }
73
+ }
74
+ });
75
+
76
+
77
+ });
78
+ // return new Promise(async (resolve, reject) => {
79
+ // cbws.getWebsocket.send(JSON.stringify({
80
+ // "type": "codeEvent",
81
+ // "action": "getJsTree",
82
+ // payload: {
83
+ // filePath
84
+ // }
85
+ // }));
86
+ // cbws.getWebsocket.on('message', (data: string) => {
87
+ // const response = JSON.parse(data);
88
+ // if (response.type === "getJsTreeResponse") {
89
+ // resolve(response); // Resolve the Promise with the response data
73
90
  // }
74
91
  // });
75
-
76
- // // cbws.getWebsocket.send(JSON.stringify({
77
- // // "type": "codeEvent",
78
- // // "action":"getJsTree",
79
- // // payload:{
80
- // // filePath
81
- // // }
82
- // // }));
83
- // // cbws.getWebsocket.on('message', (data: string) => {
84
- // // const response = JSON.parse(data);
85
- // // if (response.type === "getJsTreeResponse") {
86
- // // resolve(response); // Resolve the Promise with the response data
87
- // // }
88
- // // });
89
92
  // });
90
93
  },
91
94
 
@@ -97,13 +100,13 @@ const cbcodeutils = {
97
100
  return new Promise((resolve, reject) => {
98
101
  cbws.getWebsocket.send(JSON.stringify({
99
102
  "type": "codeEvent",
100
- "action":"getAllFilesMarkdown"
103
+ "action": "getAllFilesMarkdown"
101
104
  }));
102
105
  cbws.getWebsocket.on('message', (data: string) => {
103
106
  const response = JSON.parse(data);
104
107
  if (response.type === "getAllFilesMarkdownResponse") {
105
108
  resolve(response); // Resolve the Promise with the response data
106
- }
109
+ }
107
110
  });
108
111
  });
109
112
  },
@@ -119,8 +122,8 @@ const cbcodeutils = {
119
122
  return new Promise((resolve, reject) => {
120
123
  cbws.getWebsocket.send(JSON.stringify({
121
124
  "type": "codeEvent",
122
- "action":"performMatch",
123
- payload:{
125
+ "action": "performMatch",
126
+ payload: {
124
127
  matcherDefinition,
125
128
  problemPatterns,
126
129
  }
@@ -129,9 +132,9 @@ const cbcodeutils = {
129
132
  const response = JSON.parse(data);
130
133
  if (response.type === "getgetJsTreeResponse") {
131
134
  resolve(response); // Resolve the Promise with the response data
132
- }
135
+ }
133
136
  });
134
- });
137
+ });
135
138
  },
136
139
 
137
140
  /**
@@ -142,15 +145,15 @@ const cbcodeutils = {
142
145
  return new Promise((resolve, reject) => {
143
146
  cbws.getWebsocket.send(JSON.stringify({
144
147
  "type": "codeEvent",
145
- "action":"getMatcherList",
148
+ "action": "getMatcherList",
146
149
  }));
147
150
  cbws.getWebsocket.on('message', (data: string) => {
148
151
  const response = JSON.parse(data);
149
152
  if (response.type === "getMatcherListTreeResponse") {
150
153
  resolve(response); // Resolve the Promise with the response data
151
- }
154
+ }
152
155
  });
153
- });
156
+ });
154
157
  },
155
158
 
156
159
  /**
@@ -162,18 +165,18 @@ const cbcodeutils = {
162
165
  return new Promise((resolve, reject) => {
163
166
  cbws.getWebsocket.send(JSON.stringify({
164
167
  "type": "codeEvent",
165
- "action":"getMatchDetail",
166
- payload:{
167
- match:matcher
168
+ "action": "getMatchDetail",
169
+ payload: {
170
+ match: matcher
168
171
  }
169
172
  }));
170
173
  cbws.getWebsocket.on('message', (data: string) => {
171
174
  const response = JSON.parse(data);
172
175
  if (response.type === "matchDetailTreeResponse") {
173
176
  resolve(response); // Resolve the Promise with the response data
174
- }
177
+ }
175
178
  });
176
- });
179
+ });
177
180
  }
178
181
 
179
182
  };