UNPKG

initia-devaxis

Version:

CLI to create full-stack React projects with Next.js (REST) or RedwoodJS (GraphQL)

267 lines (239 loc) 9.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createRedwoodProject = createRedwoodProject; const child_process_1 = require("child_process"); const promises_1 = require("fs/promises"); const path_1 = require("path"); const util_1 = require("util"); const execAsync = (0, util_1.promisify)(child_process_1.exec); /** * Crée un nouveau projet RedwoodJS avec la configuration spécifiée */ async function createRedwoodProject(config) { // Vérifier que Yarn est disponible await checkYarnAvailability(); // Arguments simplifiés - laissons RedwoodJS gérer l'installation par défaut const args = ["dlx", "create-redwood-app", config.name]; // Options de base seulement if (config.typescript) { args.push("--typescript"); } args.push("--yes"); // Accepter automatiquement try { // Créer le projet RedwoodJS avec la commande standard qui fonctionne await executeCommandWithLoader("yarn", args, { timeout: 900000, // 15 minutes pour tout le processus loadingMessage: "Creating RedwoodJS project...", }); // Configuration post-création (optionnelle et simplifiée) try { if (config.prettier) { await setupPrettierSimple(config.name); } await createRedwoodReadme(config); } catch (postError) { // Les erreurs post-création ne sont pas critiques } } catch (error) { throw new Error(`Failed to create RedwoodJS project: ${error instanceof Error ? error.message : String(error)}`); } } /** * Vérifie que Yarn est installé et compatible */ async function checkYarnAvailability() { try { await executeCommandWithLoader("yarn", ["--version"]); } catch (error) { throw new Error(` Yarn is required to create a RedwoodJS project. Install Yarn by running: npm install -g yarn Or visit: https://yarnpkg.com/getting-started/install For Yarn 4.x (recommended): npm install -g yarn@4 `); } } /** * Exécute une commande silencieusement avec un loader */ async function executeCommandWithLoader(command, args, options) { const fullCommand = `${command} ${args.join(" ")}`; try { const { stdout, stderr } = await execAsync(fullCommand, { cwd: options?.cwd, timeout: options?.timeout || 600000, maxBuffer: 1024 * 1024 * 10, // 10MB buffer env: { ...process.env, // Configuration pour minimiser les outputs non nécessaires CI: "true", NODE_ENV: "production", }, }); // Ne montrer que les messages d'erreur ou les interactions nécessaires if (stderr && stderr.includes("?")) { // Si RedwoodJS pose une question, l'afficher console.error(stderr); } } catch (error) { // En cas d'erreur, montrer les détails pour le debugging if (error.stdout) { console.log(error.stdout); } if (error.stderr) { console.error(error.stderr); } throw new Error(`Command failed: ${error.message}`); } } // Ancienne fonction supprimée - utilisons executeCommandWithLoader /** * Configure Prettier de manière simplifiée pour éviter les conflits */ async function setupPrettierSimple(projectName) { const projectPath = (0, path_1.join)(process.cwd(), projectName); // Juste ajouter les scripts au package.json, sans toucher aux dépendances try { const packageJsonPath = (0, path_1.join)(projectPath, "package.json"); const packageJson = JSON.parse(await (0, promises_1.readFile)(packageJsonPath, "utf-8")); // Ajouter seulement les scripts si pas déjà présents if (!packageJson.scripts.format) { packageJson.scripts = { ...packageJson.scripts, format: "prettier --write .", "format:check": "prettier --check .", }; await (0, promises_1.writeFile)(packageJsonPath, JSON.stringify(packageJson, null, 2)); } } catch (error) { // Ignorer les erreurs de configuration Prettier - ce n'est pas critique } } /** * Améliore la configuration ESLint pour RedwoodJS (sans installer de dépendances) */ async function enhanceESLintConfig(projectName, typescript, prettier) { const projectPath = (0, path_1.join)(process.cwd(), projectName); // RedwoodJS a déjà une config ESLint, on l'améliore sans toucher aux dépendances const eslintConfigPath = (0, path_1.join)(projectPath, ".eslintrc.js"); let eslintConfig = { extends: ["@redwoodjs/eslint-config"], rules: { // Règles personnalisées pour RedwoodJS "jsx-a11y/no-onchange": "off", "react/prop-types": "off", }, }; // Note: On évite d'installer prettier dependencies car ça cause des erreurs // RedwoodJS a déjà ses propres dépendances Prettier const eslintConfigContent = `module.exports = ${JSON.stringify(eslintConfig, null, 2)}`; await (0, promises_1.writeFile)(eslintConfigPath, eslintConfigContent); } /** * Crée un README personnalisé pour le projet RedwoodJS */ async function createRedwoodReadme(config) { const projectPath = (0, path_1.join)(process.cwd(), config.name); const readme = `# ${config.name} This project was created with [INITIA CLI](https://github.com/your-username/initia) using **${config.framework}**. ## 🚀 Quick Start Install dependencies: \`\`\`bash yarn install \`\`\` Start the development server: \`\`\`bash yarn rw dev \`\`\` Your application will be available at: - 🎨 **Frontend**: [http://localhost:8910](http://localhost:8910) - 🔌 **Backend/API**: [http://localhost:8911](http://localhost:8911) - 📊 **GraphQL Playground**: [http://localhost:8911/graphql](http://localhost:8911/graphql) ## 📁 Project Structure \`\`\` ${config.name}/ ├── api/ # Backend (Functions, GraphQL, Services) │ ├── src/ │ │ ├── functions/ # Serverless functions │ │ ├── graphql/ # GraphQL schemas and resolvers │ │ ├── lib/ # Shared configuration │ │ └── services/ # Business logic │ └── db/ # Database (Prisma) ├── web/ # Frontend (React) │ ├── src/ │ │ ├── components/# React components │ │ ├── layouts/ # Page layouts │ │ ├── pages/ # Application pages │ │ └── Routes.${config.typescript ? "tsx" : "jsx"} # Route configuration └── scripts/ # Utility scripts \`\`\` ## 🛠️ Available Scripts ### Development - \`yarn rw dev\` - Start development servers (frontend + backend) - \`yarn rw dev api\` - Start API server only - \`yarn rw dev web\` - Start web server only ### Production - \`yarn rw build\` - Build for production - \`yarn rw build api\` - Build API only - \`yarn rw build web\` - Build frontend only ### Database - \`yarn rw prisma migrate dev\` - Apply migrations in development - \`yarn rw prisma studio\` - Open Prisma Studio - \`yarn rw db seed\` - Run seeding scripts ### Code Quality - \`yarn rw lint\` - Run ESLint${config.prettier ? "\n- `yarn format` - Format code with Prettier\n- `yarn format:check` - Check formatting" : ""} ### Testing - \`yarn rw test\` - Run tests - \`yarn rw test --watch\` - Run tests in watch mode ## 🔧 Configuration ### Technologies used: - 🌲 **RedwoodJS** - Full-stack framework - ⚛️ **React** - Frontend library - 🔗 **GraphQL** - API query language - 🗄️ **Prisma** - Database ORM - 📦 **SQLite** - Database (development) ${config.typescript ? "- 🔷 **TypeScript** - Static typing" : "- 📜 **JavaScript** - Base language"} ${config.eslint ? "- 🔍 **ESLint** - Code linting" : ""} ${config.prettier ? "- 💅 **Prettier** - Code formatting" : ""} ## 🗄️ Database RedwoodJS uses **Prisma** as ORM. The database schema is located at \`api/db/schema.prisma\`. To create your first migration: \`\`\`bash yarn rw prisma migrate dev --name init \`\`\` ## 🚀 Deployment RedwoodJS can be deployed to several platforms: - **Vercel** (recommended for beginners) - **Netlify** - **AWS** - **Railway** See the [deployment documentation](https://redwoodjs.com/docs/deploy) for more details. ## 📚 Documentation - [RedwoodJS Documentation](https://redwoodjs.com/docs) - [RedwoodJS Tutorial](https://redwoodjs.com/docs/tutorial/foreword) - [Prisma Documentation](https://www.prisma.io/docs) - [GraphQL Documentation](https://graphql.org/learn/) ${config.typescript ? "- [TypeScript Documentation](https://www.typescriptlang.org/docs/)" : ""} ## 🎯 Next Steps 1. Explore the project structure 2. Read the [RedwoodJS tutorial](https://redwoodjs.com/docs/tutorial/foreword) 3. Create your first model in \`api/db/schema.prisma\` 4. Generate pages with \`yarn rw generate page\` 5. Create CRUD scaffolds with \`yarn rw generate scaffold\` --- ✨ **Generated by INITIA CLI** - For an optimal development experience `; await (0, promises_1.writeFile)((0, path_1.join)(projectPath, "README.md"), readme); } //# sourceMappingURL=redwood.js.map