CLI Getting Started
The maplibre-yaml CLI provides command-line tools for validating and previewing your YAML map configurations. It helps catch errors early and enables rapid development with hot reload.
Installation
Section titled “Installation”Global Installation
Section titled “Global Installation”Install the CLI globally to use it anywhere:
npm install -g @maplibre-yaml/cliOr with pnpm:
pnpm add -g @maplibre-yaml/cliUsing npx
Section titled “Using npx”You can use the CLI without installing it:
npx @maplibre-yaml/cli <command>Short Alias
Section titled “Short Alias”The CLI provides a shorter mlym alias:
mlym validate config.yamlValidate Configuration
Section titled “Validate Configuration”Validate your YAML configuration files to catch errors before runtime.
Basic Validation
Section titled “Basic Validation”Validate a single file:
maplibre-yaml validate my-map.yamlOutput for valid configuration:
✓ my-map.yaml
✓ 1 file(s) validOutput for invalid configuration:
✗ my-map.yaml error config: Expected object, got undefined
✗ 1 file(s) with issues: 1 error(s)Glob Patterns
Section titled “Glob Patterns”Validate multiple files using glob patterns:
# Validate all YAML files in a directorymaplibre-yaml validate "configs/**/*.yaml"
# Validate specific patternsmaplibre-yaml validate "maps/*.yaml"
# Multiple patternsmaplibre-yaml validate "src/**/*.map.yaml" "configs/*.yaml"Output with progress indicator (for >10 files):
Validating [████████████████████] 100% (25/25)✓ Validated 25 files
✓ 23 file(s) valid✗ 2 file(s) with issues: 3 error(s)Output Formats
Section titled “Output Formats”Choose from multiple output formats:
Human-Readable (default)
Section titled “Human-Readable (default)”maplibre-yaml validate my-map.yamlJSON for CI/CD
Section titled “JSON for CI/CD”Get structured JSON output:
maplibre-yaml validate my-map.yaml --format jsonOutput:
{ "valid": true, "files": [ { "file": "my-map.yaml", "valid": true, "errors": [], "warnings": [] } ], "summary": { "total": 1, "valid": 1, "invalid": 0, "errorCount": 0, "warningCount": 0 }}SARIF for GitHub Code Scanning
Section titled “SARIF for GitHub Code Scanning”Generate SARIF format for GitHub Advanced Security:
maplibre-yaml validate my-map.yaml --format sarifVSCode Problem Matcher
Section titled “VSCode Problem Matcher”Output format compatible with VSCode’s Problem Matcher:
maplibre-yaml validate my-map.yaml --format vscodeOutput:
/path/to/config.yaml:5:10: error: [config.center] Expected array, got string/path/to/config.yaml:12:3: warning: [layers[0]] Deprecated propertySee VSCode Integration for setup instructions.
Watch Mode
Section titled “Watch Mode”Continuously validate files as they change:
maplibre-yaml validate "configs/**/*.yaml" --watchFeatures:
- Intelligent Caching: Only re-validates changed files
- Fast: Cached validations complete in less than 1ms
- Real-time Feedback: Shows errors immediately on save
Strict Mode
Section titled “Strict Mode”Treat warnings as errors:
maplibre-yaml validate my-map.yaml --strictExit Codes
Section titled “Exit Codes”The validate command uses specific exit codes for automation:
| Code | Meaning |
|---|---|
| 0 | Valid configuration |
| 1 | Validation errors |
| 2 | File not found |
| 3 | Invalid YAML syntax |
| 4 | Unknown error |
Performance
Section titled “Performance”The CLI is highly optimized for speed:
- 100 files: Validated in ~80ms
- Single file: Validated in ~1ms
- Watch mode: Cached validations in ~1ms
- Parallel processing: Configurable concurrency (default: 10)
Example CI usage:
name: Validate Mapson: [push, pull_request]jobs: validate: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 - run: npx @maplibre-yaml/cli validate "configs/**/*.yaml" --format jsonGitHub Code Scanning with SARIF:
name: Code Scanningon: [push, pull_request]jobs: analyze: runs-on: ubuntu-latest permissions: security-events: write steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 - run: npx @maplibre-yaml/cli validate "**/*.yaml" --format sarif > results.sarif - uses: github/codeql-action/upload-sarif@v2 with: sarif_file: results.sarifPreview Your Map
Section titled “Preview Your Map”Start a local development server with hot reload to preview your map as you edit.
Basic Preview
Section titled “Basic Preview”maplibre-yaml preview my-map.yamlThis will:
- Start a Vite development server on port 3000
- Open your browser automatically
- Watch the YAML file for changes
- Reload the map when you save edits
Custom Port
Section titled “Custom Port”Use a different port:
maplibre-yaml preview my-map.yaml --port 8080Don’t Open Browser
Section titled “Don’t Open Browser”Start the server without opening the browser:
maplibre-yaml preview my-map.yaml --no-openPreview Features
Section titled “Preview Features”The preview server includes:
- Hot Reload: Automatically refreshes when you edit the YAML file
- Error Overlay: Shows configuration errors with helpful messages
- Status Bar: Displays connection state and file path
- Live Validation: Validates configuration on every change
- MapLibre Integration: Full support for all MapLibre features
Error Handling
Section titled “Error Handling”If your configuration has errors, the preview will show:
- A dark overlay with the error message
- Red status indicator
- Specific error details (path, line, column)
- No map render (prevents confusion)
Example error display:
Configuration Error━━━━━━━━━━━━━━━━━config: Expected object, got undefinedDevelopment Workflow
Section titled “Development Workflow”-
Start the preview server:
Terminal window maplibre-yaml preview my-map.yaml -
Edit your YAML file in your editor
-
Save the file
-
Preview automatically reloads with changes
-
Fix any errors shown in the overlay
-
Repeat!
Getting Help
Section titled “Getting Help”Command Help
Section titled “Command Help”Get help for any command:
maplibre-yaml --helpmaplibre-yaml validate --helpmaplibre-yaml preview --helpVersion
Section titled “Version”Check the installed version:
maplibre-yaml --versionNext Steps
Section titled “Next Steps”- Command Reference - Detailed command documentation
- Examples - Sample YAML configurations
- Schema Reference - Full schema documentation