Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bin/add-exercise script to call configlet create #264

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 6 additions & 48 deletions bin/add-exercise
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,11 @@ required_tool() {
die "$1 is required but not installed. Please install it and make sure it's in your PATH."
}
required_tool jq
required_tool curl

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

slug="${1}"

# transform slug 'resistor-color-duo' to name 'Resistor Color Duo'
IFS=- read -ra words <<< "${slug}"
name=${words[*]^}

it_exists=$(
jq --arg slug "${slug}" '
.exercises.practice
Expand All @@ -34,54 +29,17 @@ it_exists=$(
)
[[ ${it_exists} == false ]] || die "${slug} already exists in config.json"

# Add entry for exercise in config.json
./bin/fetch-configlet
jq --arg slug "${slug}" \
--arg uuid "$(./bin/configlet uuid)" \
--arg name "${name}" \
'
.exercises.practice += [
{
slug: $slug,
name: $name,
uuid: $uuid,
practices: [],
prerequisites: [],
difficulty: 1
}
]
' config.json > config.json.tmp \
&& mv config.json.tmp config.json

# Sync the exercise
./bin/configlet sync --update --yes \
--tests include \
--metadata \
--docs \
--exercise "${slug}"

touch "exercises/practice/${slug}/.meta/example.jq"

echo '"Remove this line and implement your solution" | halt_error' > "exercises/practice/${slug}/${slug}.jq"
./bin/fetch-configlet || die "cannot fetch configlet"

echo
read -rp 'Your github username: ' author
conf="exercises/practice/${slug}/.meta/config.json"
jq --arg slug "${slug}" \
--arg author "${author}" \
'
.authors = [$author] |
.files = {
solution: [$slug + ".jq"],
test: ["test-\($slug).bats"],
example: [".meta/example.jq"]
}
' "${conf}" > "${conf}.tmp" \
&& mv "${conf}.tmp" "${conf}"

./bin/configlet create --practice-exercise "${slug}" --author "${author}"

echo '"Remove this line and implement your solution" | halt_error' > "exercises/practice/${slug}/${slug}.jq"

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

./bin/generate_tests "${slug}"
./bin/generate_tests "${slug}" || true

echo
find "exercises/practice/${slug}" -type f -ls
Expand Down
Loading