From 54a7b00a73a360df3201634e5a9df880d0b3be62 Mon Sep 17 00:00:00 2001 From: codex-agent Date: Mon, 13 Oct 2025 22:28:47 +0000 Subject: [PATCH] EvoCoder iteration 1 --- AGENTS.md | 6 +- README.md | 6 +- jest.config.js | 2 +- scripts/migrate-page.cjs | 181 --------------------------------------- tailwind.config.js | 1 - tsconfig.json | 2 - 6 files changed, 7 insertions(+), 191 deletions(-) delete mode 100644 scripts/migrate-page.cjs diff --git a/AGENTS.md b/AGENTS.md index 22c2b38848..a3a31d9973 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -67,9 +67,9 @@ Use the `/codex/` directory as the shared source of truth for planning and ticke ## Next.js Directory Structure -The project supports both the classic `pages/` folder and Next.js `app/` router. -Legacy routes remain under `pages/`, while all **new** pages must be created -inside the `app/` directory. +All production routes now live under the Next.js `app/` router. +The legacy `pages/` directory has been fully migrated, so add any new routes +under `app/`. Routes in `app/` should export a `generateMetadata` function using the helper `getAppMetadata`: diff --git a/README.md b/README.md index 2c4effd615..0b76a43d0a 100644 --- a/README.md +++ b/README.md @@ -61,9 +61,9 @@ pm2 start npm --name=6529seize -- run start ## Directory Structure -This project uses both the legacy `pages/` directory and the new `app/` router -from Next.js. Existing pages remain under `pages/`, while **all new pages should -be created in `app/`**. +All application routes now live under Next.js’s `app/` router. +The legacy `pages/` directory has been fully migrated, so create any new routes +inside `app/`. Pages inside `app/` must define a `generateMetadata` function that returns the result of `getAppMetadata`: diff --git a/jest.config.js b/jest.config.js index 609a71c850..2df578836a 100644 --- a/jest.config.js +++ b/jest.config.js @@ -63,7 +63,7 @@ const config = { collectCoverage: true, collectCoverageFrom: [ // Target actual source directories like app, components, contexts, etc. - "{app,components,contexts,entities,helpers,hooks,lib,pages,services,store,utils,wagmiConfig}/**/*.{ts,tsx}", + "{app,components,contexts,entities,helpers,hooks,lib,services,store,utils,wagmiConfig}/**/*.{ts,tsx}", // Exclude all TypeScript definition files from coverage "!**/*.d.ts", // Exclude node_modules diff --git a/scripts/migrate-page.cjs b/scripts/migrate-page.cjs deleted file mode 100644 index cf12e8389b..0000000000 --- a/scripts/migrate-page.cjs +++ /dev/null @@ -1,181 +0,0 @@ -#!/usr/bin/env node -/* eslint-disable */ - -const fs = require("fs"); -const path = require("path"); - -const inputDir = process.argv[2]; - -if (!inputDir) { - console.error("Usage: node migrate-pages.cjs "); - process.exit(1); -} - -const inputPath = path.resolve(inputDir); -const PAGES_DIR = path.resolve("pages"); -const APP_DIR = path.resolve("app"); - -function walk(dir) { - const results = []; - const entries = fs.readdirSync(dir, { withFileTypes: true }); - for (const entry of entries) { - const fullPath = path.join(dir, entry.name); - if (entry.isDirectory()) { - results.push(...walk(fullPath)); - } else if (entry.isFile() && entry.name === "index.tsx") { - results.push(fullPath); - } - } - return results; -} - -function migrateIndexFile(indexFile) { - const fileDir = path.dirname(indexFile); - const relative = path.relative(PAGES_DIR, indexFile); - const newFile = path - .join(APP_DIR, relative) - .replace(/index\.tsx$/, "page.tsx"); - fs.mkdirSync(path.dirname(newFile), { recursive: true }); - - let content = fs.readFileSync(indexFile, "utf8"); - - // Extract - let title = "Page"; - const titleMatch = content.match(/<title>(.*?)<\/title>/i); - if (titleMatch) { - title = titleMatch[1].trim(); - } - - // Remove unused imports - content = content - .replace(/^import\s+React\s+from\s+["']react["'];?\n?/gm, "") - .replace(/^import\s+HeaderPlaceholder.*\n?/gm, "") - .replace(/^import\s+dynamic.*\n?/gm, "") - .replace(/^const\s+Header\s+=\s+dynamic\(\(\)\s+=>.*?\n^\s*}\);\n?/gms, ""); - - // Remove top-level fragment if it's the only wrapper - content = content.replace( - /(\(\s*)<>\s*\n?([\s\S]*?)\n?\s*<\/>\s*(\);)/, - "$1$2$3" - ); - - // Replace default export if needed - content = content.replace( - /export\s+default\s+.*?;/, - "export default IndexPage;" - ); - - // Add metadata imports - const metaImports = `import { getAppMetadata } from "@/components/providers/metadata";\nimport type { Metadata } from "next";\n`; - content = metaImports + content.trim() + "\n"; - - // Append generateMetadata - content += `\nexport async function generateMetadata() {\n return getAppMetadata({ title: "${title}" });\n}\n`; - - fs.writeFileSync(newFile, content.trim() + "\n", "utf8"); - fs.unlinkSync(indexFile); - - function updateImportsInTests(oldImportPath, newImportPath) { - const testRoot = path.resolve("__tests__"); - const testFiles = walkFiles(testRoot); - - for (const file of testFiles) { - let content = fs.readFileSync(file, "utf8"); - const updated = content.replace( - new RegExp(`from ['"]([^'"]*?)${escapeRegex(oldImportPath)}['"]`, "g"), - (match, pre) => `from "${pre}${newImportPath}"` - ); - - if (content !== updated) { - fs.writeFileSync(file, updated, "utf8"); - console.log(`✏ Updated imports in ${file}`); - } - } - } - - function escapeRegex(str) { - return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); - } - - function walkFiles(dir) { - if (!fs.existsSync(dir)) return []; - const entries = fs.readdirSync(dir, { withFileTypes: true }); - let results = []; - - for (const entry of entries) { - const full = path.join(dir, entry.name); - if (entry.isDirectory()) { - results = results.concat(walkFiles(full)); - } else if (entry.isFile() && /\.(t|j)sx?$/.test(entry.name)) { - results.push(full); - } - } - return results; - } - - const oldImportPath = "pages/" + relative.replace(/\/index\.tsx$/, ""); - const newImportPath = path - .relative(process.cwd(), newFile) - .replace(/\.tsx$/, "") - .replaceAll("\\", "/"); // for Windows - - updateImportsInTests(oldImportPath, newImportPath); - - // Remove the leaf folder if empty - tryRemoveFolder(fileDir); - - console.log(`✅ Migrated ${indexFile} -> ${newFile}`); -} - -function tryRemoveFolder(dir) { - if (!fs.existsSync(dir)) return; // Skip if folder was already removed - if (!dir.startsWith(PAGES_DIR)) return; // Don't delete outside /pages - - const entries = fs.readdirSync(dir, { withFileTypes: true }); - if (entries.length > 0) return; // Not empty, stop here - - try { - fs.rmdirSync(dir); - console.log(`🗑 Deleted empty folder ${dir}`); - tryRemoveFolder(path.dirname(dir)); // Recursively clean parent - } catch (err) { - if (err.code !== "ENOTEMPTY") throw err; // Only ignore ENOTEMPTY - } -} - -function hasIndexTSXRecursively(dir) { - if (!fs.existsSync(dir)) return false; - const entries = fs.readdirSync(dir, { withFileTypes: true }); - for (const entry of entries) { - const fullPath = path.join(dir, entry.name); - if (entry.isFile() && entry.name === "index.tsx") return true; - if (entry.isDirectory() && hasIndexTSXRecursively(fullPath)) return true; - } - return false; -} - -// Run only in the given inputDir -if (!fs.existsSync(inputPath)) { - console.error(`❌ Folder not found: ${inputDir}`); - process.exit(1); -} - -const files = walk(inputPath); -if (files.length === 0) { - console.log(`No index.tsx files found under ${inputDir}`); - process.exit(0); -} - -// Migrate all -for (const file of files) { - try { - migrateIndexFile(file); - } catch (err) { - console.error(`❌ Failed to migrate ${file}`, err); - } -} - -// Final cleanup: remove inputDir (and parents) if no more index.tsx -if (!hasIndexTSXRecursively(inputPath)) { - tryRemoveFolder(inputPath); -} diff --git a/tailwind.config.js b/tailwind.config.js index 76de1682e7..f2344ad05e 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -3,7 +3,6 @@ module.exports = { darkMode: "class", content: [ "./app/**/*.{js,ts,jsx,tsx}", - "./pages/**/*.{js,ts,jsx,tsx}", "./components/**/*.{js,ts,jsx,tsx}", // Or if using `src` directory: diff --git a/tsconfig.json b/tsconfig.json index 347df58b6e..a0ab578ed3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -28,8 +28,6 @@ "next-env.d.ts", "**/*.ts", "**/*.tsx", - "pages/_document.tsx", - "pages/**/*.jsx", ".next/types/**/*.ts" ], "exclude": ["node_modules", "tests", "e2e"]