|  | 
|  | 1 | +#!/bin/bash | 
|  | 2 | + | 
|  | 3 | +# MetaCPAN Web Development Environment Setup Script | 
|  | 4 | +# This script automates the setup process for new developers | 
|  | 5 | + | 
|  | 6 | +set -euo pipefail | 
|  | 7 | + | 
|  | 8 | +# Colors for output | 
|  | 9 | +RED='\033[0;31m' | 
|  | 10 | +GREEN='\033[0;32m' | 
|  | 11 | +YELLOW='\033[1;33m' | 
|  | 12 | +NC='\033[0m' # No Color | 
|  | 13 | + | 
|  | 14 | +log_info() { | 
|  | 15 | +    echo -e "${GREEN}[INFO]${NC} $1" | 
|  | 16 | +} | 
|  | 17 | + | 
|  | 18 | +log_warn() { | 
|  | 19 | +    echo -e "${YELLOW}[WARN]${NC} $1" | 
|  | 20 | +} | 
|  | 21 | + | 
|  | 22 | +log_error() { | 
|  | 23 | +    echo -e "${RED}[ERROR]${NC} $1" | 
|  | 24 | +} | 
|  | 25 | + | 
|  | 26 | +# Check if we're in the right directory | 
|  | 27 | +if [[ ! -f "cpanfile" || ! -f "package.json" ]]; then | 
|  | 28 | +    log_error "This script must be run from the metacpan-web repository root directory" | 
|  | 29 | +    exit 1 | 
|  | 30 | +fi | 
|  | 31 | + | 
|  | 32 | +log_info "Setting up MetaCPAN Web development environment..." | 
|  | 33 | + | 
|  | 34 | +# Check system requirements | 
|  | 35 | +log_info "Checking system requirements..." | 
|  | 36 | + | 
|  | 37 | +# Check Perl | 
|  | 38 | +if ! command -v perl >/dev/null 2>&1; then | 
|  | 39 | +    log_error "Perl is required but not installed" | 
|  | 40 | +    exit 1 | 
|  | 41 | +fi | 
|  | 42 | +PERL_VERSION=$(perl -e 'print $^V' | sed 's/v//') | 
|  | 43 | +log_info "Found Perl $PERL_VERSION" | 
|  | 44 | + | 
|  | 45 | +# Check Node.js | 
|  | 46 | +if ! command -v node >/dev/null 2>&1; then | 
|  | 47 | +    log_error "Node.js is required but not installed" | 
|  | 48 | +    exit 1 | 
|  | 49 | +fi | 
|  | 50 | +NODE_VERSION=$(node --version) | 
|  | 51 | +log_info "Found Node.js $NODE_VERSION" | 
|  | 52 | + | 
|  | 53 | +# Check npm | 
|  | 54 | +if ! command -v npm >/dev/null 2>&1; then | 
|  | 55 | +    log_error "npm is required but not installed" | 
|  | 56 | +    exit 1 | 
|  | 57 | +fi | 
|  | 58 | +NPM_VERSION=$(npm --version) | 
|  | 59 | +log_info "Found npm $NPM_VERSION" | 
|  | 60 | + | 
|  | 61 | +# Install system dependencies | 
|  | 62 | +log_info "Installing system dependencies..." | 
|  | 63 | +if command -v apt-get >/dev/null 2>&1; then | 
|  | 64 | +    if ! dpkg -l | grep -q libcmark-dev; then | 
|  | 65 | +        log_info "Installing libcmark-dev..." | 
|  | 66 | +        sudo apt-get update -qq | 
|  | 67 | +        sudo apt-get install -y libcmark-dev | 
|  | 68 | +    else | 
|  | 69 | +        log_info "libcmark-dev already installed" | 
|  | 70 | +    fi | 
|  | 71 | +else | 
|  | 72 | +    log_warn "apt-get not found, please install libcmark development package manually" | 
|  | 73 | +fi | 
|  | 74 | + | 
|  | 75 | +# Install Perl development tools | 
|  | 76 | +log_info "Installing Perl development tools..." | 
|  | 77 | + | 
|  | 78 | +# Check if carton is available | 
|  | 79 | +if ! command -v carton >/dev/null 2>&1; then | 
|  | 80 | +    log_info "Installing Carton..." | 
|  | 81 | +    cpanm Carton | 
|  | 82 | +else | 
|  | 83 | +    log_info "Carton already installed" | 
|  | 84 | +fi | 
|  | 85 | + | 
|  | 86 | +# Check if cpm is available | 
|  | 87 | +if ! command -v cpm >/dev/null 2>&1; then | 
|  | 88 | +    log_info "Installing App::cpm..." | 
|  | 89 | +    cpanm App::cpm | 
|  | 90 | +else | 
|  | 91 | +    log_info "App::cpm already installed" | 
|  | 92 | +fi | 
|  | 93 | + | 
|  | 94 | +# Add local Perl lib to PATH if needed | 
|  | 95 | +if [[ -d "$HOME/perl5/bin" ]]; then | 
|  | 96 | +    export PERL5LIB="$HOME/perl5/lib/perl5:${PERL5LIB:-}" | 
|  | 97 | +    export PATH="$HOME/perl5/bin:$PATH" | 
|  | 98 | +fi | 
|  | 99 | + | 
|  | 100 | +# Install npm dependencies | 
|  | 101 | +log_info "Installing Node.js dependencies..." | 
|  | 102 | +npm install | 
|  | 103 | + | 
|  | 104 | +# Install Perl dependencies | 
|  | 105 | +log_info "Installing Perl dependencies..." | 
|  | 106 | +if command -v cpm >/dev/null 2>&1; then | 
|  | 107 | +    log_info "Using cpm for faster installation..." | 
|  | 108 | +    cpm install --resolver=snapshot | 
|  | 109 | +else | 
|  | 110 | +    log_info "Using carton..." | 
|  | 111 | +    carton install | 
|  | 112 | +fi | 
|  | 113 | + | 
|  | 114 | +# Build static assets | 
|  | 115 | +log_info "Building static assets..." | 
|  | 116 | +npm run build | 
|  | 117 | + | 
|  | 118 | +# Set up git hooks | 
|  | 119 | +if [[ -f "git/setup.sh" ]]; then | 
|  | 120 | +    log_info "Setting up git hooks..." | 
|  | 121 | +    ./git/setup.sh | 
|  | 122 | +else | 
|  | 123 | +    log_warn "git/setup.sh not found, skipping git hooks setup" | 
|  | 124 | +fi | 
|  | 125 | + | 
|  | 126 | +# Run basic tests to verify setup | 
|  | 127 | +log_info "Running basic tests to verify setup..." | 
|  | 128 | +if command -v carton >/dev/null 2>&1; then | 
|  | 129 | +    log_info "Testing with offline-capable tests..." | 
|  | 130 | +    if carton exec prove -l t/moose.t t/assets.t t/static-files.t t/session.t; then | 
|  | 131 | +        log_info "Basic tests passed!" | 
|  | 132 | +    else | 
|  | 133 | +        log_warn "Some basic tests failed, but the setup might still be functional" | 
|  | 134 | +    fi | 
|  | 135 | +else | 
|  | 136 | +    log_warn "Carton not available, skipping tests" | 
|  | 137 | +fi | 
|  | 138 | + | 
|  | 139 | +log_info "Development environment setup complete!" | 
|  | 140 | +echo | 
|  | 141 | +log_info "You can now:" | 
|  | 142 | +echo "  • Run the development server: carton exec plackup -p 5001 -r app.psgi" | 
|  | 143 | +echo "  • Run tests: carton exec prove -l -r t" | 
|  | 144 | +echo "  • Build assets: npm run build" | 
|  | 145 | +echo "  • Watch for asset changes: npm run build:watch" | 
|  | 146 | +echo | 
|  | 147 | +log_warn "Note: Some tests require network access to api.metacpan.org and will fail in isolated environments" | 
0 commit comments