Last active
April 12, 2023 12:01
-
-
Save harto/cd6e9719011cfe1a5d26cd961b3dca85 to your computer and use it in GitHub Desktop.
Validate a partial Mapbox style expression
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
# Check a partial Mapbox style expression using gl-style-validate | |
# (https://github.com/mapbox/mapbox-gl-js/tree/master/src/style-spec). | |
# | |
# To install gl-style-validate: | |
# $ npm install @mapbox/mapbox-gl-style-spec --global | |
# | |
# Usage: | |
# $ validate-mapbox-expression '{"type": "line", "paint": {"line-width": "whoops"}}' | |
# /dev/stdin:16: layers[0].paint.line-width: number expected, string found | |
EXPR="$1" | |
jq -s '{ | |
"version": 8, | |
"sources": { | |
"dummy": { | |
"type": "vector", | |
"url": "http://example.com/tiles.json" | |
} | |
}, | |
"layers": [ | |
{ | |
"id": "dummy", | |
"source": "dummy", | |
"source-layer": "dummy" | |
} * .[0] | |
] | |
}' <<< "$EXPR" | gl-style-validate | |
how to run this?
@satya-auti do something like this:
- Install the Mapbox dependency as in the inline comments
- Save this gist to a file somewhere on your computer, e.g.
/usr/bin/validate-mapbox-expression
- Give your user account permission to execute it:
chmod +x /usr/bin/validate-mapbox-expression
- Run it as in the inline comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how to run this?