Skip to content

Commit c3d6fbf

Browse files
committed
[ADD] a bash script to allow the user to create a react app of their choice based on the options available as of writing the script
1 parent 463c2e2 commit c3d6fbf

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/bin/bash
2+
##
3+
## EPITECH PROJECT, 2024
4+
## epickup
5+
## File description:
6+
## create_react_app.sh
7+
##
8+
9+
TRUE=0
10+
FALSE=1
11+
12+
function check_npm_installed {
13+
npm --version 1>/dev/null 2>&1
14+
15+
if [ $? -ne 0 ]; then
16+
echo "npm could not be found"
17+
return $FALSE
18+
fi
19+
return $TRUE
20+
}
21+
22+
function check_npx_installed {
23+
npx --version 1>/dev/null 2>&1
24+
25+
if [ $? -ne 0 ]; then
26+
echo "npx could not be found"
27+
return $FALSE
28+
fi
29+
return $TRUE
30+
}
31+
32+
function check_node_installed {
33+
node --version 1>/dev/null 2>&1
34+
35+
if [ $? -ne 0 ]; then
36+
echo "node could not be found"
37+
return $FALSE
38+
fi
39+
return $TRUE
40+
}
41+
42+
echo "Checking ressources..."
43+
check_node_installed
44+
if [ $? -eq $FALSE ]; then
45+
echo "Please install node"
46+
exit 1
47+
fi
48+
49+
check_npm_installed
50+
if [ $? -eq $FALSE ]; then
51+
echo "Please install npm"
52+
exit 1
53+
fi
54+
55+
check_npx_installed
56+
if [ $? -eq $FALSE ]; then
57+
echo "npx is not installed, installing it..."
58+
sudo npm install -g npx
59+
fi
60+
61+
echo -n "app name: "
62+
read -r appname
63+
64+
echo -n "App type, [(n)ext/(r)eact/(e)xpo]: "
65+
read -r choice
66+
if [ "$choice" = "n" ]; then
67+
echo "Next.js"
68+
npx create-next-app@latest $appname .
69+
elif [ "$choice" = "r" ]; then
70+
echo "React"
71+
npx create-react-router@latest $appname .
72+
elif [ "$choice" = "e" ]; then
73+
echo "Expo"
74+
npx npx create-expo-app@latest $appname .
75+
else
76+
echo "Invalid choice"
77+
exit 1
78+
fi
79+
80+
if [ -d $appname ]; then
81+
echo "App created"
82+
echo "Entering $appname directory..."
83+
cd $appname
84+
echo "Installing dependencies..."
85+
npm install
86+
echo "Building app..."
87+
npm run build
88+
echo "App built"
89+
echo "The app is ready to be worked on"
90+
exit 0
91+
else
92+
echo "App not created"
93+
exit 1
94+
fi

0 commit comments

Comments
 (0)