UNPKG

create-app-setup

Version:

A CLI tool to quickly set up frontend & backend projects with various frameworks.

121 lines (120 loc) • 5.29 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.startProcess = void 0; const inquirer_1 = __importDefault(require("inquirer")); const path_1 = __importDefault(require("path")); const fs_1 = __importDefault(require("fs")); const Chalk_1 = require("../helper/Chalk"); const questions_1 = require("../Questions/questions"); const copyTemplate_1 = __importDefault(require("../helper/copyTemplate")); const cross_spawn_1 = __importDefault(require("cross-spawn")); const startProcess = async (projectName, TEMPLATES_DIR) => { // Dynamic Import for Ora const oraModule = await import("ora"); const ora = oraModule.default; console.log(Chalk_1.chalk.cyan.bold("\nšŸš€ Starting Project Setup...\n")); try { // Ask user questions const { framework, language, packageManager, prettier, husky, testingTool, storybook, eslint, compiler, } = await inquirer_1.default.prompt(questions_1.questions); // Define the template path based on user selection const templatePath = path_1.default.join(TEMPLATES_DIR, framework.toLowerCase(), language.toLowerCase()); // Check if the selected template exists if (!fs_1.default.existsSync(templatePath)) { console.log("\n" + Chalk_1.chalk.bgRed.white(" ERROR ") + Chalk_1.chalk.redBright(" Selected framework & language template does not exist!\n")); process.exit(1); } // Define the destination path const destinationPath = path_1.default.join(process.cwd(), projectName); // Copy the template (0, copyTemplate_1.default)({ sourceDir: templatePath, destinationDir: destinationPath, projectName, }); // Conditional Configuration Based on User Selection // // Prettier Setup // if (prettier) { // console.log(chalk.cyan("šŸ›  Setting up Prettier...")); // spawn(packageManager.toLowerCase(), ["add", "prettier", "-D"], { // cwd: destinationPath, // stdio: "inherit", // }); // } // ESLint Setup if (eslint) { console.log(Chalk_1.chalk.cyan("šŸ›  Setting up ESLint...")); (0, cross_spawn_1.default)(packageManager.toLowerCase(), ["add", "eslint", "-D"], { cwd: destinationPath, stdio: "inherit", }); } // // Husky Setup // if (husky) { // console.log(chalk.cyan("šŸ›  Setting up Husky...")); // spawn(packageManager.toLowerCase(), ["add", "husky", "-D"], { // cwd: destinationPath, // stdio: "inherit", // }); // } // // Testing Tool Setup (e.g., Jest, Cypress) // if (testingTool === "jest") { // console.log(chalk.cyan("šŸ›  Setting up Jest...")); // spawn(packageManager.toLowerCase(), ["add", "jest", "-D"], { // cwd: destinationPath, // stdio: "inherit", // }); // } // // Storybook Setup // if (storybook) { // console.log(chalk.cyan("šŸ›  Setting up Storybook...")); // spawn(packageManager.toLowerCase(), ["add", "@storybook/react"], { // cwd: destinationPath, // stdio: "inherit", // }); // } // // Compiler Setup (SWC or Babel) // if (compiler === "SWC") { // console.log(chalk.cyan("šŸ›  Setting up SWC...")); // spawn(packageManager.toLowerCase(), ["add", "@swc/core", "@swc/cli"], { // cwd: destinationPath, // stdio: "inherit", // }); // } console.log(Chalk_1.chalk.yellow("\nšŸ“¦ Installing dependencies...\n")); // Run install using selected package manager const installDeps = (0, cross_spawn_1.default)(packageManager.toLowerCase(), ["install"], { cwd: destinationPath, stdio: "pipe", shell: true, }); // Create a spinner with a custom message const spinner = ora(" Installing ...").start(); // Capture the output and stop the spinner when the process finishes // installDeps.stdout.on("data", (data) => { // // Optionally, you can log data here if needed // // For example, if you want to output some specific messages // }); // installDeps.stderr.on("data", (data) => { // // Optionally, you can log errors here // console.error(data.toString()); // }); installDeps.on("close", (code) => { if (code === 0) { spinner.succeed(Chalk_1.chalk.bold.magentaBright("šŸŽ‰ Setup Complete! Happy Coding! šŸš€")); } else { spinner.fail(Chalk_1.chalk.redBright(`āŒ ${packageManager} install failed with code: ${code}`)); } }); } catch (error) { // If user exits or any error occurs during prompt console.log(Chalk_1.chalk.red("\nāŒ Exited the Process")); } }; exports.startProcess = startProcess;