Skip to content

Examples โ€‹

Learn how to use Plexr through practical examples. These examples cover common use cases and demonstrate best practices.

Available Examples โ€‹

Basic Setup โ€‹

A simple example showing how to set up a basic development environment with common tools.

What you'll learn:

  • Creating your first plan
  • Using platform-specific scripts
  • Basic step dependencies

Advanced Patterns โ€‹

Advanced techniques for complex setups.

What you'll learn:

  • Complex dependency chains
  • Conditional execution
  • Error handling strategies
  • State management

Real World Examples โ€‹

Production-ready examples from actual projects.

What you'll learn:

  • Full-stack application setup
  • Database migrations
  • CI/CD integration
  • Team collaboration patterns

Quick Start Example โ€‹

Here's a minimal example to get you started:

yaml
name: "Quick Start"
version: "1.0.0"

executors:
  shell:
    type: shell

steps:
  - id: hello_world
    description: "Say hello"
    executor: shell
    files:
      - path: "hello.sh"

With hello.sh:

bash
#!/bin/bash
echo "Hello from Plexr! ๐Ÿš€"

Run it:

bash
plexr execute quickstart.yml

Common Patterns โ€‹

1. Tool Installation with Verification โ€‹

yaml
steps:
  - id: install_node
    description: "Install Node.js"
    executor: shell
    check_command: "node --version"
    files:
      - path: "install_node.sh"

2. Platform-Specific Scripts โ€‹

yaml
steps:
  - id: install_deps
    description: "Install dependencies"
    executor: shell
    files:
      - path: "install_linux.sh"
        platform: linux
      - path: "install_mac.sh"
        platform: darwin
      - path: "install_windows.ps1"
        platform: windows

3. Sequential Dependencies โ€‹

yaml
steps:
  - id: step1
    description: "First step"
    executor: shell
    files:
      - path: "step1.sh"
  
  - id: step2
    description: "Second step"
    depends_on: [step1]
    executor: shell
    files:
      - path: "step2.sh"
  
  - id: step3
    description: "Third step"
    depends_on: [step2]
    executor: shell
    files:
      - path: "step3.sh"

4. Parallel Execution โ€‹

yaml
steps:
  - id: download_tools
    description: "Download tools"
    executor: shell
    files:
      - path: "download.sh"
  
  - id: create_dirs
    description: "Create directories"
    executor: shell
    files:
      - path: "mkdirs.sh"
  
  - id: setup_configs
    description: "Setup configurations"
    depends_on: [download_tools, create_dirs]
    executor: shell
    files:
      - path: "configure.sh"

Best Practices from Examples โ€‹

1. Always Use Check Commands โ€‹

yaml
check_command: "command -v docker >/dev/null 2>&1"

2. Make Scripts Idempotent โ€‹

bash
# Bad
mkdir ~/workspace

# Good
mkdir -p ~/workspace

3. Handle Errors Gracefully โ€‹

bash
set -euo pipefail

if ! command -v node &> /dev/null; then
    echo "Node.js is required but not installed"
    exit 1
fi

4. Use Descriptive Step IDs โ€‹

yaml
# Bad
id: step1

# Good
id: install_postgresql_14

Example Repository Structure โ€‹

A typical project using Plexr:

my-project/
โ”œโ”€โ”€ setup.yml              # Main plan file
โ”œโ”€โ”€ scripts/              # Execution scripts
โ”‚   โ”œโ”€โ”€ install/
โ”‚   โ”‚   โ”œโ”€โ”€ node.sh
โ”‚   โ”‚   โ”œโ”€โ”€ docker.sh
โ”‚   โ”‚   โ””โ”€โ”€ postgres.sh
โ”‚   โ”œโ”€โ”€ configure/
โ”‚   โ”‚   โ”œโ”€โ”€ git.sh
โ”‚   โ”‚   โ””โ”€โ”€ env.sh
โ”‚   โ””โ”€โ”€ verify/
โ”‚       โ””โ”€โ”€ health_check.sh
โ”œโ”€โ”€ sql/                  # SQL scripts
โ”‚   โ”œโ”€โ”€ create_db.sql
โ”‚   โ””โ”€โ”€ migrations/
โ””โ”€โ”€ configs/              # Configuration templates
    โ”œโ”€โ”€ .env.template
    โ””โ”€โ”€ docker-compose.yml

Contributing Examples โ€‹

Have a great example? We'd love to include it!

  1. Fork the repository
  2. Add your example to examples/
  3. Include a README explaining the use case
  4. Submit a pull request

Next Steps โ€‹

Released under the MIT License.