Conditionals
Basic If/Else
Section titled “Basic If/Else”task install: @if env(CI) npm ci @else npm install @endIf/Elif/Else
Section titled “If/Elif/Else”task deploy: @if env(PRODUCTION) echo "Deploying to production" @elif env(STAGING) echo "Deploying to staging" @else echo "Deploying to development" @endCondition Functions
Section titled “Condition Functions”| Function | Description |
|---|---|
env(VAR) | True if environment variable is set and non-empty |
exists(path) | True if file or directory exists |
command(name) | True if command exists in PATH |
eq(a, b) | True if strings are equal |
neq(a, b) | True if strings are not equal |
is_watching() | True if running in watch mode (-w) |
is_dry_run() | True if running in dry-run mode (-n) |
is_verbose() | True if running in verbose mode (-v) |
is_macos() | True if running on macOS |
is_linux() | True if running on Linux |
is_windows() | True if running on Windows |
is_unix() | True if running on Unix-like OS (Linux, macOS, BSD) |
is_platform(name) | True if running on the specified platform |
Runtime State Conditions
Section titled “Runtime State Conditions”Check how jake was invoked:
task build: @if is_watching() echo "Watch mode: skipping expensive lint" @else npm run lint @end npm run build
task deploy: @if is_dry_run() echo "[DRY RUN] Would deploy to production" @else rsync dist/ server:/var/www/ @end
task test: @if is_verbose() npm test -- --verbose @else npm test @endFile Existence
Section titled “File Existence”task setup: @if exists(node_modules) echo "Dependencies already installed" @else npm install @endString Comparison
Section titled “String Comparison”task build: @if eq($BUILD_MODE, "release") cargo build --release @else cargo build @endCommand Availability
Section titled “Command Availability”Check if tools are available before using them:
task build: @if command(docker) docker build -t myapp . @elif command(podman) podman build -t myapp . @else echo "No container runtime found" @end
task deploy: @if command(kubectl) kubectl apply -f k8s/ @else echo "kubectl not installed - skipping deploy" @endWorks with absolute paths too:
task check: @if command(/usr/local/bin/custom-tool) /usr/local/bin/custom-tool run @endPlatform Detection
Section titled “Platform Detection”Run platform-specific commands:
task install: @if is_macos() brew install ripgrep @elif is_linux() apt-get install ripgrep @elif is_windows() choco install ripgrep @end
task open: @if is_macos() open https://jakefile.dev @elif is_linux() xdg-open https://jakefile.dev @elif is_windows() start https://jakefile.dev @endUse is_unix() for commands that work on all Unix-like systems:
task permissions: @if is_unix() chmod +x ./script.sh @endUse is_platform() for flexible platform matching:
task build: @if is_platform(freebsd) gmake build @else make build @end