Skip to content

Commit ad28cff

Browse files
updated fs
1 parent f37321b commit ad28cff

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@codebolt/codeboltjs",
3-
"version": "1.1.66",
3+
"version": "1.1.67",
44
"description": "",
55
"keywords": [],
66
"author": "",

src/modules/fs.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,12 @@ const cbfs = {
6464
* @param {string} filePath - The path of the file to read.
6565
* @returns {Promise<ReadFileResponse>} A promise that resolves with the server response.
6666
*/
67-
readFile: (filename: string, filePath: string): Promise<ReadFileResponse> => {
67+
readFile: (filePath: string): Promise<ReadFileResponse> => {
6868
return new Promise((resolve, reject) => {
6969
cbws.getWebsocket.send(JSON.stringify({
7070
"type":"fsEvent",
7171
"action": "readFile",
7272
"message": {
73-
filename,
7473
filePath
7574
},
7675
}));
@@ -233,6 +232,31 @@ const cbfs = {
233232
});
234233
});
235234
},
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+
},
236260

237261
};
238262

0 commit comments

Comments
 (0)