Skip to content

Commit 3b22b9f

Browse files
committed
Add build, development, initialization, linting, and testing scripts
1 parent dcfd9aa commit 3b22b9f

5 files changed

Lines changed: 629 additions & 0 deletions

File tree

scripts/build.sh

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
#!/bin/bash
2+
# ============================================================================
3+
# Rica - Production Build Script
4+
# ============================================================================
5+
#
6+
# Purpose:
7+
# Creates an optimized production build of rica with optional asset inlining
8+
# for single-file HTML distribution (suitable for embedding in tedana outputs).
9+
#
10+
# Expected Environment:
11+
# - Node.js v16+ installed
12+
# - Dependencies installed via npm install
13+
#
14+
# Build Output:
15+
# - ./build/ - Standard React production build
16+
# - ./build/index.html - With --inline: single-file with inlined JS/CSS
17+
#
18+
# Usage:
19+
# ./scripts/build.sh # Standard production build
20+
# ./scripts/build.sh --inline # Build + inline assets (single HTML file)
21+
# ./scripts/build.sh --analyze # Build + analyze bundle size
22+
# ./scripts/build.sh --check # Build + verify output integrity
23+
#
24+
# Notes:
25+
# - The --inline option uses Gulp to inline JS/CSS into index.html
26+
# - This is useful for distributing rica as a single file with tedana outputs
27+
# - Build artifacts are placed in ./build/ directory
28+
#
29+
# ============================================================================
30+
31+
set -e
32+
33+
# Colors for output
34+
RED='\033[0;31m'
35+
GREEN='\033[0;32m'
36+
YELLOW='\033[1;33m'
37+
NC='\033[0m'
38+
39+
# Navigate to project root
40+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
41+
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
42+
cd "$PROJECT_ROOT"
43+
44+
# Default values
45+
INLINE=false
46+
ANALYZE=false
47+
CHECK=false
48+
49+
# Parse arguments
50+
while [[ $# -gt 0 ]]; do
51+
case $1 in
52+
--inline)
53+
INLINE=true
54+
shift
55+
;;
56+
--analyze)
57+
ANALYZE=true
58+
shift
59+
;;
60+
--check)
61+
CHECK=true
62+
shift
63+
;;
64+
*)
65+
echo "Unknown option: $1"
66+
echo "Usage: ./scripts/build.sh [--inline] [--analyze] [--check]"
67+
exit 1
68+
;;
69+
esac
70+
done
71+
72+
# Check if node_modules exists
73+
if [ ! -d "node_modules" ]; then
74+
echo -e "${RED}Error: node_modules not found. Run ./scripts/init_env.sh first.${NC}"
75+
exit 1
76+
fi
77+
78+
echo "============================================"
79+
echo "Rica Production Build"
80+
echo "============================================"
81+
echo ""
82+
83+
# Clean previous build
84+
if [ -d "build" ]; then
85+
echo "Cleaning previous build..."
86+
rm -rf build
87+
fi
88+
89+
# Run production build
90+
echo "Creating production build..."
91+
if [ "$ANALYZE" = true ]; then
92+
# Build with source maps for analysis
93+
GENERATE_SOURCEMAP=true npm run build
94+
else
95+
npm run build
96+
fi
97+
98+
# Verify build output
99+
if [ ! -f "build/index.html" ]; then
100+
echo -e "${RED}Error: Build failed - index.html not found${NC}"
101+
exit 1
102+
fi
103+
104+
echo -e "${GREEN}React build complete${NC}"
105+
106+
# Inline assets if requested
107+
if [ "$INLINE" = true ]; then
108+
echo ""
109+
echo "Inlining JS and CSS assets..."
110+
111+
# Check if gulp is available
112+
if [ ! -f "node_modules/.bin/gulp" ]; then
113+
echo -e "${YELLOW}Warning: Gulp not found. Installing...${NC}"
114+
npm install --save-dev gulp gulp-inline-source gulp-replace
115+
fi
116+
117+
# Run gulp task
118+
npx gulp
119+
120+
if [ $? -eq 0 ]; then
121+
echo -e "${GREEN}Assets inlined successfully${NC}"
122+
123+
# Check file size
124+
INLINE_SIZE=$(wc -c < "build/index.html" | tr -d ' ')
125+
INLINE_SIZE_MB=$(echo "scale=2; $INLINE_SIZE / 1048576" | bc)
126+
echo "Inlined index.html size: ${INLINE_SIZE_MB}MB"
127+
else
128+
echo -e "${RED}Warning: Asset inlining failed${NC}"
129+
fi
130+
fi
131+
132+
# Verify build integrity if requested
133+
if [ "$CHECK" = true ]; then
134+
echo ""
135+
echo "Verifying build integrity..."
136+
137+
# Check for expected files
138+
EXPECTED_FILES=("build/index.html" "build/static/js" "build/static/css")
139+
ALL_PRESENT=true
140+
141+
for file in "${EXPECTED_FILES[@]}"; do
142+
if [ -e "$file" ] || [ -d "$file" ]; then
143+
echo -e " ${GREEN}[OK]${NC} $file"
144+
else
145+
echo -e " ${RED}[MISSING]${NC} $file"
146+
ALL_PRESENT=false
147+
fi
148+
done
149+
150+
if [ "$ALL_PRESENT" = true ]; then
151+
echo -e "${GREEN}Build verification passed${NC}"
152+
else
153+
echo -e "${YELLOW}Warning: Some expected files are missing${NC}"
154+
fi
155+
fi
156+
157+
# Print build summary
158+
echo ""
159+
echo "============================================"
160+
echo -e "${GREEN}Build complete!${NC}"
161+
echo "============================================"
162+
echo ""
163+
echo "Output directory: ./build/"
164+
165+
if [ "$INLINE" = true ]; then
166+
echo "Single-file distribution: ./build/index.html"
167+
fi
168+
169+
echo ""
170+
echo "To preview the build locally:"
171+
echo " npx serve -s build"
172+
echo ""

