mern-auth-boilerplate
Version:
CLI to scaffold a MERN Auth Boilerplate
52 lines (41 loc) ⢠1.94 kB
JavaScript
import fs from 'fs-extra';
import inquirer from 'inquirer';
import path from 'path';
import { fileURLToPath } from 'url';
import { execSync } from 'child_process';
import chalk from 'chalk';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
(async () => {
console.log(chalk.cyan.bold("\nš Welcome to MERN Auth Stack Boilerplate!\n"));
console.log(chalk.cyan("š Made with ā¤ļø by Jaivardhan Singh"));
console.log(chalk.cyan("š GitHub: ") + chalk.underline.blue("https://github.com/Jaivardhan7773\n"));
const { projectName } = await inquirer.prompt([
{
name: "projectName",
type: "input",
message: "Enter your project folder name:",
validate: input => input ? true : "Project name cannot be empty!"
}
]);
const targetPath = path.join(process.cwd(), projectName);
const sourcePath = path.join(__dirname, "template");
const frontendPath = path.join(targetPath, 'FRONTEND');
const backendPath = path.join(targetPath, 'SERVER');
try {
console.log(chalk.yellow("š Copying files..."));
await fs.copy(sourcePath, targetPath);
console.log(chalk.green("ā
Files copied successfully!\n"));
console.log(chalk.yellow("š¦ Installing dependencies... (this might take a minute)\n"));
console.log(chalk.blue("š¦ Installing dependencies for frontend..."));
execSync('npm install', { cwd: frontendPath, stdio: 'inherit' });
console.log(chalk.blue("\nš¦ Installing dependencies for backend..."));
execSync('npm install', { cwd: backendPath, stdio: 'inherit' });
console.log(chalk.green.bold("\nā
Project setup complete!"));
console.log(chalk.cyan(`\nš cd ${projectName}`));
console.log(chalk.cyan("š npm run dev"));
} catch (err) {
console.error(chalk.red("ā Failed to scaffold project:"), err);
}
})();