From f4d7227c081c6a4da2d9e91f2dc1d6ba7640f445 Mon Sep 17 00:00:00 2001 From: Isaac Good Date: Tue, 27 Oct 2026 22:32:27 -0700 Subject: [PATCH] Add a helper script to sort the config.json practice exercises --- CONTRIBUTING.md | 6 +++--- bin/sort_exercises | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) create mode 100755 bin/sort_exercises diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8b69f01a..37a39ddd 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -15,16 +15,16 @@ Maintainers are happy to interact with humans; maintainers are not interested in ``` # Use the configlet to set things up. $ ./bin/fetch-configlet -$ ./bin/configlet create --practice-exercise $slug -a $author -d $difficulty +$ ./bin/configlet create --practice-exercise "${slug}" -a "${author}" -d "${difficulty}" # Sort `config.json`. -$ sorted=$( jq ' (.exercises.practice |= sort_by(.slug)) | .exercises.practice |= sort_by(.difficulty)' config.json ) && echo "$sorted" > config.json +$ ./bin/sort_exercises # Add the test runner. $ ./bin/update_test_runner # It's recommended you copy a .meta/template.j2 from another exercise as a starting point. # Edit the template file and use it to regenerate tests. The problem spec repo should be updated at least once. $ ./bin/generate_tests [--no-pull] # Solve the exercise and validate by running the tests. -$ ( cd exercises/practice/$slug && bash run_tests; ) +$ ( cd "exercises/practice/${slug}" && bash run_tests; ) ``` ### Error handling diff --git a/bin/sort_exercises b/bin/sort_exercises new file mode 100755 index 00000000..4a2ced11 --- /dev/null +++ b/bin/sort_exercises @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +self=$(readlink -e "$0") +bin=${self%/*} + +# shellcheck disable=SC1091 +. "${bin}/utils.bash" + +config="${REPO_ROOT}/config.json" + +sorted=$( jq ' + (.exercises.practice |= sort_by(.name | ascii_downcase)) | + .exercises.practice |= sort_by(.difficulty) +' "${config}" ) +printf '%s\n' "${sorted}" > "${config}"