Files
eCommerce-backend/setup-local.js
2026-02-19 17:25:38 +05:30

102 lines
3.7 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/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');