#!/usr/bin/env bash ##? Usage: ##? run [build|init|needed] ##? run --help ##? ##? Options: ##? --help Show this help ##? ##? ##? Requirements: ##? ##? This script is used to build language grammars from Atom's various ##? github repositories. They must be built because Atom stupidly uses ##? CoffeeScript's pointless CSON format and therefore needs to be converted to ##? JSON to be usable. To build these grammars the following packages must be ##? installed on a unix-based system: ##? ##? * bash >=5.0 ##? * composer >=2.0.6 ##? * docopts >=0.6.3 ##? * gnu awk >=5.1.0 ##? * gnu coreutils >=8.0 ##? * gnu parallel >=20180922 ##? * yarn >=1.22.10 ##? ##? Arch Linux: ##? ``` ##? pacman -S composer docopts parallel yarn ##? ``` ##? ##? macOS: ##? ``` ##? brew install bash composer coreutils docopts gawk parallel yarn ##? echo \"/usr/local/bin/bash\" >> /etc/shells ##? chsh -s /usr/local/bin/bash ##? ``` ##? ##? Building the grammars is then a matter of running the following commands ##? from the project folder: ##? ##? ``` ##? ./run init ##? ./run build ##? ``` ##? ##? ##? Commands: ##? ##? init ##? Initializes the dependencies necessary to build the language ##? grammars. ##? ##? build ##? Build the language grammars. Puts them into data/. ##? ##? needed ##? List the language grammars that are included in the current grammars ##? but are not in the data/ folder. cwd=$(pwd) PATH="$cwd/node_modules/.bin:$PATH" help=$(grep "^##?" "$0" | cut -c 5-) eval "$(docopts -h "$help" : "$@")" fail() { echo $help exit 1 } # Check for bash 4+ shopt -s globstar extglob || fail awkcmd="awk" if [ "$(uname)" == "Darwin" ]; then awkcmd="gawk" fi # Check for presence of dependencies if (( $(which $awkcmd composer parallel yarn | wc -l) < 4 )); then fail; fi case $1 in init) yarn install mkdir -p "$cwd"/deps rm -rf "$cwd"/deps/* cd "$cwd"/deps printf "franzheidl/atom-applescript atom/language-c atom/language-coffee-script atom/language-css rmosolgo/language-graphql atom/language-html atom/language-java atom/language-javascript atom/language-json burodepeper/language-markdown Azganoth/language-lua-plus atom/language-php atom/language-python atom/language-ruby atom/language-shellscript MaxGiting/atom-language-smarty atom/language-sql al3x/atom-language-textile atom/language-typescript atom/language-xml" | parallel "git clone https://github.com/{}.git" cd "$cwd" ;; needed) grep -Fxv -f <(cd "$cwd"/data && ls -1 *.json | sed -e 's/\.json$//g') <(cat "$cwd"/data/*.json | grep -E "\"include\"\s*:\s*\"[^#\$]+\"" | gawk '{ match($0, /"include": "(.+?)"/, arr); if(arr[1] != "") print arr[1] }' | sort -u) ;; build | *) rm -rf "$cwd"/data/* # Convert from CSON to JSON AND rename the files to their scopes... all in parallel. ls -1 "$cwd"/deps/**/grammars/!(tree-sitter-*).cson | parallel "temp=\$(mktemp) && csonc --output=\$temp {} mv \$temp \"$cwd\"/data/\$(grep -m1 scopeName \$temp | $awkcmd '{ match(\$0, /\s*:\s*\"(.+?)\"/, arr); if(arr[1] != \"\") print arr[1] }').json" # Some packages use JSON files, so just rename them to their scopes ls -1 "$cwd"/deps/**/grammars/!(tree-sitter-*).json | parallel "cp {} \"$cwd\"/data/\$(grep -m1 scopeName {} | $awkcmd '{ match(\$0, /\s*:\s*\"(.+?)\"/, arr); if(arr[1] != \"\") print arr[1] }').json" ;; esac