Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit c36fca7

Browse files
Merge pull request #199 from SwapnilChand/combine-explorer-and-editor
Combine Project Explorer and Editor into a Single Interface (#198)
2 parents 807331e + 956e15f commit c36fca7

15 files changed

Lines changed: 1808 additions & 1006 deletions

File tree

packages/editor/package-lock.json

Lines changed: 341 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/editor/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@
99
"lint": "next lint"
1010
},
1111
"dependencies": {
12+
"@anthropic-ai/sdk": "^0.17.1",
1213
"@dnd-kit/core": "^6.1.0",
1314
"@dnd-kit/sortable": "^8.0.0",
1415
"@dnd-kit/utilities": "^3.2.2",
16+
"@google/generative-ai": "^0.2.1",
1517
"@radix-ui/react-accordion": "^1.2.1",
1618
"@radix-ui/react-checkbox": "^1.1.2",
1719
"@radix-ui/react-collapsible": "^1.1.1",
20+
"@radix-ui/react-context-menu": "^2.2.3",
1821
"@radix-ui/react-dialog": "^1.1.2",
1922
"@radix-ui/react-dropdown-menu": "^2.1.2",
2023
"@radix-ui/react-label": "^2.1.0",
@@ -34,11 +37,10 @@
3437
"next": "15.1.2",
3538
"next-themes": "^0.4.3",
3639
"openai": "^4.73.1",
37-
"@anthropic-ai/sdk": "^0.17.1",
38-
"@google/generative-ai": "^0.2.1",
3940
"react": "^18.3.1",
4041
"react-dom": "^18.2.0",
4142
"react-error-boundary": "^4.1.2",
43+
"react-resizable-panels": "^2.1.7",
4244
"react-syntax-highlighter": "^15.6.1",
4345
"sonner": "^1.7.0",
4446
"tailwind-merge": "^2.5.4",
Lines changed: 62 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,125 @@
1-
import { writeFile, mkdir, rm, unlink, readFile } from 'fs/promises'
2-
import { NextResponse } from 'next/server'
3-
import path from 'path'
1+
import { writeFile, mkdir, rm, unlink, readFile } from "fs/promises";
2+
import { NextResponse } from "next/server";
3+
import path from "path";
44

55
function getBasePath() {
6-
return path.join(process.cwd(), '..', 'compiled')
6+
return path.join(process.cwd(), "..", "compiled");
77
}
88

99
export async function POST(request: Request) {
1010
try {
11-
const { path: filePath, content } = await request.json()
12-
const fullPath = path.join(getBasePath(), filePath)
13-
11+
const { path: filePath, content, isDirectory } = await request.json();
12+
const fullPath = path.join(getBasePath(), filePath);
13+
1414
// Ensure the directory exists
15-
await mkdir(path.dirname(fullPath), { recursive: true })
16-
17-
// Write the file
18-
await writeFile(fullPath, JSON.stringify(content, null, 2))
19-
return NextResponse.json({ success: true })
15+
await mkdir(path.dirname(fullPath), { recursive: true });
16+
17+
if (isDirectory) {
18+
// If it's a directory, just create it
19+
await mkdir(fullPath, { recursive: true });
20+
} else {
21+
// If it's a file, write the content
22+
await writeFile(fullPath, JSON.stringify(content, null, 2));
23+
}
24+
25+
return NextResponse.json({ success: true });
2026
} catch (error) {
21-
console.error('Error creating file:', error)
27+
console.error("Error creating file:", error);
2228
return NextResponse.json(
23-
{ error: 'Failed to create file' },
29+
{ error: "Failed to create file" },
2430
{ status: 500 }
25-
)
31+
);
2632
}
2733
}
2834

