Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
208 changes: 208 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
# Development Setup Guide

This guide helps you set up a local development environment for MetaCPAN Web.

## Quick Setup

For automated setup, run:

```bash
./bin/setup-dev
```

This script will:
- Check system requirements
- Install system dependencies (libcmark-dev)
- Install Perl development tools (carton, cpm)
- Install all project dependencies
- Build static assets
- Set up git hooks
- Run basic tests

## Manual Setup

If you prefer to set up manually or the automated script doesn't work in your environment:

### Prerequisites

- Perl 5.36+ (tested with 5.38.2)
- Node.js 20+ (tested with 20.19.4)
- npm 10+ (tested with 10.8.2)
- System dependencies: libcmark-dev (on Ubuntu/Debian)

### Install Dependencies

1. **Install system dependencies:**
```bash
# On Ubuntu/Debian
sudo apt-get install libcmark-dev

# On macOS
brew install cmark
```

2. **Install Perl tools:**
```bash
# Install carton and cpm
cpan App::carton App::cpm
```

3. **Install Node.js dependencies:**
```bash
npm install
```

4. **Install Perl dependencies:**
```bash
# Using cpm (faster)
cpm install --resolver=snapshot

# Or using carton
carton install
```

5. **Build static assets:**
```bash
npm run build
```

6. **Set up git hooks:**
```bash
./git/setup.sh
```

## Running the Application

### Development Server

```bash
carton exec plackup -p 5001 -r app.psgi
```

The application will be available at http://localhost:5001

### Alternative Servers

For better performance during development:

```bash
# Using Gazelle
carton exec plackup -p 5001 -s Gazelle -r app.psgi

# Using Starman
carton exec plackup -p 5001 -s Starman app.psgi
```

## Testing

### Run All Tests

```bash
carton exec prove -l -r --jobs 2 t
```

### Run Specific Tests

```bash
# Basic functionality tests (work offline)
carton exec prove -l t/moose.t t/assets.t t/session.t

# Specific controller tests
carton exec prove -l t/controller/about.t
```

### Note on Test Failures

Many tests require network access to `api.metacpan.org` and will fail in isolated environments. This is expected behavior. The core functionality tests (like `t/moose.t`, `t/assets.t`, etc.) should pass.

## Asset Development

### Building Assets

```bash
# One-time build
npm run build

# Minified build (for production)
npm run build:min

# Watch for changes during development
npm run build:watch
```

### Asset Files

- Source files: `root/static/`
- Built files: `root/assets/`
- Build configuration: `build-assets.mjs`

## Code Quality

### Linting

The project uses `precious` to orchestrate various linters:

```bash
# Install precious (if not using Docker)
./bin/install-precious /usr/local/bin

# Lint all files
precious lint --all

# Lint specific files
precious lint path/to/file

# Auto-fix issues
precious tidy --all
```

### Git Hooks

Pre-commit hooks are configured to run `precious` automatically. Set them up with:

```bash
./git/setup.sh
```

## Docker Development

For a completely isolated environment, use Docker:

```bash
# Build development image
docker build --target develop -t metacpan-web:dev .

# Run development container
docker run -it -p 5001:8000 -v $(pwd):/app metacpan-web:dev
```

## Configuration

### Local Configuration

Create a `metacpan_web_local.yaml` file to override settings:

```yaml
api: http://127.0.0.1:5000 # Local API server
debug: 1
```

### Environment Variables

- `PLACK_ENV`: Set to `development` for development mode
- `METACPAN_WEB_HOME`: Path to application root (auto-detected)

## Troubleshooting

### Common Issues

1. **Asset map errors**: Run `npm run build` to generate assets
2. **Permission errors**: Check that `local/` directory is writable
3. **Test failures**: Most network-dependent tests will fail without API access
4. **Module not found**: Ensure `carton exec` is used or local lib is in `PERL5LIB`

### Getting Help

