-
-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathadd-exercise
executable file
·38 lines (30 loc) · 1.2 KB
/
add-exercise
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env bash
set -euo pipefail
if [ $# -ne 1 ]; then
echo "Usage: bin/add-exercise <exercise-slug>"
exit 1
fi
command -v jq >/dev/null 2>&1 || {
echo >&2 "jq is required but not installed. Please install it and make sure it's in your PATH."
exit 1
}
command -v curl >/dev/null 2>&1 || {
echo >&2 "curl is required but not installed. Please install it and make sure it's in your PATH."
exit 1
}
bin/fetch-configlet
# Add entry for exercise in config.json
slug="${1}"
# shellcheck disable=SC2001
name=$(echo "${slug}" | sed 's/\b\w/\u&/g')
uuid=$(bin/configlet uuid)
jq --arg slug "${slug}" --arg uuid "${uuid}" --arg name "${name}" \
'.exercises.practice += [{slug: $slug, name: $name, uuid: $uuid, practices: [], prerequisites: [], difficulty: 1}]' \
config.json | sed 's/"average_run_time": 5/"average_run_time": 5.0/' > config.json.tmp && mv config.json.tmp config.json
# Sync the exercise
bin/configlet sync --update --yes --tests include --filepaths --metadata --docs --exercise "${slug}"
exercise_dir="exercises/practice/${slug}"
exercise_files=$(jq -r '.files[][]' "${exercise_dir}/.meta/config.json")
for file in ${exercise_files}; do
touch "${exercise_dir}/${file}"
done