-
-
Notifications
You must be signed in to change notification settings - Fork 636
Expand file tree
/
Copy pathconductor-setup.sh
More file actions
executable file
·153 lines (133 loc) · 5.16 KB
/
conductor-setup.sh
File metadata and controls
executable file
·153 lines (133 loc) · 5.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/bin/zsh
set -e
echo "🚀 Setting up React on Rails workspace..."
# Detect and initialize version manager
# Supports: mise, asdf, or direct PATH (rbenv/nvm/nodenv already in PATH)
VERSION_MANAGER="none"
echo "📋 Detecting version manager..."
if command -v mise &> /dev/null; then
VERSION_MANAGER="mise"
echo "✅ Found mise"
# Trust mise config for current directory only and install tools
mise trust 2>/dev/null || true
mise install
elif [[ -f ~/.asdf/asdf.sh ]]; then
VERSION_MANAGER="asdf"
source ~/.asdf/asdf.sh
echo "✅ Found asdf (from ~/.asdf/asdf.sh)"
elif command -v asdf &> /dev/null; then
VERSION_MANAGER="asdf"
# For homebrew-installed asdf
if [[ -f /opt/homebrew/opt/asdf/libexec/asdf.sh ]]; then
source /opt/homebrew/opt/asdf/libexec/asdf.sh
fi
echo "✅ Found asdf"
else
echo "ℹ️ No version manager detected, using system PATH"
echo " (Assuming rbenv/nvm/nodenv or system tools are already configured)"
fi
# Helper function to run commands with the detected version manager
run_cmd() {
if [[ "$VERSION_MANAGER" == "mise" ]] && [[ -x "bin/conductor-exec" ]]; then
bin/conductor-exec "$@"
else
"$@"
fi
}
# Check required tools
echo "📋 Checking required tools..."
run_cmd ruby --version >/dev/null 2>&1 || { echo "❌ Error: Ruby is not installed or not in PATH."; exit 1; }
run_cmd node --version >/dev/null 2>&1 || { echo "❌ Error: Node.js is not installed or not in PATH."; exit 1; }
# Check Ruby version
RUBY_VERSION=$(run_cmd ruby -v | awk '{print $2}')
MIN_RUBY_VERSION="3.0.0"
if [[ $(echo -e "$MIN_RUBY_VERSION\n$RUBY_VERSION" | sort -V | head -n1) != "$MIN_RUBY_VERSION" ]]; then
echo "❌ Error: Ruby version $RUBY_VERSION is too old. React on Rails requires Ruby >= 3.0.0"
echo " Please upgrade Ruby using your version manager or system package manager."
exit 1
fi
echo "✅ Ruby version: $RUBY_VERSION"
# Check Node version
NODE_VERSION=$(run_cmd node -v | cut -d'v' -f2)
MIN_NODE_VERSION="20.0.0"
if [[ $(echo -e "$MIN_NODE_VERSION\n$NODE_VERSION" | sort -V | head -n1) != "$MIN_NODE_VERSION" ]]; then
echo "❌ Error: Node.js version v$NODE_VERSION is too old. React on Rails requires Node.js >= 20.0.0"
echo " Please upgrade Node.js using your version manager or system package manager."
exit 1
fi
echo "✅ Node.js version: v$NODE_VERSION"
# Copy any environment files from root if they exist
if [ -n "$CONDUCTOR_ROOT_PATH" ]; then
if [ -f "$CONDUCTOR_ROOT_PATH/.env" ]; then
cp "$CONDUCTOR_ROOT_PATH/.env" .env
fi
if [ -f "$CONDUCTOR_ROOT_PATH/.env.local" ]; then
cp "$CONDUCTOR_ROOT_PATH/.env.local" .env.local
fi
fi
# Install the bundler version each lockfile expects so that `bundle install`
# does not re-resolve platform gems (e.g., sqlite3 native vs source).
# Lockfiles record BUNDLED WITH <version>; a different major (4.x vs 2.x)
# can silently rewrite platform resolution.
install_matching_bundler() {
local lockfile="$1"
if [[ -f "$lockfile" ]]; then
local v
v=$(grep -A1 "BUNDLED WITH" "$lockfile" | tail -1 | tr -d ' ')
if [[ -n "$v" ]]; then
if ! run_cmd gem list bundler -i -v "$v" > /dev/null 2>&1; then
echo " Installing bundler $v (expected by $lockfile)..."
run_cmd gem install bundler -v "$v" --no-document
fi
fi
fi
}
LOCKFILE_DIRS=(
"."
"react_on_rails/spec/dummy"
"react_on_rails_pro"
"react_on_rails_pro/spec/dummy"
)
echo "💎 Ensuring matching bundler versions..."
for dir in "${LOCKFILE_DIRS[@]}"; do
install_matching_bundler "$dir/Gemfile.lock"
done
echo "💎 Installing Ruby dependencies..."
for dir in "${LOCKFILE_DIRS[@]}"; do
echo " $dir ..."
pushd "$dir" > /dev/null
run_cmd bundle install
popd > /dev/null
done
# Enable corepack for pnpm (this project uses pnpm, not yarn)
echo "📦 Enabling corepack for pnpm..."
run_cmd corepack enable
# Install JavaScript dependencies
echo "📦 Installing JavaScript dependencies..."
run_cmd pnpm install
# Build TypeScript (required for tests)
echo "🔨 Building TypeScript package..."
run_cmd pnpm run build
# Generate the node package
echo "📦 Generating node package..."
run_cmd rake node_package
# Install git hooks for linting
echo "🪝 Installing git hooks..."
run_cmd bundle exec lefthook install || echo "⚠️ Could not install lefthook hooks"
# Run initial linting to ensure everything is set up correctly
echo "✅ Running initial linting checks..."
run_cmd bundle exec rubocop --version
run_cmd pnpm run type-check || echo "⚠️ Type checking had issues"
echo "✨ Workspace setup complete!"
echo ""
echo "📚 Key commands:"
echo " • rake - Run all tests and linting"
echo " • rake run_rspec - Run Ruby tests"
echo " • pnpm run test - Run JavaScript tests"
echo " • bundle exec rubocop - Run Ruby linting (required before commits)"
echo " • rake autofix - Auto-fix formatting issues"
echo ""
if [[ "$VERSION_MANAGER" == "mise" ]]; then
echo "💡 Tip: Use 'bin/conductor-exec <command>' if tool versions aren't detected correctly."
fi
echo "⚠️ Remember: Always run 'bundle exec rubocop' before committing!"