Skip to content

Commit dd6533e

Browse files
justin808claude
andcommitted
Address review comments: enhance bin/setup robustness
Key improvements based on PR review feedback: 1. Path verification: Added verify_root_directory() to check Rakefile and package.json exist before proceeding 2. Build artifact validation: Added verify_build_artifacts() to verify packages/react-on-rails/lib/ReactOnRails.full.js exists after build 3. Error handling: Improved bundle install error handling with explicit failure detection and messages 4. CI-like behavior: Use pnpm install --frozen-lockfile to match CI and ensure lockfile integrity 5. Rake error handling: Added error handling for rake node_package 6. Version display: Show Ruby, Node, pnpm, and Bundler versions during prerequisites check 7. --skip-pro flag: Added for contributors without Pro access 8. Elapsed time: Display total setup time at completion 9. Git hooks documentation: Added message about automatic git hooks installation 10. CONTRIBUTING.md: Added version verification example before setup 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 23eed32 commit dd6533e

File tree

2 files changed

+121
-19
lines changed

2 files changed

+121
-19
lines changed

CONTRIBUTING.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,18 @@ or the equivalent command for your package manager.
202202

203203
### Quick Setup (Recommended)
204204

205-
After checking out the repo and ensuring you have Ruby and Node version managers set up (such as rvm and nvm, or rbenv and nodenv, etc.), run:
205+
After checking out the repo and ensuring you have Ruby and Node version managers set up (such as rvm and nvm, or rbenv and nodenv, etc.) with the correct versions active, run:
206206

207207
```sh
208+
# First, verify your versions match the project requirements
209+
ruby -v # Should show 3.4.x or version in .ruby-version
210+
node -v # Should show 22.x or version in .node-version
211+
212+
# Then run the setup script
208213
bin/setup
214+
215+
# Or skip Pro setup (for contributors without Pro access)
216+
bin/setup --skip-pro
209217
```
210218

211219
This single command installs all dependencies across the monorepo:

bin/setup

Lines changed: 112 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
# making it easy for new contributors to get started quickly.
77
#
88
# Usage:
9-
# bin/setup # Full setup of all packages
10-
# bin/setup --help # Show this help message
9+
# bin/setup # Full setup of all packages
10+
# bin/setup --skip-pro # Skip Pro package setup
11+
# bin/setup --help # Show this help message
1112
#
1213

1314
set -e
@@ -23,22 +24,29 @@ NC='\033[0m' # No Color
2324
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
2425
ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
2526

27+
# Track start time for elapsed time display
28+
START_TIME=$(date +%s)
29+
30+
# Flags
31+
SKIP_PRO=false
32+
2633
show_help() {
2734
echo "Usage: bin/setup [OPTIONS]"
2835
echo ""
2936
echo "Sets up the React on Rails development environment by installing"
3037
echo "all dependencies across the monorepo."
3138
echo ""
3239
echo "Options:"
33-
echo " --help Show this help message"
40+
echo " --skip-pro Skip react_on_rails_pro setup (for contributors without Pro access)"
41+
echo " --help Show this help message"
3442
echo ""
3543
echo "This script will:"
3644
echo " 1. Install root pnpm and bundle dependencies"
3745
echo " 2. Build the node package"
3846
echo " 3. Set up react_on_rails/spec/dummy"
39-
echo " 4. Set up react_on_rails_pro (if present)"
40-
echo " 5. Set up react_on_rails_pro/spec/dummy (if present)"
41-
echo " 6. Set up react_on_rails_pro/spec/execjs-compatible-dummy (if present)"
47+
echo " 4. Set up react_on_rails_pro (if present and not skipped)"
48+
echo " 5. Set up react_on_rails_pro/spec/dummy (if present and not skipped)"
49+
echo " 6. Set up react_on_rails_pro/spec/execjs-compatible-dummy (if present and not skipped)"
4250
}
4351

