2021-06-16 17:44:47 -04:00
|
|
|
#!/usr/bin/env bash
|
2021-06-17 17:59:08 -04:00
|
|
|
|
|
|
|
##? 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
|
2021-06-28 17:52:38 -04:00
|
|
|
##? * GNU coreutils >=8.0
|
|
|
|
##? * GNU parallel >=20180922
|
2021-07-08 17:18:10 -04:00
|
|
|
##? * jq >=1.6
|
2021-06-17 17:59:08 -04:00
|
|
|
##? * yarn >=1.22.10
|
|
|
|
##?
|
|
|
|
##? Arch Linux:
|
2021-07-08 17:18:10 -04:00
|
|
|
##?
|
|
|
|
##?
|
|
|
|
##? pacman -S composer docopts jq parallel yarn
|
|
|
|
##?
|
2021-06-17 17:59:08 -04:00
|
|
|
##?
|
|
|
|
##? macOS:
|
2021-07-08 17:18:10 -04:00
|
|
|
##?
|
|
|
|
##?
|
|
|
|
##? brew install bash composer coreutils docopts jq parallel yarn
|
2021-06-28 17:52:38 -04:00
|
|
|
##? echo \"/usr/local/bin/bash\" >> /etc/shells
|
|
|
|
##? chsh -s /usr/local/bin/bash
|
2021-07-08 17:18:10 -04:00
|
|
|
##?
|
2021-06-17 17:59:08 -04:00
|
|
|
##?
|
|
|
|
##? Building the grammars is then a matter of running the following commands
|
|
|
|
##? from the project folder:
|
|
|
|
##?
|
2021-07-08 17:18:10 -04:00
|
|
|
##?
|
2021-06-28 17:52:38 -04:00
|
|
|
##? ./run init
|
|
|
|
##? ./run build
|
2021-06-17 17:59:08 -04:00
|
|
|
##?
|
|
|
|
##?
|
|
|
|
##? 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.
|
2021-06-28 17:52:38 -04:00
|
|
|
##?
|
2021-06-17 17:59:08 -04:00
|
|
|
|
2021-06-28 17:52:38 -04:00
|
|
|
set -e
|
2021-06-16 17:44:47 -04:00
|
|
|
cwd=$(pwd)
|
|
|
|
PATH="$cwd/node_modules/.bin:$PATH"
|
2021-06-17 17:59:08 -04:00
|
|
|
help=$(grep "^##?" "$0" | cut -c 5-)
|
2021-06-28 17:52:38 -04:00
|
|
|
eval "$(docopts -A args -h "$help" : "$@")"
|
2021-06-16 17:44:47 -04:00
|
|
|
|
|
|
|
fail() {
|
2021-06-17 17:59:08 -04:00
|
|
|
echo $help
|
2021-06-16 17:44:47 -04:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2021-06-28 17:52:38 -04:00
|
|
|
# Check for bash 4+ and set extra glob options
|
|
|
|
shopt -s globstar extglob || fail
|
2021-06-17 15:50:41 -04:00
|
|
|
|
2021-06-17 17:59:08 -04:00
|
|
|
# Check for presence of dependencies
|
2021-07-08 17:18:10 -04:00
|
|
|
if (( $(which composer jq parallel yarn | wc -l) < 4 )); then fail; fi
|
2021-06-28 17:52:38 -04:00
|
|
|
|
|
|
|
# Process the subcommand
|
|
|
|
subcmd="build"
|
|
|
|
subcmd=$([ "${args[init]}" == "true" ] && echo "init" || echo "$subcmd")
|
|
|
|
subcmd=$([ "${args[needed]}" == "true" ] && echo "needed" || echo "$subcmd")
|
2021-06-28 09:16:18 -04:00
|
|
|
|
2021-06-28 17:52:38 -04:00
|
|
|
# Grammar table of the github repository location followed by its local folder
|
|
|
|
# name
|
2021-07-08 17:18:10 -04:00
|
|
|
grammars="franzheidl/atom-applescript
|
|
|
|
atom/language-c
|
|
|
|
atom/language-coffee-script
|
|
|
|
atom/language-csharp
|
|
|
|
atom/language-css
|
|
|
|
miketheman/language-diff
|
|
|
|
atom/language-gfm
|
|
|
|
atom/language-git
|
|
|
|
atom/language-go
|
|
|
|
atom/language-html
|
|
|
|
atom/language-hyperlink
|
|
|
|
atom/language-java
|
|
|
|
atom/language-javascript
|
|
|
|
atom/language-json
|
|
|
|
atom/language-less
|
|
|
|
Azganoth/language-lua-plus
|
|
|
|
burodepeper/language-markdown
|
|
|
|
atom/language-make
|
|
|
|
atom/language-mustache
|
|
|
|
atom/language-objective-c
|
|
|
|
atom/language-perl
|
|
|
|
atom/language-php
|
|
|
|
atom/language-property-list
|
|
|
|
atom/language-python
|
|
|
|
atom/language-ruby
|
|
|
|
atom/language-ruby-on-rails
|
|
|
|
zargony/atom-language-rust
|
|
|
|
atom/language-sass
|
|
|
|
atom/language-shellscript
|
|
|
|
MaxGiting/atom-language-smarty
|
|
|
|
atom/language-sql
|
|
|
|
kelvin13/atom-swift-89
|
|
|
|
atom/language-text
|
|
|
|
atom/language-todo
|
|
|
|
al3x/atom-language-textile
|
|
|
|
atom/language-typescript
|
|
|
|
atom/language-xml
|
|
|
|
atom/language-yaml"
|
2021-06-16 17:44:47 -04:00
|
|
|
|
2021-06-28 17:52:38 -04:00
|
|
|
case $subcmd in
|
2021-06-17 23:53:47 -04:00
|
|
|
init)
|
|
|
|
yarn install
|
|
|
|
mkdir -p "$cwd"/deps
|
|
|
|
rm -rf "$cwd"/deps/*
|
|
|
|
|
|
|
|
cd "$cwd"/deps
|
2021-07-08 17:18:10 -04:00
|
|
|
printf "$grammars" | parallel "git clone --depth 1 https://github.com/{}.git"
|
|
|
|
|
2021-06-17 23:53:47 -04:00
|
|
|
cd "$cwd"
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
|
|
needed)
|
2021-07-08 17:18:10 -04:00
|
|
|
grep -Fv -f <(ls -1 "$cwd"/data/*.json | parallel "basename {} .json") <(ls -1 "$cwd"/data/*.json | parallel "jq -r '.. | select(.include | startswith(\"\$\") or startswith(\"#\") | not)? | .include?' {}" | sort | uniq | tail -n +2)
|
2021-06-17 23:53:47 -04:00
|
|
|
;;
|
|
|
|
|
|
|
|
|
2021-07-08 17:18:10 -04:00
|
|
|
build)
|
2021-06-17 17:59:08 -04:00
|
|
|
rm -rf "$cwd"/data/*
|
|
|
|
|
2021-07-08 17:18:10 -04:00
|
|
|
# Copy root non-tree-sitter cson and json grammar files to a temporary folder in
|
|
|
|
# subfolders with the repository's name.
|
2021-06-28 09:16:18 -04:00
|
|
|
temp=$(mktemp -d)
|
2021-07-08 17:18:10 -04:00
|
|
|
ls -1 "$cwd"/deps/*/grammars/!(tree-sitter-*).@(cson|json) | parallel "
|
|
|
|
folder=\"$temp/\$(basename \$(dirname \$(dirname {})))\";
|
|
|
|
mkdir -p \"\$folder\" &&
|
|
|
|
cp {} \"\$folder\"/{/}"
|
|
|
|
|
|
|
|
# Convert all cson files in the temp folder to json files
|
|
|
|
ls -1 $temp/**/*.cson | parallel "csonc --output={.}.json {} && rm {}"
|
|
|
|
# Move all json files to the root of the temp folder with the filename's being
|
|
|
|
# the scopeName property within the json files
|
|
|
|
ls -1 $temp/**/*.json | parallel "mv {} \"$temp/\$(jq -r '.scopeName' {}).json\""
|
|
|
|
# Finally, move the json files to the data folder
|
|
|
|
mv $temp/*.json "$cwd"/data/
|
|
|
|
rm -rf $temp
|
2021-06-17 17:59:08 -04:00
|
|
|
;;
|
|
|
|
esac
|