82 lines
2.4 KiB
Bash
Executable File
82 lines
2.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
scriptname=$0
|
|
|
|
help_and_exit() {
|
|
echo >&2 "Populates a new directory for a practice exercise."
|
|
echo >&2 "Usage: ${scriptname} [-h] [-a author] <exercise-slug>"
|
|
echo >&2 "Where: author is the github username of the exercise creator."
|
|
exit 1
|
|
}
|
|
|
|
die() { echo >&2 "$*"; exit 1; }
|
|
|
|
required_tool() {
|
|
command -v "$1" >/dev/null 2>&1 ||
|
|
die "$1 is required but not installed. Please install it and make sure it's in your PATH."
|
|
}
|
|
|
|
(( $# >= 1 )) || help_and_exit
|
|
|
|
required_tool jq
|
|
required_tool curl
|
|
|
|
[[ -f ./bin/fetch-configlet ]] || die "run this script from the repo's root directory."
|
|
|
|
author=''
|
|
while getopts :ha: opt; do
|
|
case $opt in
|
|
h) help_and_exit ;;
|
|
a) author=$OPTARG ;;
|
|
?) echo >&2 "Unknown option: -$OPTARG"; help_and_exit ;;
|
|
esac
|
|
done
|
|
shift "$((OPTIND - 1))"
|
|
|
|
slug="${1}"
|
|
|
|
# Create entry for exercise in config.json and exercise files
|
|
./bin/fetch-configlet
|
|
./bin/configlet create --practice-exercise "${slug}"
|
|
|
|
cp ./libs/exercism/test "exercises/practice/${slug}/libs/exercism/test"
|
|
|
|
cat << END_TEST > "exercises/practice/${slug}/test.8th"
|
|
"${slug}.8th" f:include
|
|
needs exercism/test
|
|
with: test
|
|
N tests
|
|
|
|
$(curl --silent "https://raw.githubusercontent.com/exercism/problem-specifications/main/exercises/${slug}/canonical-data.json")
|
|
|
|
end-of-tests
|
|
;with
|
|
END_TEST
|
|
|
|
if [[ -z $author ]]; then
|
|
echo
|
|
read -rp 'Your github username: ' author
|
|
fi
|
|
|
|
conf="exercises/practice/${slug}/.meta/config.json"
|
|
jq --arg author "${author}" \
|
|
'.authors = [$author]' "${conf}" > "${conf}.tmp" \
|
|
&& mv "${conf}.tmp" "${conf}"
|
|
|
|
echo
|
|
find "exercises/practice/${slug}" -type f -ls
|
|
|
|
cat << NEXT_STEPS
|
|
|
|
Your next steps are:
|
|
- Create the test suite in 'exercises/practice/${slug}/test.8th'
|
|
based on the canonical data at 'https://github.com/exercism/problem-specifications/blob/main/exercises/${slug}/canonical-data.json'
|
|
- Any test cases you don't implement, mark them in 'exercises/practice/${slug}/.meta/tests.toml' with "include = false"
|
|
- Create the example solution in 'exercises/practice/${slug}/.meta/example.8th'
|
|
- Verify the example solution by running 'bin/test-no-docker ${slug}'
|
|
- Create the stub solution in 'exercises/practice/${slug}/${slug}.8th'
|
|
- Update the 'difficulty' value for the exercise's entry in the 'config.json' file
|
|
- Validate CI using 'bin/configlet lint' and 'bin/configlet fmt'
|
|
NEXT_STEPS
|