diff --git a/CodeLanguagesContainer.xcframework.zip b/CodeLanguagesContainer.xcframework.zip index d4bdf52..052a89c 100644 Binary files a/CodeLanguagesContainer.xcframework.zip and b/CodeLanguagesContainer.xcframework.zip differ diff --git a/Sources/CodeEditLanguages/Documentation.docc/Add-Languages.md b/Sources/CodeEditLanguages/Documentation.docc/Add-Languages.md index 37a71b5..cdda5e8 100644 --- a/Sources/CodeEditLanguages/Documentation.docc/Add-Languages.md +++ b/Sources/CodeEditLanguages/Documentation.docc/Add-Languages.md @@ -117,6 +117,10 @@ In order to add a language to ``CodeEditLanguages`` you need to open the `.xcode ```bash $ ./build_framework.sh ``` + > Note: To run the script, you need to install `jq` by downloading it [here](https://stedolan.github.io/jq/) or with Homebrew using: + > ```bash + > $ brew install jq + > ``` 5. Check the output of the script. It should say `Done!` at the end. ![build_framework.sh console output](build-output) diff --git a/Sources/CodeEditLanguages/Documentation.docc/Update-Languages.md b/Sources/CodeEditLanguages/Documentation.docc/Update-Languages.md index 72a5a49..aa4079b 100644 --- a/Sources/CodeEditLanguages/Documentation.docc/Update-Languages.md +++ b/Sources/CodeEditLanguages/Documentation.docc/Update-Languages.md @@ -32,6 +32,11 @@ From time to time the `tree-sitter` languages need to be updated to their latest ```bash $ ./build_framework.sh ``` + > Note: To run the script, you need to install `jq` by downloading it [here](https://stedolan.github.io/jq/) or with Homebrew using: + > ```bash + > $ brew install jq + > ``` + > Note: This script automatically removes old artifacts and replaces them with the new ones. 3. Check the console output. It should say `Done!` at the end. diff --git a/build_framework.sh b/build_framework.sh index 39e37cc..ca1d821 100755 --- a/build_framework.sh +++ b/build_framework.sh @@ -13,7 +13,7 @@ # convenience function to print a status message in green status () { local GREEN='\033[0;32m' - local NC='\033[0m' # No Color + local NC='\033[0m' # No Color echo "${GREEN}◆ $1${NC}" } @@ -75,21 +75,69 @@ RESOURCES_PATH="$PWD/Sources/CodeEditLanguages/Resources" status "Copying language queries to package resources..." rm -rf "$RESOURCES_PATH" -# find and copy language queries +# find and copy language queries LIST=$( echo $CHECKOUTS_PATH/tree-* ) +OLD_PWD="$PWD" + for lang in $LIST ; do - name=${lang##*/} - mkdir -p $RESOURCES_PATH/$name - highlights=$( find $lang -type f -name "*.scm" ) - for highlight in $highlights ; do - highlight_name=${highlight##*/} - cp $highlight $RESOURCES_PATH/$name/$highlight_name + # determine how many targets a given package has + cd $lang + + # get package info as JSON + manifest=$(swift package dump-package) + + # use jq to get the target path + targets=$(echo $manifest | jq -r '.targets[].path') + + # use jq to count number of targets + count=$(echo $manifest | jq '.targets | length') + + # Determine if target paths are all '.' + same=1 + for target in $targets; do + if [[ $target != "." ]]; then + same=0 + break + fi + done + + # loop through targets + for target in $targets; do + name=${lang##*/} + + # if there is only one target, use name + # otherwise use target + if [[ $count -eq 1 || ($count -ne 1 && $same -eq 1) ]]; then + mkdir -p $RESOURCES_PATH/$name + else + mkdir -p $RESOURCES_PATH/$target + fi + + highlights=$( find $lang/$target -type f -name "*.scm" ) + for highlight in $highlights ; do + highlight_name=${highlight##*/} + + # if there is only one target, use name + # otherwise use target + if [[ $count -eq 1 || ($count -ne 1 && $same -eq 1) ]]; then + cp $highlight $RESOURCES_PATH/$name/$highlight_name + else + cp $highlight $RESOURCES_PATH/$target/$highlight_name + fi + done + + # If target paths are all '.', break out of loop + if [[ $same -eq 1 || ($count -ne 1 && $same -eq 1) ]]; then + break + fi done done status "Language queries copied to package resources!" -# cleanup derived derived data +# cleanup derived derived data + +cd $OLD_PWD if [ -d "$PWD/DerivedData" ]; then status "Cleaning up DerivedData..."