2935
export async function DELETE(request: Request) {
3036
try {
31-
const { path: itemPath, type } = await request.json()
32-
const fullPath = path.join(getBasePath(), itemPath)
37+
const { path: itemPath, type } = await request.json();
38+
const fullPath = path.join(getBasePath(), itemPath);
3339

34-
if (type === 'folder') {
35-
await rm(fullPath, { recursive: true, force: true })
40+
if (type === "folder") {
41+
await rm(fullPath, { recursive: true, force: true });
3642
} else {
37-
await unlink(fullPath)
43+
await unlink(fullPath);
3844
}
3945

40-
return NextResponse.json({ success: true })
46+
return NextResponse.json({ success: true });
4147
} catch (error) {
42-
console.error('Error deleting item:', error)
48+
console.error("Error deleting item:", error);
4349
return NextResponse.json(
44-
{ error: 'Failed to delete item' },
50+
{ error: "Failed to delete item" },
4551
{ status: 500 }
46-
)
52+
);
4753
}
4854
}
4955

5056
export async function GET(request: Request) {
5157
try {
52-
const { searchParams } = new URL(request.url)
53-
const filePath = searchParams.get('path')
54-
58+
const { searchParams } = new URL(request.url);
59+
const filePath = searchParams.get("path");
60+
5561
if (!filePath) {
5662
return NextResponse.json(
57-
{ error: 'No file path provided' },
63+
{ error: "No file path provided" },
5864
{ status: 400 }
59-
)
65+
);
6066
}
6167

62-
const fullPath = path.join(getBasePath(), filePath)
63-
const fileContent = await readFile(fullPath, 'utf-8')
64-
const parsedContent = JSON.parse(fileContent)
65-
66-
return NextResponse.json(parsedContent)
68+
const fullPath = path.join(getBasePath(), filePath);
69+
const fileContent = await readFile(fullPath, "utf-8");
70+
const parsedContent = JSON.parse(fileContent);
71+
72+
return NextResponse.json(parsedContent);
6773
} catch (error) {
68-
console.error('Error reading file:', error)
69-
return NextResponse.json(
70-
{ error: 'Failed to read file' },
71-
{ status: 500 }
72-
)
74+
console.error("Error reading file:", error);
75+
return NextResponse.json({ error: "Failed to read file" }, { status: 500 });
7376
}
7477
}
7578

7679
export async function PUT(request: Request) {
7780
try {
78-
const { path: filePath, content } = await request.json()
79-
81+
const { path: filePath, content } = await request.json();
82+
8083
if (!filePath) {
8184
return NextResponse.json(
82-
{ error: 'No file path provided' },
85+
{ error: "No file path provided" },
8386
{ status: 400 }
84-
)
87+
);
8588
}
8689

8790
// Validate content
8891
if (!content) {
8992
return NextResponse.json(
90-
{ error: 'No content provided' },
93+
{ error: "No content provided" },
9194
{ status: 400 }
92-
)
95+
);
9396
}
9497

95-
const fullPath = path.join(getBasePath(), filePath)
96-
98+
const fullPath = path.join(getBasePath(), filePath);
99+
97100
// Check if directory exists, if not create it
98-
await mkdir(path.dirname(fullPath), { recursive: true })
99-
101+
await mkdir(path.dirname(fullPath), { recursive: true });
102+
100103
// Add retry logic
101104
const maxRetries = 3;
102105
for (let i = 0; i < maxRetries; i++) {
103106
try {
104-
const jsonContent = JSON.stringify(content, null, 2)
105-
await writeFile(fullPath, jsonContent, 'utf-8')
106-
return NextResponse.json({ success: true })
107+
const jsonContent = JSON.stringify(content, null, 2);
108+
await writeFile(fullPath, jsonContent, "utf-8");
109+
return NextResponse.json({ success: true });
107110
} catch (writeError) {
108111
if (i === maxRetries - 1) throw writeError;
109-
await new Promise(resolve => setTimeout(resolve, 1000)); // Wait 1s before retry
112+
await new Promise((resolve) => setTimeout(resolve, 1000)); // Wait 1s before retry
110113
}
111114
}
112115
} catch (error) {
113-
console.error('Error writing file:', error)
116+
console.error("Error writing file:", error);
114117
return NextResponse.json(
115-
{
116-
error: 'Failed to write file',
117-
details: error instanceof Error ? error.message : 'Unknown error'
118+
{
119+
error: "Failed to write file",
120+
details: error instanceof Error ? error.message : "Unknown error",
118121
},
119122
{ status: 500 }
120-
)
123+
);
121124
}
122-
}
125+
}

0 commit comments

Comments
 (0)