-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·394 lines (337 loc) · 12.4 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·394 lines (337 loc) · 12.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
#!/bin/bash
set -e
echo "╔══════════════════════════════════════════════════════════════╗"
echo "║ RUNLOOP Setup & Refactor Script ║"
echo "╚══════════════════════════════════════════════════════════════╝"
echo ""
PROJECT_DIR="/Users/hacka/Works/RUNLOOP"
GIT_URL="http://<git-server>/platform/runloop.git"
# ============================================
# Step 1: Clone from Git
# ============================================
echo "📥 Step 1: Cloning from Git..."
if [ -d "$PROJECT_DIR" ]; then
echo " Removing existing directory..."
rm -rf "$PROJECT_DIR"
fi
cd /Users/hacka/Works
git clone "$GIT_URL" RUNLOOP
cd "$PROJECT_DIR"
echo "✓ Cloned successfully"
echo ""
# ============================================
# Step 2: Create apps/ structure
# ============================================
echo "📁 Step 2: Creating apps/ structure..."
mkdir -p apps
mv frontend apps/runloop
mv executor apps/runloop-engine
rm -rf api-server
echo "✓ Structure created"
echo " apps/runloop/ ← Next.js (will be refactored)"
echo " apps/runloop-engine/ ← Go Worker"
echo ""
# ============================================
# Step 3: Backup & Create Next.js
# ============================================
echo "⚛️ Step 3: Refactoring to Next.js..."
cd apps
# Backup old frontend
cp -r runloop runloop-vite-backup
# Remove old node_modules
rm -rf runloop/node_modules runloop/package-lock.json
# Create new Next.js app
npx create-next-app@latest runloop --typescript --tailwind --eslint --app --src-dir --import-alias "@/*" --use-npm --yes
echo "✓ Next.js created"
echo ""
# ============================================
# Step 4: Install dependencies
# ============================================
echo "📦 Step 4: Installing dependencies..."
cd runloop
npm install lucide-react recharts @xyflow/react @prisma/client bcryptjs jsonwebtoken
npm install -D prisma @types/bcryptjs @types/jsonwebtoken
echo "✓ Dependencies installed"
echo ""
# ============================================
# Step 5: Copy important files
# ============================================
echo "📋 Step 5: Copying files..."
# Copy Prisma schema
mkdir -p prisma
if [ -f "../runloop-vite-backup/src/types/index.ts" ]; then
cp -r ../runloop-vite-backup/src/types src/
fi
# Copy context files
mkdir -p src/context
if [ -d "../runloop-vite-backup/src/context" ]; then
cp ../runloop-vite-backup/src/context/*.tsx src/context/
fi
echo "✓ Files copied"
echo ""
# ============================================
# Step 6: Create config files
# ============================================
echo "⚙️ Step 6: Creating config files..."
# next.config.ts
cat > next.config.ts << 'EOF'
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
basePath: "/runloop",
async rewrites() {
return [
{
source: "/api/engine/:path*",
destination: `${process.env.EXECUTOR_URL || "http://localhost:8080"}/runloop-engine/api/:path*`,
},
];
},
async headers() {
return [
{
source: "/:path*",
headers: [
{ key: "Access-Control-Allow-Origin", value: "*" },
{ key: "Access-Control-Allow-Methods", value: "GET,POST,PUT,DELETE,OPTIONS" },
{ key: "Access-Control-Allow-Headers", value: "Content-Type, Authorization" },
],
},
];
},
};
export default nextConfig;
EOF
# .env.local
cat > .env.local << 'EOF'
# Database
DATABASE_URL=postgres://runloop:runloop_secret@localhost:5434/runloop?sslmode=disable
# Auth
JWT_SECRET=dev-secret-key
SKIP_AUTH=true
# App
NEXT_PUBLIC_API_URL=/runloop/api
EXECUTOR_URL=http://localhost:8080
EOF
# .env for Prisma
cat > .env << 'EOF'
DATABASE_URL=postgres://runloop:runloop_secret@localhost:5434/runloop?sslmode=disable
EOF
echo "✓ Config files created"
echo ""
# ============================================
# Step 7: Create directory structure
# ============================================
echo "📂 Step 7: Creating directory structure..."
mkdir -p src/app/login
mkdir -p src/app/dashboard
mkdir -p src/app/projects
mkdir -p "src/app/projects/[id]"
mkdir -p "src/app/projects/[id]/schedulers/new"
mkdir -p "src/app/projects/[id]/schedulers/new/flow"
mkdir -p src/app/schedulers
mkdir -p "src/app/schedulers/[id]"
mkdir -p src/app/executions
mkdir -p "src/app/executions/[id]"
mkdir -p "src/app/api/[[...path]]"
mkdir -p src/components
mkdir -p src/lib
echo "✓ Directories created"
echo ""
# ============================================
# Step 8: Create basic files
# ============================================
echo "📝 Step 8: Creating basic files..."
# globals.css
cat > src/app/globals.css << 'EOF'
@tailwind base;
@tailwind components;
@tailwind utilities;
:root {
--bg-primary: #0a0a0b;
--bg-secondary: #121214;
--bg-tertiary: #1a1a1c;
--ocean-blue: #0ea5e9;
--warm-orange: #f97316;
}
body {
background-color: var(--bg-primary);
color: #fafafa;
}
.spinner {
width: 32px;
height: 32px;
border: 2px solid #2e2e33;
border-top-color: #0ea5e9;
border-radius: 50%;
animation: spin 0.6s linear infinite;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
.btn-primary {
@apply inline-flex items-center justify-center gap-2 px-4 py-2 bg-ocean-blue text-white rounded-lg;
}
EOF
# Root layout
cat > src/app/layout.tsx << 'EOF'
import type { Metadata } from "next";
import { Inter } from "next/font/google";
import "./globals.css";
const inter = Inter({ subsets: ["latin"] });
export const metadata: Metadata = {
title: "RunLoop - Scheduler Platform",
description: "Modern scheduler platform for automated workflows",
};
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en" className="dark">
<body className={inter.className}>{children}</body>
</html>
);
}
EOF
# Root page (redirect)
cat > src/app/page.tsx << 'EOF'
import { redirect } from "next/navigation";
export default function HomePage() {
redirect("/dashboard");
}
EOF
# Login page
cat > src/app/login/page.tsx << 'EOF'
"use client";
import { useState } from "react";
import { useRouter } from "next/navigation";
export default function LoginPage() {
const router = useRouter();
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
// TODO: Implement login
router.push("/dashboard");
};
return (
<div className="min-h-screen flex items-center justify-center bg-dark-950">
<div className="w-full max-w-md p-8 bg-dark-850 rounded-xl border border-dark-700">
<h1 className="text-2xl font-bold text-white mb-6">Welcome to RunLoop</h1>
<form onSubmit={handleSubmit} className="space-y-4">
<div>
<label className="block text-sm font-medium text-gray-300 mb-1">Email</label>
<input
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
className="w-full px-4 py-2 bg-dark-900 border border-dark-600 rounded-lg text-white"
placeholder="you@example.com"
/>
</div>
<div>
<label className="block text-sm font-medium text-gray-300 mb-1">Password</label>
<input
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
className="w-full px-4 py-2 bg-dark-900 border border-dark-600 rounded-lg text-white"
placeholder="••••••••"
/>
</div>
<button type="submit" className="w-full btn-primary py-2.5">
Sign In
</button>
</form>
</div>
</div>
);
}
EOF
# Dashboard page (simple)
cat > src/app/dashboard/page.tsx << 'EOF'
"use client";
import Link from "next/link";
export default function DashboardPage() {
return (
<div className="p-8">
<h1 className="text-3xl font-bold text-white mb-4">Dashboard</h1>
<div className="grid grid-cols-1 md:grid-cols-3 gap-6">
<Link href="/projects" className="p-6 bg-dark-850 rounded-xl border border-dark-700 hover:border-ocean-blue/50">
<h2 className="text-xl font-semibold text-white">Projects</h2>
<p className="text-gray-400 mt-2">Manage your projects</p>
</Link>
<Link href="/schedulers" className="p-6 bg-dark-850 rounded-xl border border-dark-700 hover:border-ocean-blue/50">
<h2 className="text-xl font-semibold text-white">RunLoops</h2>
<p className="text-gray-400 mt-2">Manage schedulers</p>
</Link>
<Link href="/executions" className="p-6 bg-dark-850 rounded-xl border border-dark-700 hover:border-ocean-blue/50">
<h2 className="text-xl font-semibold text-white">Executions</h2>
<p className="text-gray-400 mt-2">View execution history</p>
</Link>
</div>
</div>
);
}
EOF
# API route handler
cat > "src/app/api/[[...path]]/route.ts" << 'EOF'
import { NextRequest, NextResponse } from "next/server";
const corsHeaders = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Authorization",
};
export async function OPTIONS() {
return NextResponse.json({}, { headers: corsHeaders });
}
export async function GET(request: NextRequest, { params }: { params: { path: string[] } }) {
const path = params.path || [];
return NextResponse.json({ message: "API Ready", path }, { headers: corsHeaders });
}
export async function POST(request: NextRequest, { params }: { params: { path: string[] } }) {
const path = params.path || [];
const body = await request.json().catch(() => ({}));
return NextResponse.json({ message: "API Ready", path, body }, { headers: corsHeaders });
}
EOF
echo "✓ Basic files created"
echo ""
# ============================================
# Step 9: Commit changes
# ============================================
echo "💾 Step 9: Committing changes..."
cd "$PROJECT_DIR"
git add -A
git commit -m "refactor: migrate to Next.js with apps/ structure
- Move frontend to apps/runloop (Next.js 16)
- Move executor to apps/runloop-engine
- Remove api-server (merged into Next.js API routes)
- Setup basePath: /runloop
- Add CORS and proxy config for Go engine"
git push origin master
echo "✓ Committed and pushed"
echo ""
# ============================================
# Done
# ============================================
echo "╔══════════════════════════════════════════════════════════════╗"
echo "║ ✅ SETUP COMPLETE! ║"
echo "╠══════════════════════════════════════════════════════════════╣"
echo "║ ║"
echo "║ 📁 Structure: ║"
echo "║ apps/runloop/ ← Next.js 16 + API ║"
echo "║ apps/runloop-engine/ ← Go Worker ║"
echo "║ ║"
echo "║ 🚀 Next steps: ║"
echo "║ 1. cd /Users/hacka/Works/RUNLOOP/apps/runloop ║"
echo "║ 2. npm run dev ║"
echo "║ 3. Open http://localhost:3000/runloop ║"
echo "║ ║"
echo "║ 📦 Run database: ║"
echo "║ docker run -d -p 5434:5432 \ ║"
echo "║ -e POSTGRES_PASSWORD=runloop_secret \ ║"
echo "║ postgres:16 ║"
echo "║ ║"
echo "╚══════════════════════════════════════════════════════════════╝"