|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# 🚀 PDAAS One-Click Setup Script |
| 4 | +# This script will install Node.js, Yarn, dependencies, and get you ready to dev! |
| 5 | + |
| 6 | +set -e # Exit on any error |
| 7 | + |
| 8 | +echo "🌟 Welcome to PDAAS Setup!" |
| 9 | +echo "================================" |
| 10 | +echo "" |
| 11 | + |
| 12 | +# Colors for output |
| 13 | +RED='\033[0;31m' |
| 14 | +GREEN='\033[0;32m' |
| 15 | +YELLOW='\033[1;33m' |
| 16 | +NC='\033[0m' # No Color |
| 17 | + |
| 18 | +# Function to print colored output |
| 19 | +print_success() { |
| 20 | + echo -e "${GREEN}✓${NC} $1" |
| 21 | +} |
| 22 | + |
| 23 | +print_error() { |
| 24 | + echo -e "${RED}✗${NC} $1" |
| 25 | +} |
| 26 | + |
| 27 | +print_info() { |
| 28 | + echo -e "${YELLOW}→${NC} $1" |
| 29 | +} |
| 30 | + |
| 31 | +# Check if Node.js 20 is installed |
| 32 | +print_info "Checking Node.js version..." |
| 33 | +if command -v node &> /dev/null; then |
| 34 | + NODE_VERSION=$(node -v | cut -d'v' -f2 | cut -d'.' -f1) |
| 35 | + if [ "$NODE_VERSION" -ge 20 ] && [ "$NODE_VERSION" -lt 23 ]; then |
| 36 | + print_success "Node.js $(node -v) is installed and compatible!" |
| 37 | + else |
| 38 | + print_error "Node.js version $(node -v) found, but we need v20.x" |
| 39 | + print_info "Installing Node.js 20..." |
| 40 | + |
| 41 | + # Try to install via nvm if available |
| 42 | + if command -v nvm &> /dev/null; then |
| 43 | + nvm install 20 |
| 44 | + nvm use 20 |
| 45 | + print_success "Node.js 20 installed via nvm!" |
| 46 | + else |
| 47 | + print_error "Please install Node.js 20 manually from https://nodejs.org/" |
| 48 | + print_info "Or install nvm first: curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash" |
| 49 | + exit 1 |
| 50 | + fi |
| 51 | + fi |
| 52 | +else |
| 53 | + print_error "Node.js is not installed" |
| 54 | + |
| 55 | + # Try to install via nvm if available |
| 56 | + if [ -f "$HOME/.nvm/nvm.sh" ]; then |
| 57 | + print_info "Found nvm, installing Node.js 20..." |
| 58 | + source "$HOME/.nvm/nvm.sh" |
| 59 | + nvm install 20 |
| 60 | + nvm use 20 |
| 61 | + print_success "Node.js 20 installed via nvm!" |
| 62 | + else |
| 63 | + print_error "Please install Node.js 20 first!" |
| 64 | + print_info "Easiest way: Install nvm and run this script again" |
| 65 | + print_info "curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash" |
| 66 | + print_info "Then restart your terminal and run this script again" |
| 67 | + exit 1 |
| 68 | + fi |
| 69 | +fi |
| 70 | + |
| 71 | +# Check if Yarn is installed |
| 72 | +print_info "Checking Yarn installation..." |
| 73 | +if command -v yarn &> /dev/null; then |
| 74 | + YARN_VERSION=$(yarn --version | cut -d'.' -f1) |
| 75 | + if [ "$YARN_VERSION" -eq 1 ]; then |
| 76 | + print_success "Yarn Classic $(yarn --version) is installed!" |
| 77 | + else |
| 78 | + print_info "Found Yarn $YARN_VERSION but we need Yarn Classic (v1)" |
| 79 | + print_info "Installing Yarn Classic via Corepack..." |
| 80 | + corepack enable |
| 81 | + corepack prepare yarn@1.22.22 --activate |
| 82 | + print_success "Yarn Classic installed!" |
| 83 | + fi |
| 84 | +else |
| 85 | + print_info "Installing Yarn Classic..." |
| 86 | + if command -v corepack &> /dev/null; then |
| 87 | + corepack enable |
| 88 | + corepack prepare yarn@1.22.22 --activate |
| 89 | + print_success "Yarn Classic installed via Corepack!" |
| 90 | + else |
| 91 | + print_info "Corepack not available, using npm..." |
| 92 | + npm install -g yarn@1.22.22 |
| 93 | + print_success "Yarn Classic installed via npm!" |
| 94 | + fi |
| 95 | +fi |
| 96 | + |
| 97 | +# Create .env file if it doesn't exist |
| 98 | +print_info "Setting up environment variables..." |
| 99 | +if [ ! -f .env ]; then |
| 100 | + cp .env.example .env |
| 101 | + print_success "Created .env file from .env.example" |
| 102 | + print_info "You can customize .env later if needed" |
| 103 | +else |
| 104 | + print_success ".env file already exists" |
| 105 | +fi |
| 106 | + |
| 107 | +# Install dependencies |
| 108 | +print_info "Installing project dependencies (this may take a few minutes)..." |
| 109 | +yarn install |
| 110 | + |
| 111 | +print_success "Dependencies installed!" |
| 112 | + |
| 113 | +echo "" |
| 114 | +echo "================================" |
| 115 | +echo -e "${GREEN}🎉 Setup Complete!${NC}" |
| 116 | +echo "================================" |
| 117 | +echo "" |
| 118 | +echo "You're all set! To start developing:" |
| 119 | +echo "" |
| 120 | +echo -e " ${YELLOW}yarn dev${NC}" |
| 121 | +echo "" |
| 122 | +echo "The app will be available at:" |
| 123 | +echo -e " ${YELLOW}http://127.0.0.1:3000${NC}" |
| 124 | +echo "" |
| 125 | +echo "Happy coding! 🚀" |
| 126 | +echo "" |
| 127 | + |
0 commit comments