4452
print_step() {
@@ -98,6 +106,26 @@ check_prerequisites() {
98106
done
99107
exit 1
100108
fi
109+
110+
# Display versions found
111+
echo " Ruby: $(ruby -v | head -1)"
112+
echo " Node: $(node -v)"
113+
echo " pnpm: $(pnpm -v)"
114+
echo " Bundler: $(bundle -v)"
115+
}
116+
117+
verify_root_directory() {
118+
if [ ! -f "$ROOT_DIR/Rakefile" ]; then
119+
print_error "Rakefile not found. Are you in the correct directory?"
120+
print_error "Expected location: $ROOT_DIR/Rakefile"
121+
exit 1
122+
fi
123+
124+
if [ ! -f "$ROOT_DIR/package.json" ]; then
125+
print_error "package.json not found. Are you in the correct directory?"
126+
print_error "Expected location: $ROOT_DIR/package.json"
127+
exit 1
128+
fi
101129
}
102130

103131
install_dependencies() {
@@ -118,33 +146,92 @@ install_dependencies() {
118146
if bundle check &> /dev/null; then
119147
print_success "Ruby dependencies already satisfied"
120148
else
121-
bundle install
149+
if ! bundle install; then
150+
print_error "Failed to install Ruby dependencies in $name"
151+
exit 1
152+
fi
122153
print_success "Ruby dependencies installed"
123154
fi
124155
fi
125156

126157
# Install JS dependencies if package.json exists
158+
# Use --frozen-lockfile to match CI behavior and ensure lockfile integrity
127159
if [ -f "package.json" ]; then
128160
echo " Installing JavaScript dependencies..."
129-
pnpm install
161+
if ! pnpm install --frozen-lockfile; then
162+
print_error "Failed to install JavaScript dependencies in $name"
163+
exit 1
164+
fi
130165
print_success "JavaScript dependencies installed"
131166
fi
132167

133168
cd "$ROOT_DIR"
134169
}
135170

136-
main() {
137-
# Handle --help
138-
if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
139-
show_help
140-
exit 0
171+
build_node_package() {
172+
print_step "Building node package..."
173+
if ! rake node_package; then
174+
print_error "Failed to build node package"
175+
exit 1
176+
fi
177+
print_success "Node package built"
178+
}
179+
180+
verify_build_artifacts() {
181+
print_step "Verifying build artifacts..."
182+
183+
local artifact="packages/react-on-rails/lib/ReactOnRails.full.js"
184+
if [ ! -f "$ROOT_DIR/$artifact" ]; then
185+
print_error "Build failed: $artifact not found"
186+
print_error "Expected location: $ROOT_DIR/$artifact"
187+
exit 1
188+
fi
189+
print_success "Build artifacts verified"
190+
}
191+
192+
show_elapsed_time() {
193+
local END_TIME=$(date +%s)
194+
local ELAPSED=$((END_TIME - START_TIME))
195+
local MINUTES=$((ELAPSED / 60))
196+
local SECONDS=$((ELAPSED % 60))
197+
198+
if [ $MINUTES -gt 0 ]; then
199+
echo -e "Total time: ${BLUE}${MINUTES}m ${SECONDS}s${NC}"
200+
else
201+
echo -e "Total time: ${BLUE}${SECONDS}s${NC}"
141202
fi
203+
}
204+
205+
main() {
206+
# Parse arguments
207+
while [[ $# -gt 0 ]]; do
208+
case $1 in
209+
--help|-h)
210+
show_help
211+
exit 0
212+
;;
213+
--skip-pro)
214+
SKIP_PRO=true
215+
shift
216+
;;
217+
*)
218+
print_error "Unknown option: $1"
219+
echo "Run 'bin/setup --help' for usage information."
220+
exit 1
221+
;;
222+
esac
223+
done
142224

143225
echo -e "${GREEN}Setting up React on Rails development environment...${NC}"
144226
echo ""
145227

146228
cd "$ROOT_DIR"
147229

230+
# Verify we're in the correct directory
231+
print_step "Verifying project directory..."
232+
verify_root_directory
233+
print_success "Project directory verified"
234+
148235
# Check prerequisites
149236
print_step "Checking prerequisites..."
150237
check_prerequisites
@@ -154,15 +241,18 @@ main() {
154241
install_dependencies "$ROOT_DIR" "root directory"
155242

156243
# Build node package
157-
print_step "Building node package..."
158-
rake node_package
159-
print_success "Node package built"
244+
build_node_package
245+
246+
# Verify build artifacts
247+
verify_build_artifacts
160248

161249
# react_on_rails/spec/dummy
162250
install_dependencies "$ROOT_DIR/react_on_rails/spec/dummy" "react_on_rails/spec/dummy"
163251

164-
# react_on_rails_pro (if present)
165-
if [ -d "$ROOT_DIR/react_on_rails_pro" ]; then
252+
# react_on_rails_pro (if present and not skipped)
253+
if [ "$SKIP_PRO" = true ]; then
254+
print_warning "Skipping react_on_rails_pro setup (--skip-pro flag)"
255+
elif [ -d "$ROOT_DIR/react_on_rails_pro" ]; then
166256
install_dependencies "$ROOT_DIR/react_on_rails_pro" "react_on_rails_pro"
167257

168258
# react_on_rails_pro/spec/dummy
@@ -176,6 +266,10 @@ main() {
176266
echo -e "${GREEN}========================================${NC}"
177267
echo -e "${GREEN}Setup complete!${NC}"
178268
echo -e "${GREEN}========================================${NC}"
269+
show_elapsed_time
270+
echo ""
271+
echo "Git hooks have been automatically installed during setup."
272+
echo "They will run linting on changed files before each commit."
179273
echo ""
180274
echo "You can now run:"
181275
echo " rake # Run all tests"

0 commit comments

Comments
 (0)