- Check the main [README.md](README.md)
- Review existing [issues](https://github.com/metacpan/metacpan-web/issues)
- Ask in the MetaCPAN IRC channel or discussions
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,30 @@ We strongly recommend using
[metacpan-docker](https://github.com/metacpan/metacpan-docker). This will give
you a virtual machine already configured and ready to start developing on.

If you prefer not to use Docker, the following commands will get you started:
If you prefer not to use Docker, you can set up a local development environment:

## Quick Setup

For automated setup, run:

```bash
./bin/setup-dev
```

This will install all dependencies, build assets, and verify your setup.

## Installing Manually

If you prefer manual setup or need more control:

```bash
carton install
npm install
export PATH="$(realpath ./node_modules/.bin):$PATH"
```

For detailed setup instructions, see [DEVELOPMENT.md](DEVELOPMENT.md).

### Building Static Assets

```bash
Expand Down
147 changes: 147 additions & 0 deletions bin/setup-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
#!/bin/bash

# MetaCPAN Web Development Environment Setup Script
# This script automates the setup process for new developers

set -euo pipefail

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

log_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}

log_warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}

log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}

# Check if we're in the right directory
if [[ ! -f "cpanfile" || ! -f "package.json" ]]; then
log_error "This script must be run from the metacpan-web repository root directory"
exit 1
fi

log_info "Setting up MetaCPAN Web development environment..."

# Check system requirements
log_info "Checking system requirements..."

# Check Perl
if ! command -v perl >/dev/null 2>&1; then
log_error "Perl is required but not installed"
exit 1
fi
PERL_VERSION=$(perl -e 'print $^V' | sed 's/v//')
log_info "Found Perl $PERL_VERSION"

# Check Node.js
if ! command -v node >/dev/null 2>&1; then
log_error "Node.js is required but not installed"
exit 1
fi
NODE_VERSION=$(node --version)
log_info "Found Node.js $NODE_VERSION"

# Check npm
if ! command -v npm >/dev/null 2>&1; then
log_error "npm is required but not installed"
exit 1
fi
NPM_VERSION=$(npm --version)
log_info "Found npm $NPM_VERSION"

# Install system dependencies
log_info "Installing system dependencies..."
if command -v apt-get >/dev/null 2>&1; then
if ! dpkg -l | grep -q libcmark-dev; then
log_info "Installing libcmark-dev..."
sudo apt-get update -qq
sudo apt-get install -y libcmark-dev
else
log_info "libcmark-dev already installed"
fi
else
log_warn "apt-get not found, please install libcmark development package manually"
fi

# Install Perl development tools
log_info "Installing Perl development tools..."

# Check if carton is available
if ! command -v carton >/dev/null 2>&1; then
log_info "Installing Carton..."
PERL_MM_USE_DEFAULT=1 cpan -i Carton
else
log_info "Carton already installed"
fi

# Check if cpm is available
if ! command -v cpm >/dev/null 2>&1; then
log_info "Installing App::cpm..."
PERL_MM_USE_DEFAULT=1 cpan -i App::cpm
else
log_info "App::cpm already installed"
fi

# Add local Perl lib to PATH if needed
if [[ -d "$HOME/perl5/bin" ]]; then
export PERL5LIB="$HOME/perl5/lib/perl5:${PERL5LIB:-}"
export PATH="$HOME/perl5/bin:$PATH"
fi

# Install npm dependencies
log_info "Installing Node.js dependencies..."
npm install

# Install Perl dependencies
log_info "Installing Perl dependencies..."
if command -v cpm >/dev/null 2>&1; then
log_info "Using cpm for faster installation..."
cpm install --resolver=snapshot
else
log_info "Using carton..."
carton install
fi

# Build static assets
log_info "Building static assets..."
npm run build

# Set up git hooks
if [[ -f "git/setup.sh" ]]; then
log_info "Setting up git hooks..."
./git/setup.sh
else
log_warn "git/setup.sh not found, skipping git hooks setup"
fi

# Run basic tests to verify setup
log_info "Running basic tests to verify setup..."
if command -v carton >/dev/null 2>&1; then
log_info "Testing with offline-capable tests..."
if carton exec prove -l t/moose.t t/assets.t t/static-files.t t/session.t; then
log_info "Basic tests passed!"
else
log_warn "Some basic tests failed, but the setup might still be functional"
fi
else
log_warn "Carton not available, skipping tests"
fi

log_info "Development environment setup complete!"
echo
log_info "You can now:"
echo " β€’ Run the development server: carton exec plackup -p 5001 -r app.psgi"
echo " β€’ Run tests: carton exec prove -l -r t"
echo " β€’ Build assets: npm run build"
echo " β€’ Watch for asset changes: npm run build:watch"
echo
log_warn "Note: Some tests require network access to api.metacpan.org and will fail in isolated environments"
Loading