@codebolt/codeboltjs 1.1.66 → 1.1.68

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
@@ -21,7 +21,7 @@ declare class Codebolt {
21
21
  fs: {
22
22
  createFile: (fileName: string, source: string, filePath: string) => Promise<import("@codebolt/types").CreateFileResponse>;
23
23
  createFolder: (folderName: string, folderPath: string) => Promise<import("@codebolt/types").CreateFolderResponse>;
24
- readFile: (filename: string, filePath: string) => Promise<import("@codebolt/types").ReadFileResponse>;
24
+ readFile: (filePath: string) => Promise<import("@codebolt/types").ReadFileResponse>;
25
25
  updateFile: (filename: string, filePath: string, newContent: string) => Promise<import("@codebolt/types").UpdateFileResponse>;
26
26
  deleteFile: (filename: string, filePath: string) => Promise<import("@codebolt/types").DeleteFileResponse>;
27
27
  deleteFolder: (foldername: string, folderpath: string) => Promise<import("@codebolt/types").DeleteFolderResponse>;
@@ -34,6 +34,7 @@ declare class Codebolt {
34
34
  success: boolean;
35
35
  result: any;
36
36
  }>;
37
+ writeToFile: (relPath: string, newContent: string) => Promise<unknown>;
37
38
  };
38
39
  git: {
39
40
  init: (path: string) => Promise<any>;
@@ -138,7 +139,7 @@ declare class Codebolt {
138
139
  prependOnceListener<K_11>(eventName: string | symbol, listener: (...args: any[]) => void): any;
139
140
  eventNames(): (string | symbol)[];
140
141
  };
141
- executeCommand: (command: string, executeInMain?: boolean) => Promise<import("@codebolt/types").CommandOutput | import("@codebolt/types").CommandError>;
142
+ executeCommand: (command: string, returnEmptyStringOnSuccess?: boolean) => Promise<unknown>;
142
143
  executeCommandRunUntilError: (command: string, executeInMain?: boolean) => Promise<import("@codebolt/types").CommandError>;
143
144
  sendManualInterrupt(): Promise<import("@codebolt/types").TerminalInterruptResponse>;
144
145
  executeCommandWithStream(command: string, executeInMain?: boolean): EventEmitter<[never]>;
package/modules/fs.d.ts CHANGED
@@ -28,7 +28,7 @@ declare const cbfs: {
28
28
  * @param {string} filePath - The path of the file to read.
29
29
  * @returns {Promise<ReadFileResponse>} A promise that resolves with the server response.
30
30
  */
31
- readFile: (filename: string, filePath: string) => Promise<ReadFileResponse>;
31
+ readFile: (filePath: string) => Promise<ReadFileResponse>;
32
32
  /**
33
33
  * @function updateFile
34
34
  * @description Updates the content of a file.
@@ -82,5 +82,13 @@ declare const cbfs: {
82
82
  success: boolean;
83
83
  result: any;
84
84
  }>;
85
+ /**
86
+ * @function writeToFile
87
+ * @description Writes content to a file.
88
+ * @param {string} relPath - The relative path of the file to write to.
89
+ * @param {string} newContent - The new content to write into the file.
90
+ * @returns {Promise<{success: boolean, result: any}>} A promise that resolves with the write operation result.
91
+ */
92
+ writeToFile: (relPath: string, newContent: string) => Promise<unknown>;
85
93
  };
86
94
  export default cbfs;
package/modules/fs.js CHANGED
@@ -68,13 +68,12 @@ const cbfs = {
68
68
  * @param {string} filePath - The path of the file to read.
69
69
  * @returns {Promise<ReadFileResponse>} A promise that resolves with the server response.
70
70
  */
71
- readFile: (filename, filePath) => {
71
+ readFile: (filePath) => {
72
72
  return new Promise((resolve, reject) => {
73
73
  websocket_1.default.getWebsocket.send(JSON.stringify({
74
74
  "type": "fsEvent",
75
75
  "action": "readFile",
76
76
  "message": {
77
- filename,
78
77
  filePath
79
78
  },
80
79
  }));
@@ -236,5 +235,30 @@ const cbfs = {
236
235
  });
237
236
  });
238
237
  },
238
+ /**
239
+ * @function writeToFile
240
+ * @description Writes content to a file.
241
+ * @param {string} relPath - The relative path of the file to write to.
242
+ * @param {string} newContent - The new content to write into the file.
243
+ * @returns {Promise<{success: boolean, result: any}>} A promise that resolves with the write operation result.
244
+ */
245
+ writeToFile: (relPath, newContent) => {
246
+ return new Promise((resolve, reject) => {
247
+ websocket_1.default.getWebsocket.send(JSON.stringify({
248
+ "type": "fsEvent",
249
+ "action": "writeToFile",
250
+ "message": {
251
+ relPath,
252
+ newContent
253
+ }
254
+ }));
255
+ websocket_1.default.getWebsocket.on('message', (data) => {
256
+ const response = JSON.parse(data);
257
+ if (response.type === "writeToFileResponse") {
258
+ resolve(response);
259
+ }
260
+ });
261
+ });
262
+ },
239
263
  };
240
264
  exports.default = cbfs;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { EventEmitter } from 'events';
3
- import { CommandError, CommandOutput, TerminalInterruptResponse } from '@codebolt/types';
3
+ import { CommandError, TerminalInterruptResponse } from '@codebolt/types';
4
4
  /**
5
5
  * CustomEventEmitter class that extends the Node.js EventEmitter class.
6
6
  */
@@ -19,7 +19,7 @@ declare const cbterminal: {
19
19
  * @param {string} command - The command to be executed.
20
20
  * @returns {Promise<CommandOutput|CommandError>} A promise that resolves with the command's output, error, or finish signal.
21
21
  */
22
- executeCommand: (command: string, executeInMain?: boolean) => Promise<CommandOutput | CommandError>;
22
+ executeCommand: (command: string, returnEmptyStringOnSuccess?: boolean) => Promise<unknown>;
23
23
  /**
24
24
  * Executes a given command and keeps running until an error occurs.
25
25
  * Listens for messages from the WebSocket and resolves the promise when an error is encountered.
@@ -23,31 +23,18 @@ const cbterminal = {
23
23
  * @param {string} command - The command to be executed.
24
24
  * @returns {Promise<CommandOutput|CommandError>} A promise that resolves with the command's output, error, or finish signal.
25
25
  */
26
- executeCommand: async (command, executeInMain = false) => {
26
+ executeCommand: async (command, returnEmptyStringOnSuccess = false) => {
27
27
  return new Promise((resolve, reject) => {
28
28
  websocket_1.default.getWebsocket.send(JSON.stringify({
29
29
  "type": "executeCommand",
30
30
  "message": command,
31
- executeInMain
31
+ returnEmptyStringOnSuccess
32
32
  }));
33
33
  let result = "";
34
34
  websocket_1.default.getWebsocket.on('message', (data) => {
35
35
  const response = JSON.parse(data);
36
- if (response.type === "commandOutput" || response.type === "commandError" || response.type === "commandFinish") {
37
- if (response.type === "commandOutput") {
38
- // Initialize result as an empty string
39
- result += response.stdout + "/n"; // Append the output
40
- }
41
- else if (response.type === "commandError") {
42
- result = response.stderr + "/n";
43
- ; // Set result to the error
44
- response.result = result;
45
- resolve(response); // Resolve with the result string
46
- }
47
- else if (response.type === "commandFinish") {
48
- response.result = result;
49
- resolve(response); // Resolve with the result string
50
- }
36
+ if (response.type === "commandError" || response.type === "commandFinish") {
37
+ resolve(response);
51
38
  }
52
39
  });
53
40
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codebolt/codeboltjs",
3
- "version": "1.1.66",
3
+ "version": "1.1.68",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "author": "",
package/src/modules/fs.ts CHANGED
@@ -64,13 +64,12 @@ const cbfs = {
64
64
  * @param {string} filePath - The path of the file to read.
65
65
  * @returns {Promise<ReadFileResponse>} A promise that resolves with the server response.
66
66
  */
67
- readFile: (filename: string, filePath: string): Promise<ReadFileResponse> => {
67
+ readFile: (filePath: string): Promise<ReadFileResponse> => {
68
68
  return new Promise((resolve, reject) => {
69
69
  cbws.getWebsocket.send(JSON.stringify({
70
70
  "type":"fsEvent",
71
71
  "action": "readFile",
72
72
  "message": {
73
- filename,
74
73
  filePath
75
74
  },
76
75
  }));
@@ -233,6 +232,31 @@ const cbfs = {
233
232
  });
234
233
  });
235
234
  },
235
+ /**
236
+ * @function writeToFile
237
+ * @description Writes content to a file.
238
+ * @param {string} relPath - The relative path of the file to write to.
239
+ * @param {string} newContent - The new content to write into the file.
240
+ * @returns {Promise<{success: boolean, result: any}>} A promise that resolves with the write operation result.
241
+ */
242
+ writeToFile: (relPath:string, newContent:string) => {
243
+ return new Promise((resolve, reject) => {
244
+ cbws.getWebsocket.send(JSON.stringify({
245
+ "type": "fsEvent",
246
+ "action": "writeToFile",
247
+ "message": {
248
+ relPath,
249
+ newContent
250
+ }
251
+ }));
252
+ cbws.getWebsocket.on('message', (data:string) => {
253
+ const response = JSON.parse(data);
254
+ if (response.type === "writeToFileResponse") {
255
+ resolve(response);
256
+ }
257
+ });
258
+ });
259
+ },
236
260
 
237
261
  };
238
262
 
@@ -19,29 +19,18 @@ const cbterminal = {
19
19
  * @param {string} command - The command to be executed.
20
20
  * @returns {Promise<CommandOutput|CommandError>} A promise that resolves with the command's output, error, or finish signal.
21
21
  */
22
- executeCommand: async (command: string,executeInMain=false): Promise<CommandOutput|CommandError> => {
22
+ executeCommand: async (command:string, returnEmptyStringOnSuccess:boolean = false) => {
23
23
  return new Promise((resolve, reject) => {
24
24
  cbws.getWebsocket.send(JSON.stringify({
25
25
  "type": "executeCommand",
26
26
  "message": command,
27
- executeInMain
27
+ returnEmptyStringOnSuccess
28
28
  }));
29
29
  let result = "";
30
- cbws.getWebsocket.on('message', (data: string) => {
30
+ cbws.getWebsocket.on('message', (data:string) => {
31
31
  const response = JSON.parse(data);
32
-
33
- if (response.type === "commandOutput" || response.type === "commandError" || response.type === "commandFinish") {
34
- if (response.type === "commandOutput") {
35
- // Initialize result as an empty string
36
- result += response.stdout + "/n"; // Append the output
37
- } else if (response.type === "commandError") {
38
- result = response.stderr + "/n";; // Set result to the error
39
- response.result = result;
40
- resolve(response); // Resolve with the result string
41
- } else if (response.type === "commandFinish") {
42
- response.result = result;
43
- resolve(response); // Resolve with the result string
44
- }
32
+ if (response.type === "commandError" || response.type === "commandFinish" ) {
33
+ resolve(response)
45
34
  }
46
35
  });
47
36
  });