import fs from 'fs';
import path from 'path';
export function generatePage(rootPath: string, pageName: string, components: string[] = []) {
const pagesDir = path.join(rootPath, 'app', pageName.toLowerCase());
if (!fs.existsSync(pagesDir)) fs.mkdirSync(pagesDir, { recursive: true });
const imports = components.map((c) => `import ${c} from "../../components/${c}";`).join('\n');
const jsxComponents = components.map((c) => `<${c} />`).join('\n ');
const code = `
${imports}
export default function ${pageName}Page() {
return (
<div>
${jsxComponents}
</div>
);
}
`;
const filePath = path.join(pagesDir, 'page.tsx');
fs.writeFileSync(filePath, code);
return filePath;
}
// Example usage:
// generatePage("/path/to/project", "Home", ["Header", "Footer"]);
// This will create a file at /path/to/project/app/home/page.tsx
// with imports for Header and Footer components.
// The generated file will look like this:
// import Header from "../../components/Header";
// import Footer from "../../components/Footer";
//
// export default function HomePage() {
// return (
// <div>
// <Header />
// <Footer />
// </div>
// );
// }