UNPKG

validstart

Version:

ValidStart is a powerful and intuitive command-line interface (CLI) tool meticulously crafted to streamline the project setup process.

79 lines (61 loc) • 2.59 kB
import { execa } from "execa";; import path from "path"; import chalk from "chalk";; import fs from "fs-extra"; interface Options { projectName: string; projectType: string; language: string; framework: string; selectedTools: string[]; } export async function scaffoldFrontendJS(options: Options): Promise<void> { const { projectName, framework, selectedTools } = options; const projectPath = path.resolve(process.cwd(), projectName); if (framework !== "React") { console.log(chalk.red(`āŒ Only React is supported for JavaScript frontend at the moment.`)); return; } console.log(chalk.cyan(`\n🚧 Creating React + Vite project: ${chalk.bold(projectName)}`)); await execa("npm", ["create", "vite@latest", projectName, "--", "--template", "react"], { stdio: "inherit", }); const toolDeps: string[] = []; if (selectedTools.includes("react-router-dom")) { toolDeps.push("react-router-dom"); } if (selectedTools.includes("tailwindcss")) { toolDeps.push("tailwindcss", "postcss", "autoprefixer"); await setupTailwind(projectPath); } if (selectedTools.includes("shadcn/ui")) { toolDeps.push("class-variance-authority", "tailwind-variants", "lucide-react"); console.log(chalk.yellow("āš ļø You will need to manually initialize shadcn/ui afterwards.")); } if (toolDeps.length > 0) { console.log(chalk.blue(`šŸ“¦ Installing additional tools: ${toolDeps.join(", ")}`)); await execa("npm", ["install", ...toolDeps], { cwd: projectPath, stdio: "inherit", }); } console.log(chalk.gray("šŸ”§ Initializing git...")); await execa("git", ["init"], { cwd: projectPath }); console.log(chalk.green(`\nāœ… React project '${projectName}' created at ${projectPath}\n`)); } async function setupTailwind(projectPath: string): Promise<void> { console.log(chalk.blue(`āš™ļø Setting up TailwindCSS...`)); await execa("npx", ["tailwindcss", "init", "-p"], { cwd: projectPath }); const inputCssPath = path.join(projectPath, "src", "index.css"); const tailwindDirectives = `@tailwind base;\n@tailwind components;\n@tailwind utilities;\n`; if (await fs.pathExists(inputCssPath)) { await fs.writeFile(inputCssPath, tailwindDirectives); } const configPath = path.join(projectPath, "tailwind.config.js"); const updatedConfig = `module.exports = { content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"], theme: { extend: {} }, plugins: [], };`; await fs.writeFile(configPath, updatedConfig); }