From 703dcbd0b394bb5dc30b0ba596fe06482c895ca1 Mon Sep 17 00:00:00 2001 From: einhorn_b Date: Thu, 16 Nov 2023 14:25:43 +0100 Subject: [PATCH] update locales check sorting script with fix option --- admin/scripts/sort.sh | 15 +++++++-------- backend/scripts/sort.sh | 15 +++++++-------- frontend/scripts/sort.sh | 15 +++++++-------- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/admin/scripts/sort.sh b/admin/scripts/sort.sh index e5c5c41c6..d24307d7c 100755 --- a/admin/scripts/sort.sh +++ b/admin/scripts/sort.sh @@ -2,24 +2,23 @@ ROOT_DIR=$(dirname "$0")/.. -tmp=$(mktemp) exit_code=0 for locale_file in $ROOT_DIR/src/locales/*.json do - jq -f $(dirname "$0")/sort_filter.jq $locale_file > "$tmp" + jq -M 'to_entries | sort_by(.key) | from_entries' "$locale_file" > tmp.json + if [ "$*" == "--fix" ] then - mv "$tmp" $locale_file + mv tmp.json "$locale_file" else - if diff -q "$tmp" $locale_file > /dev/null ; + if ! diff -q tmp.json "$locale_file" > /dev/null ; then - : # all good - else - exit_code=$? - echo "$(basename -- $locale_file) is not sorted by keys" + exit_code=1 + echo "$(basename -- "$locale_file") is not sorted by keys" fi fi done +rm -f tmp.json exit $exit_code diff --git a/backend/scripts/sort.sh b/backend/scripts/sort.sh index e5c5c41c6..d24307d7c 100755 --- a/backend/scripts/sort.sh +++ b/backend/scripts/sort.sh @@ -2,24 +2,23 @@ ROOT_DIR=$(dirname "$0")/.. -tmp=$(mktemp) exit_code=0 for locale_file in $ROOT_DIR/src/locales/*.json do - jq -f $(dirname "$0")/sort_filter.jq $locale_file > "$tmp" + jq -M 'to_entries | sort_by(.key) | from_entries' "$locale_file" > tmp.json + if [ "$*" == "--fix" ] then - mv "$tmp" $locale_file + mv tmp.json "$locale_file" else - if diff -q "$tmp" $locale_file > /dev/null ; + if ! diff -q tmp.json "$locale_file" > /dev/null ; then - : # all good - else - exit_code=$? - echo "$(basename -- $locale_file) is not sorted by keys" + exit_code=1 + echo "$(basename -- "$locale_file") is not sorted by keys" fi fi done +rm -f tmp.json exit $exit_code diff --git a/frontend/scripts/sort.sh b/frontend/scripts/sort.sh index e5c5c41c6..d24307d7c 100755 --- a/frontend/scripts/sort.sh +++ b/frontend/scripts/sort.sh @@ -2,24 +2,23 @@ ROOT_DIR=$(dirname "$0")/.. -tmp=$(mktemp) exit_code=0 for locale_file in $ROOT_DIR/src/locales/*.json do - jq -f $(dirname "$0")/sort_filter.jq $locale_file > "$tmp" + jq -M 'to_entries | sort_by(.key) | from_entries' "$locale_file" > tmp.json + if [ "$*" == "--fix" ] then - mv "$tmp" $locale_file + mv tmp.json "$locale_file" else - if diff -q "$tmp" $locale_file > /dev/null ; + if ! diff -q tmp.json "$locale_file" > /dev/null ; then - : # all good - else - exit_code=$? - echo "$(basename -- $locale_file) is not sorted by keys" + exit_code=1 + echo "$(basename -- "$locale_file") is not sorted by keys" fi fi done +rm -f tmp.json exit $exit_code