#!/usr/bin/env node /** * Local Development Setup Script * * This script helps set up the local development environment * by creating the PostgreSQL database and running initial setup. */ const { execSync } = require('child_process'); const fs = require('fs'); const path = require('path'); console.log('šŸš€ Setting up Vaishnavi Creation Backend for local development...\n'); // Check if .env file exists const envPath = path.join(__dirname, '.env'); const envExamplePath = path.join(__dirname, '.env.example'); if (!fs.existsSync(envPath)) { if (fs.existsSync(envExamplePath)) { console.log('šŸ“ Creating .env file from .env.example...'); fs.copyFileSync(envExamplePath, envPath); console.log('āœ… .env file created! Please update it with your database credentials.\n'); } else { console.log('āŒ .env.example file not found. Please create a .env file manually.\n'); process.exit(1); } } // Check Node.js version const nodeVersion = process.version; const majorVersion = parseInt(nodeVersion.slice(1).split('.')[0]); if (majorVersion < 18) { console.log('āŒ Node.js 18+ is required. Current version:', nodeVersion); process.exit(1); } console.log('āœ… Node.js version check passed:', nodeVersion); // Install dependencies console.log('\nšŸ“¦ Installing dependencies...'); try { execSync('npm install', { stdio: 'inherit' }); console.log('āœ… Dependencies installed successfully!'); } catch (error) { console.log('āŒ Failed to install dependencies:', error.message); process.exit(1); } // Generate Prisma client console.log('\nšŸ”§ Generating Prisma client...'); try { execSync('npx prisma generate', { stdio: 'inherit' }); console.log('āœ… Prisma client generated successfully!'); } catch (error) { console.log('āŒ Failed to generate Prisma client:', error.message); console.log('šŸ’” Make sure your PostgreSQL database is running and the DATABASE_URL in .env is correct.'); process.exit(1); } // Test database connection and run migrations console.log('\nšŸ—„ļø Setting up database...'); try { execSync('npx prisma db push', { stdio: 'inherit' }); console.log('āœ… Database schema created successfully!'); } catch (error) { console.log('āŒ Failed to create database schema:', error.message); console.log('šŸ’” Please check:'); console.log(' - PostgreSQL is running'); console.log(' - Database "vaishnavi_db" exists'); console.log(' - DATABASE_URL in .env is correct'); console.log(' - User has proper permissions'); process.exit(1); } // Seed database console.log('\n🌱 Seeding database...'); try { execSync('npm run db:seed', { stdio: 'inherit' }); console.log('āœ… Database seeded successfully!'); } catch (error) { console.log('āš ļø Failed to seed database:', error.message); console.log('šŸ’” You can run "npm run db:seed" manually later.'); } console.log('\nšŸŽ‰ Setup completed successfully!'); console.log('\nšŸ“‹ Next steps:'); console.log('1. Make sure MongoDB is running on port 27017'); console.log('2. Update your .env file with correct database credentials'); console.log('3. Run "npm run dev" to start the development server'); console.log('\nšŸ”— Useful commands:'); console.log('- Start dev server: npm run dev'); console.log('- View database: npm run db:studio'); console.log('- Run tests: npm test'); console.log('- Lint code: npm run lint'); console.log('\nšŸ“š API will be available at: http://localhost:3000'); console.log('šŸ„ Health check: http://localhost:3000/health'); console.log('\nšŸ‘¤ Default admin user: admin@vaishnavi.com / admin123'); console.log('šŸ‘¤ Default customer: customer@example.com / customer123');