-
Notifications
You must be signed in to change notification settings - Fork 11
/
submit-authored-solutions
executable file
·62 lines (47 loc) · 1.71 KB
/
submit-authored-solutions
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env bash
# Synopsis:
# Submit a track's authored exercises that haven't been submitted yet.
# Example:
# bin/add-practice-exercise prolog
scriptname=$0
help_and_exit() {
echo >&2 "Submit a track's authored exercises that haven't been submitted yet"
echo >&2 "Usage: ${scriptname} <track-slug>"
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."
}
required_tool jq
(( $# >= 1 )) || help_and_exit
track_slug="${1}"
track_dir="${HOME}/exercism/tracks/${track_slug}"
track_solutions_dir="${HOME}/solutions/${track_slug}"
pushd "${track_dir}" > /dev/null
git sync
popd > /dev/null
mkdir -p "${track_solutions_dir}"
for exercise_dir in "${track_dir}"/exercises/practice/*; do
meta_config_file="${exercise_dir}"/.meta/config.json
if jq -e '.authors | map(ascii_downcase) | index("erikschierboom")' "${meta_config_file}" > /dev/null; then
exercise_slug=$(basename "${exercise_dir}")
solution_dir="${track_solutions_dir}/${exercise_slug}"
if [[ -d "${solution_dir}" ]]; then
echo "Skipping ${solution_dir} as it already exists"
continue
fi
exercism download --exercise="${exercise_slug}" --track="${track_slug}"
pushd "${solution_dir}" > /dev/null
jq -c '[.files.solution, .files.example] | transpose | map({src: .[1], dst: .[0]}) | .[]' "${meta_config_file}" \
| while read -r src_and_dst; do
src=$(jq -r '.src' <<< "${src_and_dst}")
dst=$(jq -r '.dst' <<< "${src_and_dst}")
cp "${exercise_dir}/${src}" "${solution_dir}/${dst}"
done
exercise
sleep 12
popd > /dev/null
fi
done