Skip to content

Commit 721995e

Browse files
terminal changes 3
1 parent 65aa16c commit 721995e

File tree

3 files changed

+43
-10
lines changed

3 files changed

+43
-10
lines changed

client/src/Components/DasboardComponents/IDE.jsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,5 +326,3 @@ const IDE = () => {
326326
};
327327

328328
export default IDE;
329-
330-

client/src/Context/FileTreeContext.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React, { createContext, useContext, useState } from 'react';
2+
3+
const FileTreeContext = createContext();
4+
5+
export const useFileTree = () => useContext(FileTreeContext);
6+
7+
export const FileTreeProvider = ({ children }) => {
8+
const [fileTreeKey, setFileTreeKey] = useState(0); // Initial key
9+
10+
const updateFileTree = () => {
11+
setFileTreeKey(prevKey => prevKey + 1); // Increment key to force rerender
12+
};
13+
14+
return (
15+
<FileTreeContext.Provider value={{ fileTreeKey, updateFileTree }}>
16+
{children}
17+
</FileTreeContext.Provider>
18+
);
19+
};
20+
21+

server/services/CommandExecutor.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
const shell = require('shelljs');
2+
const fs = require('fs-extra');
3+
const path = require('path');
24

35
const runCommand = (cmd) => {
4-
return new Promise((resolve, reject) => {
5-
shell.exec(cmd, (code, stdout, stderr) => {
6-
if (code !== 0) {
7-
reject(new Error(stderr));
8-
} else {
9-
resolve(stdout);
6+
return new Promise(async (resolve, reject) => {
7+
const touchMatch = cmd.match(/^touch\s+(.*)$/);
8+
9+
if (touchMatch) {
10+
const filePath = touchMatch[1];
11+
12+
try {
13+
await fs.outputFile(filePath, path.basename(filePath));
14+
resolve(`File ${filePath} created and written to successfully.`);
15+
} catch (error) {
16+
reject(new Error(`Error writing to file: ${error.message}`));
1017
}
11-
});
18+
} else {
19+
shell.exec(cmd, (code, stdout, stderr) => {
20+
if (code !== 0) {
21+
reject(new Error(stderr));
22+
} else {
23+
resolve(stdout);
24+
}
25+
});
26+
}
1227
});
1328
};
1429

15-
1630
module.exports = runCommand;

0 commit comments

Comments
 (0)