Skip to content

Commit ba8a29d

Browse files
authored
bin/add-exercise script to call configlet create (#264)
1 parent f5a3925 commit ba8a29d

File tree

1 file changed

+6
-48
lines changed

1 file changed

+6
-48
lines changed

bin/add-exercise

+6-48
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,11 @@ required_tool() {
1515
die "$1 is required but not installed. Please install it and make sure it's in your PATH."
1616
}
1717
required_tool jq
18-
required_tool curl
1918

2019
[[ -f ./bin/fetch-configlet ]] || die "run this script from the repo's root directory."
2120

2221
slug="${1}"
2322

24-
# transform slug 'resistor-color-duo' to name 'Resistor Color Duo'
25-
IFS=- read -ra words <<< "${slug}"
26-
name=${words[*]^}
27-
2823
it_exists=$(
2924
jq --arg slug "${slug}" '
3025
.exercises.practice
@@ -34,54 +29,17 @@ it_exists=$(
3429
)
3530
[[ ${it_exists} == false ]] || die "${slug} already exists in config.json"
3631

37-
# Add entry for exercise in config.json
38-
./bin/fetch-configlet
39-
jq --arg slug "${slug}" \
40-
--arg uuid "$(./bin/configlet uuid)" \
41-
--arg name "${name}" \
42-
'
43-
.exercises.practice += [
44-
{
45-
slug: $slug,
46-
name: $name,
47-
uuid: $uuid,
48-
practices: [],
49-
prerequisites: [],
50-
difficulty: 1
51-
}
52-
]
53-
' config.json > config.json.tmp \
54-
&& mv config.json.tmp config.json
55-
56-
# Sync the exercise
57-
./bin/configlet sync --update --yes \
58-
--tests include \
59-
--metadata \
60-
--docs \
61-
--exercise "${slug}"
62-
63-
touch "exercises/practice/${slug}/.meta/example.jq"
64-
65-
echo '"Remove this line and implement your solution" | halt_error' > "exercises/practice/${slug}/${slug}.jq"
32+
./bin/fetch-configlet || die "cannot fetch configlet"
6633

67-
echo
6834
read -rp 'Your github username: ' author
69-
conf="exercises/practice/${slug}/.meta/config.json"
70-
jq --arg slug "${slug}" \
71-
--arg author "${author}" \
72-
'
73-
.authors = [$author] |
74-
.files = {
75-
solution: [$slug + ".jq"],
76-
test: ["test-\($slug).bats"],
77-
example: [".meta/example.jq"]
78-
}
79-
' "${conf}" > "${conf}.tmp" \
80-
&& mv "${conf}.tmp" "${conf}"
35+
36+
./bin/configlet create --practice-exercise "${slug}" --author "${author}"
37+
38+
echo '"Remove this line and implement your solution" | halt_error' > "exercises/practice/${slug}/${slug}.jq"
8139

8240
cp -pt exercises/practice/"${slug}" lib/bats-*.bash
8341

84-
./bin/generate_tests "${slug}"
42+
./bin/generate_tests "${slug}" || true
8543

8644
echo
8745
find "exercises/practice/${slug}" -type f -ls

0 commit comments

Comments
 (0)