|
1 | | -#!/bin/bash |
| 1 | +#!/bin/zsh |
2 | 2 | set -e |
3 | 3 |
|
4 | 4 | echo "🚀 Setting up React on Rails workspace..." |
5 | 5 |
|
| 6 | +# Detect and initialize version manager |
| 7 | +# Supports: mise, asdf, or direct PATH (rbenv/nvm/nodenv already in PATH) |
| 8 | +VERSION_MANAGER="none" |
| 9 | + |
| 10 | +echo "📋 Detecting version manager..." |
| 11 | + |
| 12 | +if command -v mise &> /dev/null; then |
| 13 | + VERSION_MANAGER="mise" |
| 14 | + echo "✅ Found mise" |
| 15 | + # Trust mise config for current directory only and install tools |
| 16 | + mise trust 2>/dev/null || true |
| 17 | + mise install |
| 18 | +elif [[ -f ~/.asdf/asdf.sh ]]; then |
| 19 | + VERSION_MANAGER="asdf" |
| 20 | + source ~/.asdf/asdf.sh |
| 21 | + echo "✅ Found asdf (from ~/.asdf/asdf.sh)" |
| 22 | +elif command -v asdf &> /dev/null; then |
| 23 | + VERSION_MANAGER="asdf" |
| 24 | + # For homebrew-installed asdf |
| 25 | + if [[ -f /opt/homebrew/opt/asdf/libexec/asdf.sh ]]; then |
| 26 | + source /opt/homebrew/opt/asdf/libexec/asdf.sh |
| 27 | + fi |
| 28 | + echo "✅ Found asdf" |
| 29 | +else |
| 30 | + echo "ℹ️ No version manager detected, using system PATH" |
| 31 | + echo " (Assuming rbenv/nvm/nodenv or system tools are already configured)" |
| 32 | +fi |
| 33 | + |
| 34 | +# Helper function to run commands with the detected version manager |
| 35 | +run_cmd() { |
| 36 | + if [[ "$VERSION_MANAGER" == "mise" ]] && [[ -x "bin/conductor-exec" ]]; then |
| 37 | + bin/conductor-exec "$@" |
| 38 | + else |
| 39 | + "$@" |
| 40 | + fi |
| 41 | +} |
| 42 | + |
6 | 43 | # Note: This project requires Ruby 3.4.6. |
7 | 44 | # Please ensure you have the correct Ruby version active before running this script. |
8 | 45 |
|
| 46 | +# Check required tools |
| 47 | +echo "📋 Checking required tools..." |
| 48 | +run_cmd ruby --version >/dev/null 2>&1 || { echo "❌ Error: Ruby is not installed or not in PATH."; exit 1; } |
| 49 | +run_cmd node --version >/dev/null 2>&1 || { echo "❌ Error: Node.js is not installed or not in PATH."; exit 1; } |
| 50 | + |
| 51 | +# Check Ruby version |
| 52 | +RUBY_VERSION=$(run_cmd ruby -v | awk '{print $2}') |
| 53 | +MIN_RUBY_VERSION="3.0.0" |
| 54 | +if [[ $(echo -e "$MIN_RUBY_VERSION\n$RUBY_VERSION" | sort -V | head -n1) != "$MIN_RUBY_VERSION" ]]; then |
| 55 | + echo "❌ Error: Ruby version $RUBY_VERSION is too old. This project requires Ruby >= 3.0.0" |
| 56 | + echo " Please upgrade Ruby using your version manager or system package manager." |
| 57 | + exit 1 |
| 58 | +fi |
| 59 | +echo "✅ Ruby version: $RUBY_VERSION" |
| 60 | + |
| 61 | +# Check Node version |
| 62 | +NODE_VERSION=$(run_cmd node -v | cut -d'v' -f2) |
| 63 | +MIN_NODE_VERSION="20.0.0" |
| 64 | +if [[ $(echo -e "$MIN_NODE_VERSION\n$NODE_VERSION" | sort -V | head -n1) != "$MIN_NODE_VERSION" ]]; then |
| 65 | + echo "❌ Error: Node.js version v$NODE_VERSION is too old. This project requires Node.js >= 20.0.0" |
| 66 | + echo " Please upgrade Node.js using your version manager or system package manager." |
| 67 | + exit 1 |
| 68 | +fi |
| 69 | +echo "✅ Node.js version: v$NODE_VERSION" |
| 70 | + |
9 | 71 | # Copy environment files if they exist in the root |
10 | | -if [ -f "$CONDUCTOR_ROOT_PATH/.env" ]; then |
| 72 | +if [[ -f "$CONDUCTOR_ROOT_PATH/.env" ]]; then |
11 | 73 | cp "$CONDUCTOR_ROOT_PATH/.env" .env |
12 | 74 | echo "✅ Copied .env file from root" |
13 | | -elif [ -f "$CONDUCTOR_ROOT_PATH/.env.example" ]; then |
| 75 | +elif [[ -f "$CONDUCTOR_ROOT_PATH/.env.example" ]]; then |
14 | 76 | cp "$CONDUCTOR_ROOT_PATH/.env.example" .env |
15 | 77 | echo "✅ Copied .env.example to .env" |
16 | 78 | fi |
17 | 79 |
|
18 | | -if [ -f "$CONDUCTOR_ROOT_PATH/config/database.yml" ]; then |
| 80 | +if [[ -f "$CONDUCTOR_ROOT_PATH/.env.local" ]]; then |
| 81 | + cp "$CONDUCTOR_ROOT_PATH/.env.local" .env.local |
| 82 | + echo "✅ Copied .env.local file from root" |
| 83 | +fi |
| 84 | + |
| 85 | +if [[ -f "$CONDUCTOR_ROOT_PATH/config/database.yml" ]]; then |
19 | 86 | cp "$CONDUCTOR_ROOT_PATH/config/database.yml" config/database.yml |
20 | 87 | echo "✅ Copied database.yml from root" |
21 | | -elif [ -f "config/database.yml.example" ]; then |
| 88 | +elif [[ -f "config/database.yml.example" ]]; then |
22 | 89 | cp config/database.yml.example config/database.yml |
23 | 90 | echo "✅ Copied database.yml.example to database.yml" |
24 | 91 | fi |
25 | 92 |
|
26 | 93 | # Run the standard Rails setup script |
27 | 94 | echo "🔧 Running Rails setup script..." |
28 | | -bin/setup --skip-server |
| 95 | +run_cmd bin/setup --skip-server |
29 | 96 |
|
30 | | -echo "✨ Setup complete! You can now run the development server." |
| 97 | +echo "✨ Setup complete!" |
| 98 | +echo "" |
| 99 | +echo "📚 Key commands:" |
| 100 | +echo " • bin/dev - Start development server" |
| 101 | +echo " • bundle exec rspec - Run tests" |
| 102 | +echo " • bundle exec rubocop - Run Ruby linting" |
| 103 | +echo "" |
| 104 | +if [[ "$VERSION_MANAGER" == "mise" ]]; then |
| 105 | + echo "💡 Tip: Use 'bin/conductor-exec <command>' if tool versions aren't detected correctly." |
| 106 | +fi |
| 107 | +echo "⚠️ Remember: Always run 'bundle exec rubocop' before committing!" |
0 commit comments