import fs from "fs-extra"; import path from "path"; import chalk from "chalk"; /** * Generate a new React component * @param componentName The name of the component * @param projectType 'next-app', 'next-pages', 'react' * @param withStyles Optional: add Tailwind class example */ export async function generateComponent( componentName: string, projectType: "next-app" | "next-pages" | "react" = "react", withStyles: boolean = true ) { if (!componentName) { console.error(chalk.red("❌ Component name is required!")); return; } let baseDir: string; switch (projectType) { case "next-app": baseDir = path.join(process.cwd(), "app", "components"); break; case "next-pages": baseDir = path.join(process.cwd(), "src", "components"); break; case "react": default: baseDir = fs.existsSync(path.join(process.cwd(), "src")) ? path.join(process.cwd(), "src", "components") : path.join(process.cwd(), "components"); break; } fs.ensureDirSync(baseDir); const componentDir = path.join(baseDir, componentName); fs.ensureDirSync(componentDir); // فایل Component.tsx const componentContent = `import React from 'react'; interface ${componentName}Props { // add props here } const ${componentName}: React.FC<${componentName}Props> = (props) => { return (

${componentName} Component

); }; export default ${componentName}; `; fs.writeFileSync(path.join(componentDir, `${componentName}.tsx`), componentContent); // index.ts const indexContent = `export { default } from './${componentName}';\n`; fs.writeFileSync(path.join(componentDir, "index.ts"), indexContent); console.log(chalk.green(`✅ Component "${componentName}" created in ${componentDir}`)); }