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