Skip to content

Commit 72c2e26

Browse files
add-practice-exercise copies templates (#9)
1 parent 2b9fecf commit 72c2e26

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ bin/configlet.exe
55
bin/latest-configlet.tar.gz
66
bin/latest-configlet.zip
77
bin/configlet.zip
8+
9+
# Lake build artifacts
10+
.lake/
11+
lake-manifest.json

bin/add-practice-exercise

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ require_files_template() {
3636
die "The '.files.${1}' array in the 'config.json' file is empty. Please add at least one file. See https://exercism.org/docs/building/tracks/config-json#h-files for more information."
3737
}
3838

39+
toPascalCase() {
40+
# "some-kebab-case-word" => "SomeKebabCaseWord"
41+
local word=${1^}
42+
while [[ ${word} =~ (.*)-(.*) ]]; do
43+
word=${BASH_REMATCH[1]}${BASH_REMATCH[2]^}
44+
done
45+
echo "${word}"
46+
}
47+
3948
required_tool jq
4049

4150
require_files_template "solution"
@@ -59,6 +68,7 @@ shift "$((OPTIND - 1))"
5968
(( $# >= 1 )) || help_and_exit
6069

6170
slug="${1}"
71+
pascal=$(toPascalCase "${slug}")
6272

6373
if [[ -z "${author}" ]]; then
6474
read -rp 'Your GitHub username: ' author
@@ -68,8 +78,12 @@ fi
6878
./bin/configlet create --practice-exercise "${slug}" --author "${author}" --difficulty "${difficulty}"
6979

7080
exercise_dir="exercises/practice/${slug}"
81+
sed -e "s#%{kebab_slug}#${slug}#g" templates/lakefile.toml | sed -e "s#%{pascal_slug}#${pascal}#g" > "${exercise_dir}/lakefile.toml"
7182
files=$(jq -r --arg dir "${exercise_dir}" '.files | to_entries | map({key: .key, value: (.value | map("'"'"'" + $dir + "/" + . + "'"'"'") | join(" and "))}) | from_entries' "${exercise_dir}/.meta/config.json")
7283

84+
cp templates/lean-toolchain "exercises/practice/${slug}/lean-toolchain"
85+
cp -r templates/vendor "exercises/practice/${slug}/vendor"
86+
7387
cat << NEXT_STEPS
7488
7589
Your next steps are:

exercises/practice/hello-world/.meta/config.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
2-
"authors": [],
2+
"authors": [
3+
"tim-br"
4+
],
35
"files": {
46
"solution": [
57
"HelloWorld.lean"

0 commit comments

Comments
 (0)