scripts/dev.sh

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#!/bin/bash
2+
# ============================================================================
3+
# Rica - Development Server Script
4+
# ============================================================================
5+
#
6+
# Purpose:
7+
# Starts the React development server with hot reload for rapid iteration.
8+
# Optionally starts Tailwind CSS watcher in parallel.
9+
#
10+
# Expected Environment:
11+
# - Node.js v16+ installed
12+
# - Dependencies installed via npm install
13+
# - Browser: Chrome, Firefox, Safari, or Edge (modern versions)
14+
#
15+
# Default Behavior:
16+
# - Starts on http://localhost:3000
17+
# - Opens browser automatically
18+
# - Hot reload enabled for JS/CSS changes
19+
#
20+
# Usage:
21+
# ./scripts/dev.sh # Start dev server (port 3000)
22+
# ./scripts/dev.sh --port 3001 # Start on custom port
23+
# ./scripts/dev.sh --no-open # Don't auto-open browser
24+
# ./scripts/dev.sh --with-css # Also run Tailwind CSS watcher
25+
#
26+
# Environment Variables:
27+
# PORT=3001 ./scripts/dev.sh # Alternative way to set port
28+
# BROWSER=none ./scripts/dev.sh # Prevent browser from opening
29+
#
30+
# ============================================================================
31+
32+
set -e
33+
34+
# Navigate to project root
35+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
36+
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
37+
cd "$PROJECT_ROOT"
38+
39+
# Default values
40+
PORT=${PORT:-3000}
41+
OPEN_BROWSER=true
42+
WITH_CSS=false
43+
44+
# Parse arguments
45+
while [[ $# -gt 0 ]]; do
46+
case $1 in
47+
--port)
48+
PORT="$2"
49+
shift 2
50+
;;
51+
--no-open)
52+
OPEN_BROWSER=false
53+
shift
54+
;;
55+
--with-css)
56+
WITH_CSS=true
57+
shift
58+
;;
59+
*)
60+
echo "Unknown option: $1"
61+
echo "Usage: ./scripts/dev.sh [--port PORT] [--no-open] [--with-css]"
62+
exit 1
63+
;;
64+
esac
65+
done
66+
67+
# Check if node_modules exists
68+
if [ ! -d "node_modules" ]; then
69+
echo "Error: node_modules not found. Run ./scripts/init_env.sh first."
70+
exit 1
71+
fi
72+
73+
echo "============================================"
74+
echo "Rica Development Server"
75+
echo "============================================"
76+
echo ""
77+
echo "Starting on: http://localhost:$PORT"
78+
echo ""
79+
80+
# Set environment
81+
export PORT=$PORT
82+
83+
if [ "$OPEN_BROWSER" = false ]; then
84+
export BROWSER=none
85+
fi
86+
87+
# Start Tailwind CSS watcher if requested
88+
if [ "$WITH_CSS" = true ]; then
89+
echo "Starting Tailwind CSS watcher in background..."
90+
npm run watch:css &
91+
CSS_PID=$!
92+
93+
# Cleanup function
94+
cleanup() {
95+
echo ""
96+
echo "Shutting down..."
97+
kill $CSS_PID 2>/dev/null || true
98+
exit 0
99+
}
100+
trap cleanup SIGINT SIGTERM
101+
fi
102+
103+
# Start development server
104+
npm start
105+
106+
# Cleanup CSS watcher if it was started
107+
if [ "$WITH_CSS" = true ]; then
108+
kill $CSS_PID 2>/dev/null || true
109+
fi

0 commit comments

Comments
 (0)