1
1
#! /usr/bin/env bash
2
2
3
- # shellcheck source=/dev/null
3
+ # shellcheck source=./generator-utils/utils.sh
4
+ # shellcheck source=./generator-utils/prompts.sh
5
+ # shellcheck source=./generator-utils/templates.sh
4
6
source ./bin/generator-utils/utils.sh
5
7
source ./bin/generator-utils/prompts.sh
6
8
source ./bin/generator-utils/templates.sh
@@ -35,46 +37,45 @@ check_exercise_existence "$1"
35
37
36
38
# ==================================================
37
39
38
- SLUG=" $1 "
39
- HAS_CANONICAL_DATA=true
40
+ slug=" $1 "
40
41
# Fetch canonical data
41
- canonical_json=$( bin/fetch_canonical_data " $SLUG " )
42
+ canonical_json=$( bin/fetch_canonical_data " $slug " )
42
43
44
+ has_canonical_data=true
43
45
if [ " ${canonical_json} " == " 404: Not Found" ]; then
44
- HAS_CANONICAL_DATA =false
46
+ has_canonical_data =false
45
47
message " warning" " This exercise doesn't have canonical data"
46
48
47
49
else
48
50
echo " $canonical_json " > canonical_data.json
49
51
message " success" " Fetched canonical data successfully!"
50
52
fi
51
53
52
- UNDERSCORED_SLUG =$( dash_to_underscore " $SLUG " )
53
- EXERCISE_DIR =" exercises/practice/${SLUG } "
54
- EXERCISE_NAME =$( format_exercise_name " $SLUG " )
55
- message " info" " Using ${YELLOW }${EXERCISE_NAME }${BLUE } as a default exercise name. You can edit this later in the config.json file"
54
+ underscored_slug =$( dash_to_underscore " $slug " )
55
+ exercise_dir =" exercises/practice/${slug } "
56
+ exercise_name =$( format_exercise_name " $slug " )
57
+ message " info" " Using ${yellow }${exercise_name }${blue } as a default exercise name. You can edit this later in the config.json file"
56
58
# using default value for difficulty
57
- EXERCISE_DIFFICULTY =$( validate_difficulty_input " ${2:- $(get_exercise_difficulty)} " )
58
- message " info" " The exercise difficulty has been set to ${YELLOW }${EXERCISE_DIFFICULTY }${BLUE } . You can edit this later in the config.json file"
59
+ exercise_difficulty =$( validate_difficulty_input " ${2:- $(get_exercise_difficulty)} " )
60
+ message " info" " The exercise difficulty has been set to ${yellow }${exercise_difficulty }${blue } . You can edit this later in the config.json file"
59
61
# using default value for author
60
- AUTHOR_HANDLE=${3:- $(get_author_handle)}
61
- message " info" " Using ${YELLOW}${AUTHOR_HANDLE}${BLUE} as author's handle. You can edit this later in the 'authors' field in the ${EXERCISE_DIR} /.meta/config.json file"
62
-
63
-
64
- create_rust_files " $EXERCISE_DIR " " $SLUG " " $HAS_CANONICAL_DATA "
62
+ author_handle=${3:- $(get_author_handle)}
63
+ message " info" " Using ${yellow}${author_handle}${blue} as author's handle. You can edit this later in the 'authors' field in the ${exercise_dir} /.meta/config.json file"
65
64
65
+ create_rust_files " $exercise_dir " " $slug " " $has_canonical_data "
66
66
67
67
# ==================================================
68
68
69
- # build configlet
69
+ # Build configlet
70
70
./bin/fetch-configlet
71
71
message " success" " Fetched configlet successfully!"
72
72
73
73
# Preparing config.json
74
74
message " info" " Adding instructions and configuration files..."
75
- UUID =$( bin/configlet uuid)
75
+ uuid =$( bin/configlet uuid)
76
76
77
- jq --arg slug " $SLUG " --arg uuid " $UUID " --arg name " $EXERCISE_NAME " --arg difficulty " $EXERCISE_DIFFICULTY " \
77
+ # Add exercise-data to global config.json
78
+ jq --arg slug " $slug " --arg uuid " $uuid " --arg name " $exercise_name " --arg difficulty " $exercise_difficulty " \
78
79
' .exercises.practice += [{slug: $slug, name: $name, uuid: $uuid, practices: [], prerequisites: [], difficulty: $difficulty}]' \
79
80
config.json > config.json.tmp
80
81
# jq always rounds whole numbers, but average_run_time needs to be a float
@@ -84,18 +85,19 @@ message "success" "Added instructions and configuration files"
84
85
85
86
# Create instructions and config files
86
87
echo " Creating instructions and config files"
87
- ./bin/configlet sync --update --yes --docs --metadata --exercise " $SLUG "
88
- ./bin/configlet sync --update --yes --filepaths --exercise " $SLUG "
89
- ./bin/configlet sync --update --tests include --exercise " $SLUG "
88
+ ./bin/configlet sync --update --yes --docs --metadata --exercise " $slug "
89
+ ./bin/configlet sync --update --yes --filepaths --exercise " $slug "
90
+ ./bin/configlet sync --update --tests include --exercise " $slug "
90
91
message " success" " Created instructions and config files"
91
92
92
- META_CONFIG=" $EXERCISE_DIR " /.meta/config.json
93
- jq --arg author " $AUTHOR_HANDLE " ' .authors += [$author]' " $META_CONFIG " > " $META_CONFIG " .tmp && mv " $META_CONFIG " .tmp " $META_CONFIG "
93
+ # Push author to "authors" array in ./meta/config.json
94
+ meta_config=" $exercise_dir " /.meta/config.json
95
+ jq --arg author " $author_handle " ' .authors += [$author]' " $meta_config " > " $meta_config " .tmp && mv " $meta_config " .tmp " $meta_config "
94
96
message " success" " You've been added as the author of this exercise."
95
97
96
- sed -i " s/name = \" .*\" /name = \" $UNDERSCORED_SLUG \" /" " $EXERCISE_DIR " /Cargo.toml
98
+ sed -i " s/name = \" .*\" /name = \" $underscored_slug \" /" " $exercise_dir " /Cargo.toml
97
99
98
100
message " done" " All stub files were created."
99
101
100
102
message " info" " After implementing the solution, tests and configuration, please run:"
101
- echo " ./bin/configlet fmt --update --yes --exercise ${SLUG } "
103
+ echo " ./bin/configlet fmt --update --yes --exercise ${slug } "
0 commit comments