Skip to content

Commit 7cf96da

Browse files
commit, rollback api basic done
1 parent f09a10c commit 7cf96da

File tree

13 files changed

+1081
-365
lines changed

13 files changed

+1081
-365
lines changed

Frontend/src/App/CodeEditor/MonacoEditor/MonacoEditor.tsx

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -193,97 +193,6 @@ export default function MonacoEditor({
193193
return initialValue;
194194
};
195195

196-
// Add this to your MonacoEditor.tsx, updating your existing useEffect
197-
198-
useEffect(() => {
199-
if (editorRef.current) {
200-
// Configure TypeScript compiler options with more advanced settings
201-
monaco.languages.typescript.javascriptDefaults.setCompilerOptions({
202-
target: monaco.languages.typescript.ScriptTarget.Latest,
203-
allowNonTsExtensions: true,
204-
moduleResolution:
205-
monaco.languages.typescript.ModuleResolutionKind.NodeJs,
206-
module: monaco.languages.typescript.ModuleKind.ESNext,
207-
noEmit: true,
208-
typeRoots: ["node_modules/@types"],
209-
jsx: monaco.languages.typescript.JsxEmit.React,
210-
allowJs: true,
211-
checkJs: true, // Enable JavaScript validation
212-
strict: true,
213-
esModuleInterop: true,
214-
allowSyntheticDefaultImports: true,
215-
resolveJsonModule: true,
216-
noImplicitAny: false, // More permissive for quick editing
217-
});
218-
219-
// Set diagnostic options to show errors for imports
220-
monaco.languages.typescript.javascriptDefaults.setDiagnosticsOptions({
221-
noSemanticValidation: false,
222-
noSyntaxValidation: false,
223-
noSuggestionDiagnostics: false,
224-
diagnosticCodesToIgnore: [],
225-
});
226-
227-
// Add basic browser and DOM typings
228-
monaco.languages.typescript.javascriptDefaults.addExtraLib(
229-
`
230-
// Basic DOM and browser APIs
231-
interface Window {
232-
document: Document;
233-
console: Console;
234-
localStorage: Storage;
235-
sessionStorage: Storage;
236-
setTimeout(callback: Function, ms: number): number;
237-
clearTimeout(id: number): void;
238-
setInterval(callback: Function, ms: number): number;
239-
clearInterval(id: number): void;
240-
}
241-
declare var window: Window;
242-
declare var document: Document;
243-
declare var console: Console;
244-
245-
// Common modules
246-
declare module "react" {
247-
export const useState: any;
248-
export const useEffect: any;
249-
export const useRef: any;
250-
export const useCallback: any;
251-
export const useMemo: any;
252-
export const useContext: any;
253-
export default any;
254-
}
255-
declare module "react-dom" {
256-
export const createRoot: any;
257-
export default any;
258-
}
259-
`,
260-
"ts:filename/lib.d.ts"
261-
);
262-
263-
// Register a mock file system for handling imports
264-
const fileMap = {
265-
"/src/utils.js": `
266-
export const add = (a, b) => a + b;
267-
export const subtract = (a, b) => a - b;
268-
export default { add, subtract };
269-
`,
270-
"/src/constants.js": `
271-
export const PI = 3.14159;
272-
export const MAX_VALUE = 1000;
273-
export default { PI, MAX_VALUE };
274-
`,
275-
};
276-
277-
// Register each mock file
278-
Object.entries(fileMap).forEach(([filePath, content]) => {
279-
monaco.languages.typescript.javascriptDefaults.addExtraLib(
280-
content,
281-
`file:${filePath}`
282-
);
283-
});
284-
}
285-
}, [editorRef.current]);
286-
287196
return (
288197
<div className="h-full flex flex-col">
289198
<CollaborativeCursor

Version_Engine/package-lock.json

Lines changed: 0 additions & 159 deletions
This file was deleted.

Version_Engine/package.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

Version_Engine/worker-git/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
FROM node:lts-alpine
22

3+
RUN apk add --no-cache git zip unzip
4+
35
WORKDIR /app
46

57
COPY package*.json ./

Version_Engine/worker-git/handlers/commit.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
import fs from "fs/promises";
2-
import path from "path";
31
import { exec } from "child_process";
42
import { promisify } from "util";
3+
import fs from "fs/promises";
54
import {
65
getGitFolderFromStorage,
76
checkGitFolderExists,
87
saveGitFolderToStorage,
98
saveCommitToDatabase,
109
getLatestCommit,
10+
loadSessionFiles,
1111
} from "../utils/database.js";
12+
import os from "os";
1213

1314
const execPromise = promisify(exec);
1415

@@ -22,15 +23,20 @@ const execPromise = promisify(exec);
2223
*/
2324
const handleCommit = async (sessionId, message, branchId) => {
2425
console.log(`Handling commit for session: ${sessionId}`);
26+
const gitRepoPath = os.homedir() + `/repo`;
2527

2628
try {
27-
const gitRepoPath = await getGitFolderFromStorage(sessionId);
29+
await fs.mkdir(gitRepoPath, { recursive: true });
30+
await loadSessionFiles(sessionId, gitRepoPath);
2831

2932
const gitInitialized = await checkGitFolderExists(sessionId);
33+
console.log(`Git initialized for session ${sessionId}: ${gitInitialized}`);
34+
3035
if (!gitInitialized) {
3136
console.log(
3237
`Git not initialized for session ${sessionId}, initializing now...`
3338
);
39+
3440
await execPromise("git init", { cwd: gitRepoPath });
3541
await execPromise(
3642
'git config --local user.email "system@codespace.com"',
@@ -39,6 +45,8 @@ const handleCommit = async (sessionId, message, branchId) => {
3945
await execPromise('git config --local user.name "Codespace System"', {
4046
cwd: gitRepoPath,
4147
});
48+
} else {
49+
await getGitFolderFromStorage(sessionId, gitRepoPath);
4250
}
4351

4452
await execPromise("git add .", { cwd: gitRepoPath });
@@ -54,14 +62,16 @@ const handleCommit = async (sessionId, message, branchId) => {
5462
}
5563
const commitHash = commitHashMatch[2];
5664

65+
await saveGitFolderToStorage(sessionId, gitRepoPath);
66+
5767
const commitRecord = await saveCommitToDatabase(
5868
branchId,
5969
null,
6070
commitHash,
6171
commitMessage
6272
);
6373

64-
await saveGitFolderToStorage(sessionId);
74+
fs.rm(gitRepoPath, { recursive: true, force: true });
6575

6676
return {
6777
success: true,
@@ -70,6 +80,8 @@ const handleCommit = async (sessionId, message, branchId) => {
7080
commitHash: commitHash,
7181
};
7282
} catch (error) {
83+
await fs.rm(gitRepoPath, { recursive: true, force: true });
84+
7385
if (error.message && error.message.includes("nothing to commit")) {
7486
console.log("No changes to commit");
7587
return {

0 commit comments

Comments
 (0)