UNPKG

initia-devaxis

Version:

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

153 lines 6.25 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.initCommand = initCommand; const chalk_1 = __importDefault(require("chalk")); const fs_1 = require("fs"); const inquirer_1 = __importDefault(require("inquirer")); const path_1 = require("path"); const nextjs_1 = require("../utils/generators/nextjs"); const redwood_1 = require("../utils/generators/redwood"); function checkProjectExists(projectName) { const projectPath = (0, path_1.join)(process.cwd(), projectName); return (0, fs_1.existsSync)(projectPath); } async function showSpinner(message, operation) { const spinnerChars = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]; let spinnerIndex = 0; let isSpinning = true; process.stdout.write(`\n${chalk_1.default.cyan("→")} ${message} ${spinnerChars[0]}`); const spinnerInterval = setInterval(() => { if (isSpinning) { spinnerIndex = (spinnerIndex + 1) % spinnerChars.length; process.stdout.write(`\r${chalk_1.default.cyan("→")} ${message} ${spinnerChars[spinnerIndex]}`); } }, 100); try { await operation(); isSpinning = false; clearInterval(spinnerInterval); process.stdout.write(`\r${chalk_1.default.cyan("→")} ${message} ${chalk_1.default.green("✓")}\n`); } catch (error) { isSpinning = false; clearInterval(spinnerInterval); process.stdout.write(`\r${chalk_1.default.cyan("→")} ${message} ${chalk_1.default.red("✗")}\n`); throw error; } } async function initCommand() { try { console.log(chalk_1.default.cyan("→ Project Configuration\n")); const config = await inquirer_1.default.prompt([ { type: "input", name: "name", message: "Project name:", validate: (input) => { if (!input || input.trim().length === 0) { return "Project name is required"; } if (!/^[a-zA-Z0-9-_]+$/.test(input.trim())) { return "Name can only contain letters, numbers, hyphens and underscores"; } const projectPath = (0, path_1.join)(process.cwd(), input.trim().toLowerCase()); if ((0, fs_1.existsSync)(projectPath)) { return `❌ A folder named "${input .trim() .toLowerCase()}" already exists. Please choose a different name.`; } return true; }, filter: (input) => input.trim().toLowerCase(), }, { type: "list", name: "framework", message: "Framework:", choices: [ { name: "Next.js - Full-stack React framework (REST/API Routes)", value: "Next.js", }, { name: "RedwoodJS - Full-stack React framework (GraphQL)", value: "RedwoodJS", }, ], default: "Next.js", }, { type: "confirm", name: "typescript", message: "Use TypeScript?", default: true, }, { type: "confirm", name: "eslint", message: "Configure ESLint?", default: true, }, { type: "confirm", name: "prettier", message: "Configure Prettier?", default: true, }, { type: "confirm", name: "tailwind", message: "Include Tailwind CSS?", default: true, when: (answers) => answers.framework === "Next.js", }, { type: "list", name: "packageManager", message: "Package manager:", choices: [ { name: "npm", value: "npm" }, { name: "yarn", value: "yarn" }, { name: "pnpm", value: "pnpm" }, ], default: "npm", when: (answers) => answers.framework === "Next.js", }, ]); if (checkProjectExists(config.name)) { throw new Error(`Project folder "${config.name}" already exists. Please remove it or choose a different name.`); } try { if (config.framework === "Next.js") { await showSpinner("Creating Next.js project...", () => (0, nextjs_1.createNextProject)(config)); } else if (config.framework === "RedwoodJS") { await showSpinner("Creating RedwoodJS project...", () => (0, redwood_1.createRedwoodProject)(config)); } console.log("\n" + chalk_1.default.cyan("→ Next steps:")); console.log(chalk_1.default.white(` cd ${config.name}`)); if (config.framework === "Next.js") { const packageManager = config.packageManager || "npm"; console.log(chalk_1.default.white(` ${packageManager} run dev`)); console.log(chalk_1.default.gray(" # Open http://localhost:3000")); } else { console.log(chalk_1.default.white(" yarn rw dev")); console.log(chalk_1.default.gray(" # Frontend: http://localhost:8910")); console.log(chalk_1.default.gray(" # Backend: http://localhost:8911")); } return config.name; } catch (error) { throw error; } } catch (error) { console.log(chalk_1.default.red("\n✗ Error:", error instanceof Error ? error.message : String(error))); return null; } } //# sourceMappingURL=init.js.map