@codebolt/codeboltjs 1.1.66 → 1.1.67

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>;
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codebolt/codeboltjs",
3
- "version": "1.1.66",
3
+ "version": "1.1.67",
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