-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-solution.sh
48 lines (36 loc) · 1.12 KB
/
create-solution.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
# script for creating a new problem in a directory with the name of the problem
# and the files index.js, index.test.js, and README.md
echo '📁 Which directory do you want to create the solution? '
read directory
# validate if the directory exists, if not, create it
if [ ! -d "$directory" ]; then
echo '📁 The directory does not exist, do you want to create it? (y/n)'
read createDirectory
if [ "$createDirectory" = "y" ]; then
mkdir "$directory"
else
echo '❌ You must create the directory'
exit 1
fi
fi
cd "$directory"
echo '🎯 What is the name of the problem? '
read problem
directoryName=$(echo "$problem" | tr ' ' '-')
mkdir "$directoryName"
cd "$directoryName"
touch "index.js"
touch "README.md"
problemNumber="${problem:0:2}"
# primera letra en mayuscula
problemName="${problem:3}"
problemName="${problemName^}"
echo "# Reto $problemNumber: $problemName" >> README.md
echo "" >> README.md
echo "## Enunciado" >> README.md
echo "" >> README.md
echo "## My solution" >> README.md
echo "" >> README.md
echo "## Explanation of my solution" >> README.md
echo '✅ The problem has been created'