UNPKG

create-app-setup

Version:

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

131 lines (130 loc) • 5.8 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 eslint_config_1 = __importDefault(require("../config/eslint-config")); const gitignore_config_1 = __importDefault(require("../config/gitignore-config")); const husky_config_1 = require("../config/husky-config"); const prettier_config_1 = require("../config/prettier-config"); const turboPack_next_config_1 = require("../config/turboPack-next-config"); 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, turbopack, } = 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) { (0, prettier_config_1.prettierConfig)({ destinationPath, pkgJson: `./${projectName}/package.json`, }); } // ESLint Setup if (eslint) { (0, eslint_config_1.default)({ isTypescript: language?.toLowerCase() == "typescript", isJest: testingTool?.toLowerCase() == "jest", isPrettier: prettier, pkgJson: `./${projectName}/package.json`, destinationPath: `./${projectName}`, }); } // Husky Setup if (husky) { (0, husky_config_1.huskyConfig)({ // pkgJson: `./${projectName}/package.json`, destinationPath, // TEMPLATES_DIR, // projectName, packageManager, }); } if (framework === "Next" && turbopack) { (0, turboPack_next_config_1.turboPackNextConfig)({ pkgJson: `./${projectName}/package.json` }); } // // 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", // }); // } //Renaming the GitIgnore (0, gitignore_config_1.default)({ path: `${projectName}/gitignore` }); // Installing Dependencies if (packageManager !== 'none') { 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(); 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}`)); } }); } else { console.log(Chalk_1.chalk.bold.magentaBright("šŸŽ‰ Setup Complete! Happy Coding! šŸš€")); } } catch (error) { // If user exits or any error occurs during prompt console.log(Chalk_1.chalk.red("\nāŒ Exited the Process", error)); } }; exports.startProcess = startProcess;