update
This commit is contained in:
88
scripts/dev-minimal.js
Normal file
88
scripts/dev-minimal.js
Normal file
@@ -0,0 +1,88 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const { spawn, exec } = require('child_process');
|
||||
const os = require('os');
|
||||
const isWindows = process.platform === 'win32';
|
||||
|
||||
console.log('🚀 Starting minimal development environment...');
|
||||
|
||||
// Detect architecture
|
||||
const arch = os.arch();
|
||||
const isAppleSilicon = arch === 'arm64' && process.platform === 'darwin';
|
||||
|
||||
console.log(`🖥️ Detected architecture: ${arch}`);
|
||||
console.log(`🍎 Apple Silicon: ${isAppleSilicon ? 'Yes' : 'No'}`);
|
||||
|
||||
// Use minimal compose file (only PostgreSQL and Redis)
|
||||
const composeFile = 'docker-compose.dev.minimal.yml';
|
||||
console.log(`📦 Using minimal Docker Compose file: ${composeFile}`);
|
||||
|
||||
// Check if docker-compose is available
|
||||
exec('docker-compose --version', (error) => {
|
||||
if (error) {
|
||||
console.error('❌ docker-compose not found');
|
||||
console.error('💡 Please install Docker Desktop or use: npm run dev:simple');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log('✅ docker-compose found, starting services...');
|
||||
|
||||
// Start Docker services
|
||||
const dockerProcess = spawn('docker-compose', ['-f', composeFile, 'up', '-d'], {
|
||||
stdio: 'inherit',
|
||||
shell: isWindows
|
||||
});
|
||||
|
||||
dockerProcess.on('close', (code) => {
|
||||
if (code === 0) {
|
||||
console.log('✅ Docker services started');
|
||||
console.log('🗄️ PostgreSQL: localhost:5432');
|
||||
console.log('📦 Redis: localhost:6379');
|
||||
console.log('📧 Note: Mailhog not included (use npm run dev:simple for email testing)');
|
||||
|
||||
// Wait a bit for services to be ready
|
||||
setTimeout(() => {
|
||||
console.log('🚀 Starting Next.js development server...');
|
||||
|
||||
// Start Next.js dev server
|
||||
const nextProcess = spawn('npm', ['run', 'dev:next'], {
|
||||
stdio: 'inherit',
|
||||
shell: isWindows,
|
||||
env: {
|
||||
...process.env,
|
||||
DATABASE_URL: 'postgresql://portfolio_user:portfolio_dev_pass@localhost:5432/portfolio_dev?schema=public',
|
||||
REDIS_URL: 'redis://localhost:6379',
|
||||
NODE_ENV: 'development'
|
||||
}
|
||||
});
|
||||
|
||||
nextProcess.on('close', (code) => {
|
||||
console.log(`Next.js dev server exited with code ${code}`);
|
||||
});
|
||||
|
||||
// Handle process signals
|
||||
process.on('SIGINT', () => {
|
||||
console.log('\n🛑 Stopping development environment...');
|
||||
nextProcess.kill('SIGTERM');
|
||||
|
||||
// Stop Docker services
|
||||
const stopProcess = spawn('docker-compose', ['-f', composeFile, 'down'], {
|
||||
stdio: 'inherit',
|
||||
shell: isWindows
|
||||
});
|
||||
|
||||
stopProcess.on('close', () => {
|
||||
console.log('✅ Development environment stopped');
|
||||
process.exit(0);
|
||||
});
|
||||
});
|
||||
|
||||
}, 5000); // Wait 5 seconds for services to be ready
|
||||
|
||||
} else {
|
||||
console.error('❌ Failed to start Docker services');
|
||||
console.error('💡 Try using: npm run dev:simple');
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
});
|
||||
40
scripts/dev-simple.js
Normal file
40
scripts/dev-simple.js
Normal file
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const { spawn } = require('child_process');
|
||||
const isWindows = process.platform === 'win32';
|
||||
|
||||
console.log('🚀 Starting Next.js development server...');
|
||||
console.log('📝 Note: This is a simplified dev mode without Docker services');
|
||||
console.log('💡 For full development environment with DB, use: npm run dev:full');
|
||||
|
||||
// Set development environment variables
|
||||
const env = {
|
||||
...process.env,
|
||||
NODE_ENV: 'development',
|
||||
DATABASE_URL: 'postgresql://portfolio_user:portfolio_dev_pass@localhost:5432/portfolio_dev?schema=public',
|
||||
REDIS_URL: 'redis://localhost:6379',
|
||||
NEXT_PUBLIC_BASE_URL: 'http://localhost:3000'
|
||||
};
|
||||
|
||||
// Start Next.js dev server
|
||||
const nextProcess = spawn('npm', ['run', 'dev:next'], {
|
||||
stdio: 'inherit',
|
||||
shell: isWindows,
|
||||
env
|
||||
});
|
||||
|
||||
nextProcess.on('close', (code) => {
|
||||
console.log(`Next.js dev server exited with code ${code}`);
|
||||
});
|
||||
|
||||
// Handle process signals
|
||||
process.on('SIGINT', () => {
|
||||
console.log('\n🛑 Stopping development server...');
|
||||
nextProcess.kill('SIGTERM');
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
process.on('SIGTERM', () => {
|
||||
nextProcess.kill('SIGTERM');
|
||||
process.exit(0);
|
||||
});
|
||||
23
scripts/init-db.sql
Normal file
23
scripts/init-db.sql
Normal file
@@ -0,0 +1,23 @@
|
||||
-- Initialize database for development
|
||||
-- This script runs when the PostgreSQL container starts
|
||||
|
||||
-- Create database if it doesn't exist (this is handled by POSTGRES_DB env var)
|
||||
-- The database 'portfolio_dev' is created automatically
|
||||
|
||||
-- Create user if it doesn't exist (this is handled by POSTGRES_USER env var)
|
||||
-- The user 'portfolio_user' is created automatically
|
||||
|
||||
-- Grant permissions
|
||||
GRANT ALL PRIVILEGES ON DATABASE portfolio_dev TO portfolio_user;
|
||||
|
||||
-- Create schema if it doesn't exist
|
||||
CREATE SCHEMA IF NOT EXISTS public;
|
||||
|
||||
-- Grant schema permissions
|
||||
GRANT ALL ON SCHEMA public TO portfolio_user;
|
||||
GRANT ALL ON ALL TABLES IN SCHEMA public TO portfolio_user;
|
||||
GRANT ALL ON ALL SEQUENCES IN SCHEMA public TO portfolio_user;
|
||||
|
||||
-- Set default privileges for future tables
|
||||
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO portfolio_user;
|
||||
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON SEQUENCES TO portfolio_user;
|
||||
97
scripts/pre-push-quick.sh
Executable file
97
scripts/pre-push-quick.sh
Executable file
@@ -0,0 +1,97 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Quick Pre-Push Hook Script
|
||||
# Minimal checks for quick fixes and small changes
|
||||
# Use this for: styling, text changes, minor bug fixes
|
||||
|
||||
set -e # Exit on any error
|
||||
|
||||
echo "⚡ Running QUICK Pre-Push Checks..."
|
||||
echo "==================================="
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Function to print colored output
|
||||
print_status() {
|
||||
echo -e "${BLUE}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
print_success() {
|
||||
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
# Check if we're in a git repository
|
||||
if ! git rev-parse --git-dir > /dev/null 2>&1; then
|
||||
print_error "Not in a git repository!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get current branch
|
||||
CURRENT_BRANCH=$(git branch --show-current)
|
||||
print_status "Current branch: $CURRENT_BRANCH"
|
||||
|
||||
# Check if there are uncommitted changes
|
||||
if ! git diff-index --quiet HEAD --; then
|
||||
print_error "You have uncommitted changes. Please commit or stash them first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 1. Quick ESLint check (only on changed files)
|
||||
print_status "Running ESLint on changed files..."
|
||||
CHANGED_FILES=$(git diff --name-only --cached | grep -E '\.(ts|tsx|js|jsx)$' || true)
|
||||
if [ -n "$CHANGED_FILES" ]; then
|
||||
if ! npx eslint $CHANGED_FILES; then
|
||||
print_error "ESLint failed on changed files! Please fix the errors."
|
||||
exit 1
|
||||
fi
|
||||
print_success "ESLint passed on changed files"
|
||||
else
|
||||
print_status "No TypeScript/JavaScript files changed, skipping ESLint"
|
||||
fi
|
||||
|
||||
# 2. Quick Type Check (only on changed files)
|
||||
print_status "Running TypeScript type check on changed files..."
|
||||
if [ -n "$CHANGED_FILES" ]; then
|
||||
if ! npx tsc --noEmit --skipLibCheck; then
|
||||
print_error "TypeScript type check failed!"
|
||||
exit 1
|
||||
fi
|
||||
print_success "TypeScript type check passed"
|
||||
else
|
||||
print_status "No TypeScript files changed, skipping type check"
|
||||
fi
|
||||
|
||||
# 3. Check for obvious syntax errors (very fast)
|
||||
print_status "Checking for syntax errors..."
|
||||
if ! node -c package.json 2>/dev/null; then
|
||||
print_error "Package.json syntax error!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "==================================="
|
||||
print_success "Quick pre-push checks passed! ⚡"
|
||||
print_status "Ready to push to $CURRENT_BRANCH"
|
||||
print_warning "Note: Full tests and build will run in CI/CD"
|
||||
echo "==================================="
|
||||
|
||||
# Show what will be pushed
|
||||
echo ""
|
||||
print_status "Files to be pushed:"
|
||||
git diff --name-only origin/$CURRENT_BRANCH..HEAD 2>/dev/null || git diff --name-only HEAD~1..HEAD
|
||||
|
||||
echo ""
|
||||
print_status "Proceeding with quick push..."
|
||||
52
scripts/setup-database.js
Normal file
52
scripts/setup-database.js
Normal file
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const { exec } = require('child_process');
|
||||
const path = require('path');
|
||||
|
||||
console.log('🗄️ Setting up database...');
|
||||
|
||||
// Set environment variables for development
|
||||
process.env.DATABASE_URL = 'postgresql://portfolio_user:portfolio_dev_pass@localhost:5432/portfolio_dev?schema=public';
|
||||
|
||||
// Function to run command and return promise
|
||||
function runCommand(command) {
|
||||
return new Promise((resolve, reject) => {
|
||||
console.log(`Running: ${command}`);
|
||||
exec(command, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
console.error(`Error: ${error.message}`);
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
if (stderr) {
|
||||
console.log(`Stderr: ${stderr}`);
|
||||
}
|
||||
console.log(`Output: ${stdout}`);
|
||||
resolve(stdout);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function setupDatabase() {
|
||||
try {
|
||||
console.log('📦 Generating Prisma client...');
|
||||
await runCommand('npx prisma generate');
|
||||
|
||||
console.log('🔄 Pushing database schema...');
|
||||
await runCommand('npx prisma db push');
|
||||
|
||||
console.log('🌱 Seeding database...');
|
||||
await runCommand('npx prisma db seed');
|
||||
|
||||
console.log('✅ Database setup complete!');
|
||||
console.log('🚀 You can now run: npm run dev');
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Database setup failed:', error.message);
|
||||
console.log('💡 Make sure PostgreSQL is running on localhost:5432');
|
||||
console.log('💡 Try: docker-compose -f docker-compose.dev.minimal.yml up -d');
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
setupDatabase();
|
||||
@@ -1,105 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "🚀 Setting up local PostgreSQL database for Portfolio..."
|
||||
|
||||
# Check if PostgreSQL is installed
|
||||
if ! command -v psql &> /dev/null; then
|
||||
echo "📦 PostgreSQL not found. Installing..."
|
||||
|
||||
# Detect OS and install PostgreSQL
|
||||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||
# Ubuntu/Debian
|
||||
if command -v apt-get &> /dev/null; then
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y postgresql postgresql-contrib
|
||||
# CentOS/RHEL
|
||||
elif command -v yum &> /dev/null; then
|
||||
sudo yum install -y postgresql postgresql-server postgresql-contrib
|
||||
sudo postgresql-setup initdb
|
||||
sudo systemctl enable postgresql
|
||||
sudo systemctl start postgresql
|
||||
# Arch Linux
|
||||
elif command -v pacman &> /dev/null; then
|
||||
sudo pacman -S postgresql
|
||||
sudo -u postgres initdb -D /var/lib/postgres/data
|
||||
sudo systemctl enable postgresql
|
||||
sudo systemctl start postgresql
|
||||
else
|
||||
echo "❌ Unsupported Linux distribution. Please install PostgreSQL manually."
|
||||
exit 1
|
||||
fi
|
||||
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
# macOS
|
||||
if command -v brew &> /dev/null; then
|
||||
brew install postgresql
|
||||
brew services start postgresql
|
||||
else
|
||||
echo "❌ Homebrew not found. Please install Homebrew first: https://brew.sh/"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "❌ Unsupported OS. Please install PostgreSQL manually."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "✅ PostgreSQL already installed"
|
||||
fi
|
||||
|
||||
# Start PostgreSQL service
|
||||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||
sudo systemctl start postgresql
|
||||
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
brew services start postgresql
|
||||
fi
|
||||
|
||||
# Create database and user
|
||||
echo "🔧 Setting up database..."
|
||||
sudo -u postgres psql -c "CREATE DATABASE portfolio_db;" 2>/dev/null || echo "Database already exists"
|
||||
sudo -u postgres psql -c "CREATE USER portfolio_user WITH PASSWORD 'portfolio_pass';" 2>/dev/null || echo "User already exists"
|
||||
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE portfolio_db TO portfolio_user;" 2>/dev/null || echo "Privileges already granted"
|
||||
sudo -u postgres psql -c "ALTER USER portfolio_user WITH SUPERUSER;" 2>/dev/null || echo "Superuser already granted"
|
||||
|
||||
# Create .env.local file
|
||||
echo "📝 Creating environment file..."
|
||||
cat > .env.local << EOF
|
||||
# Database Configuration
|
||||
DATABASE_URL="postgresql://portfolio_user:portfolio_pass@localhost:5432/portfolio_db?schema=public"
|
||||
|
||||
# Next.js Configuration
|
||||
NEXTAUTH_SECRET="$(openssl rand -base64 32)"
|
||||
NEXTAUTH_URL="http://localhost:3000"
|
||||
|
||||
# Optional: Analytics
|
||||
GOOGLE_ANALYTICS_ID=""
|
||||
GOOGLE_TAG_MANAGER_ID=""
|
||||
EOF
|
||||
|
||||
echo "✅ Environment file created: .env.local"
|
||||
|
||||
# Install dependencies
|
||||
echo "📦 Installing dependencies..."
|
||||
npm install
|
||||
|
||||
# Generate Prisma client
|
||||
echo "🔧 Generating Prisma client..."
|
||||
npx prisma generate
|
||||
|
||||
# Run database migrations
|
||||
echo "🗄️ Running database migrations..."
|
||||
npx prisma db push
|
||||
|
||||
# Seed database with sample data
|
||||
echo "🌱 Seeding database with sample data..."
|
||||
npx prisma db seed
|
||||
|
||||
echo "🎉 Database setup complete!"
|
||||
echo ""
|
||||
echo "📋 Next steps:"
|
||||
echo "1. Start your development server: npm run dev"
|
||||
echo "2. Visit http://localhost:3000/admin to manage projects"
|
||||
echo "3. Your database is running at localhost:5432"
|
||||
echo ""
|
||||
echo "🔧 Database commands:"
|
||||
echo "- View database: npx prisma studio"
|
||||
echo "- Reset database: npx prisma db push --force-reset"
|
||||
echo "- Generate client: npx prisma generate"
|
||||
Reference in New Issue
Block a user