-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreasy.sh
176 lines (133 loc) · 3.47 KB
/
reasy.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/bin/sh
# Get react app name from argument
name=$1
st=1
# Function to create react app
create_react_app(){
# Check if argument is passed
if [ -z "$name" ]
then
echo "No filename passed as an argument"
st=0
return
fi
# Check if directory with same app name already exists
if [ -d "$name" ]
then
echo "Directory with name: $name already exists..."
st=0
return
fi
# Starting to create react app/
echo "Creating a react app : $name"
npx create-react-app $name
# Check if the command was a success
if [ $? -eq 0 ]
then
echo "Created react app"
return
else
echo "Failed to create react app"
fi
st=0
}
# Function to remove boilerplate src code
remove_boilerplate_src(){
# Check if previous function executed successfully
if [ $st -eq 0 ]
then
return
fi
# Starting to remove boilerplate src
echo "Removing boilerplate src code"
rm -R $name/src
# Check if the command was a success
if [ $? -eq 0 ]
then
echo "Successfully removed src code..."
return
else
echo "Failed to remove src..."
fi
st=0
}
# Function to create custom src
create_custom_src(){
# Check if previous function executed successfully
if [ $st -eq 0 ]
then
return
fi
# Begin to generate custom src code
echo "Generating custom src code...."
mkdir $name/src
# Check if the command was a success
if [ $st -neq 0 ]
then
st=0
return
fi
echo "Folder src created..."
# Hard coded the src/index.js file
# Trying to find something more interesting
echo "Creating src/index.js"
echo "import React from 'react'
import ReactDOM from 'react-dom'
import App from './App'
ReactDOM.render(<App/>,document.getElementById('root'));" > $name/src/index.js
echo "src/index.js created..."
# Hard coded the src/App.js file
# Trying to find something more interesting for this too.
echo "Creating src/App.js"
echo "import React from 'react'
export default function App(){
return(
<div>Hello World!!</div>
)
}" > $name/src/App.js
echo "Created src/App.js"
}
# Function to create the typical React app directories
init_directories(){
# Check if the previous function executed successfully
if [ $st -eq 0 ]
then
return
fi
# Begin to create the directories
echo "Creating basic directories"
mkdir $name/src/Components
# Check if the command was a success
if [ $? -eq 0 ]
then
echo "Created directory: src/Components"
else
echo "Failed to create: src/Components"
st=0
fi
mkdir $name/src/Assets
# Check if the command was a success
if [ $? -eq 0 ]
then
echo "Created directory: src/Assets"
else
echo "Failed to create : src/Assets"
st=0
fi
}
# Todo : Adding custom scripts to package.json
add_custom_scripts(){
# Check if the previous function executed successfully
if [ $st -eq 0 ]
then
return
fi
custom_scripts="\"gitpush\": \"git add . && git commit -m 'UI Build' && git push\""
echo "Adding custom script to package.json"
echo "Custom scripts added successfully..."
}
# Calling the functions in order
create_react_app
remove_boilerplate_src
create_custom_src
init_directories