{"path":"lib/detect.js","size":2324,"locked":false,"binary":false,"truncated":false,"content":"import { existsSync, readFileSync } from 'node:fs';\nimport { join } from 'node:path';\n\n/**\n * Detects the static site framework used in a project directory.\n * MVP scope (locked): Next.js static export, Vite, Create React App only.\n * Anything else should fail loudly rather than guess.\n */\nexport function detectFramework(cwd) {\n  const pkgPath = join(cwd, 'package.json');\n  if (!existsSync(pkgPath)) {\n    throw new Error('No package.json found — run `anchr init` from your project root.');\n  }\n\n  const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));\n  const deps = { ...pkg.dependencies, ...pkg.devDependencies };\n\n  if (deps.vite) {\n    return {\n      framework: 'vite',\n      buildCommand: 'npm run build',\n      outputDir: 'dist',\n      note:\n        \"IPFS content is served from a /ipfs/<CID>/ subpath, not domain root — Vite's \" +\n        \"default absolute asset paths will cause a blank page until you set \" +\n        \"`base: './'` in vite.config.js. CONFIRMED via a real deploy: this exact fix \" +\n        \"was needed to go from a blank page to a fully working site.\"\n    };\n  }\n\n  if (deps.next) {\n    return {\n      framework: 'next',\n      buildCommand: 'npm run build',\n      outputDir: 'out',\n      note:\n        \"Next.js detected — this only works with static export. Make sure next.config.js \" +\n        \"has `output: 'export'` set, or the build won't produce a static 'out' directory. \" +\n        \"Likely also needs a relative asset path fix (e.g. `assetPrefix: './'`) for the \" +\n        \"same reason Vite does — NOT independently confirmed via a real deploy yet, \" +\n        \"verify before assuming it works out of the box.\"\n    };\n  }\n\n  if (deps['react-scripts']) {\n    return {\n      framework: 'cra',\n      buildCommand: 'npm run build',\n      outputDir: 'build',\n      note:\n        \"Add `\\\"homepage\\\": \\\".\\\"` to package.json so CRA builds with relative asset \" +\n        \"paths — needed for IPFS hosting the same way Vite needs `base: './'` \" +\n        \"(confirmed via a real deploy on Vite; CRA's fix is the standard documented \" +\n        \"approach for deploying to a non-root subpath, but not independently tested here).\"\n    };\n  }\n\n  throw new Error(\n    'Could not detect a supported framework. MVP scope only covers Vite, Next.js (static export), and Create React App.'\n  );\n}\n"}