Kakashiix26 commited on
Commit
9f6bbd7
Β·
verified Β·
1 Parent(s): 9c61e67

framework-aware publish: build_publish_repo

Browse files
agent/__pycache__/scaffold.cpython-314.pyc CHANGED
Binary files a/agent/__pycache__/scaffold.cpython-314.pyc and b/agent/__pycache__/scaffold.cpython-314.pyc differ
 
agent/scaffold.py CHANGED
@@ -397,3 +397,111 @@ def to_vite_project(files: dict[str, str], name: str) -> dict[str, str]:
397
  "Deploy on Vercel (framework preset: Vite) β€” `npm run build`, output `dist/`.\n"
398
  )
399
  return out
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
397
  "Deploy on Vercel (framework preset: Vite) β€” `npm run build`, output `dist/`.\n"
398
  )
399
  return out
400
+
401
+
402
+ # ── per-framework publish repo builders ─────────────────────────────────────
403
+
404
+ _STATIC_GITIGNORE = ".DS_Store\n"
405
+
406
+ _NEXT_GITIGNORE = (
407
+ "# dependencies\nnode_modules/\n\n"
408
+ "# Next.js build output\n.next/\nout/\n\n"
409
+ "# misc\n.DS_Store\n"
410
+ )
411
+
412
+
413
+ def _build_static_repo(files: dict[str, str], title: str) -> dict[str, str]:
414
+ """Plain static site repo: raw files at repo root, index.html at root. No build step.
415
+
416
+ Vercel serves a static site automatically when it finds index.html at the root β€”
417
+ no vercel.json needed.
418
+ """
419
+ out: dict[str, str] = {}
420
+ for path, content in files.items():
421
+ out[path.lstrip("/")] = content # strip leading / so index.html lands at root
422
+ if "index.html" not in out:
423
+ out["index.html"] = _DEFAULT_STATIC_INDEX
424
+ out[".gitignore"] = _STATIC_GITIGNORE
425
+ t = title or "App"
426
+ out["README.md"] = (
427
+ f"# {t}\n\n"
428
+ "A static site generated by AppSmith / CodyBuddy Studio.\n\n"
429
+ "## Deploy\n\n"
430
+ "Push to GitHub, then import on Vercel β€” it auto-detects a static site "
431
+ "(no build step needed).\n"
432
+ )
433
+ return out
434
+
435
+
436
+ def _build_nextjs_repo(files: dict[str, str], title: str) -> dict[str, str]:
437
+ """Next.js App Router repo: files as-is, package.json with correct scripts + next dep.
438
+
439
+ Vercel zero-config auto-detects Next.js β€” no vercel.json needed.
440
+ """
441
+ out: dict[str, str] = {}
442
+ for path, content in files.items():
443
+ out[path.lstrip("/")] = content
444
+
445
+ # Parse or create package.json with required scripts + next/react/react-dom deps.
446
+ pkg_raw = out.get("package.json", "")
447
+ try:
448
+ pkg: dict = json.loads(pkg_raw) if pkg_raw else {}
449
+ except (json.JSONDecodeError, TypeError):
450
+ pkg = {}
451
+ if not isinstance(pkg, dict):
452
+ pkg = {}
453
+
454
+ pkg.setdefault("name", slugify(title))
455
+ pkg.setdefault("version", "0.0.0")
456
+ pkg.setdefault("private", True)
457
+
458
+ scripts = pkg.get("scripts") or {}
459
+ scripts.setdefault("dev", "next dev")
460
+ scripts.setdefault("build", "next build")
461
+ scripts.setdefault("start", "next start")
462
+ pkg["scripts"] = scripts
463
+
464
+ deps = pkg.get("dependencies") or {}
465
+ for name, version in NEXT_BASE_DEPENDENCIES.items():
466
+ deps.setdefault(name, version)
467
+ pkg["dependencies"] = deps
468
+
469
+ out["package.json"] = json.dumps(pkg, indent=2)
470
+
471
+ # Minimal next.config.js only if absent.
472
+ if "next.config.js" not in out and "next.config.ts" not in out:
473
+ out["next.config.js"] = (
474
+ "/** @type {import('next').NextConfig} */\n"
475
+ "const nextConfig = {};\n"
476
+ "module.exports = nextConfig;\n"
477
+ )
478
+
479
+ out[".gitignore"] = _NEXT_GITIGNORE
480
+ t = title or "App"
481
+ out["README.md"] = (
482
+ f"# {t}\n\n"
483
+ "A Next.js app generated by AppSmith / CodyBuddy Studio.\n\n"
484
+ "## Develop\n\n"
485
+ "```bash\nnpm install\nnpm run dev\n```\n\n"
486
+ "## Deploy\n\n"
487
+ "Push to GitHub, then import on Vercel β€” it auto-detects Next.js "
488
+ "(no configuration needed).\n"
489
+ )
490
+ return out
491
+
492
+
493
+ def build_publish_repo(files: dict[str, str], framework: str, title: str) -> dict[str, str]:
494
+ """Build a deployable repo file map for the given framework.
495
+
496
+ react β†’ Vite+React via to_vite_project; Vercel detects as Vite (build: vite build).
497
+ static β†’ raw HTML/CSS/JS, index.html at repo root; Vercel zero-config static serving.
498
+ nextjs β†’ Next App Router files as-is; Vercel zero-config Next.js auto-detection.
499
+
500
+ Unknown framework values silently coerce to 'react'.
501
+ """
502
+ fw = coerce_framework(framework)
503
+ if fw == "static":
504
+ return _build_static_repo(files, title)
505
+ if fw == "nextjs":
506
+ return _build_nextjs_repo(files, title)
507
+ return to_vite_project(files, title) # react (default)