-
Notifications
You must be signed in to change notification settings - Fork 0
/
scaffoldExpress.sh
executable file
·54 lines (42 loc) · 1.43 KB
/
scaffoldExpress.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
FOLDER="../api"
DEFAULT="insecure"
SECURE_DEFAULT="secure"
#input for directory and route category
if [[ -n $1 ]]; then
FOLDER="../$1"
fi
if [[ -n $2 ]]; then
DEFAULT=$2
fi
if [[ -n $3 ]]; then
SECURE_DEFAULT=$3
fi
#folder cleaning
if [ -d $FOLDER ]; then
echo $FOLDER
read -p "Folder exists, destroy? (Y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1
rm -r $FOLDER
fi
#makes directory and echos into the defaults
mkdir $FOLDER
if ! [ -d "$FOLDER/controllers" ]; then
mkdir $FOLDER/controllers $FOLDER/controllers/auth $FOLDER/routes $FOLDER/routes/auth $FOLDER/utils $FOLDER/views $FOLDER/middleware $FOLDER/manifest
fi
#app echo
cat ./templateAPI/app.js > $FOLDER/app.js
#insecure routes echo
cat ./templateAPI/routes/category.js > $FOLDER/routes/$DEFAULT.js
cat ./templateAPI/controllers/category.js > $FOLDER/controllers/$DEFAULT.js
#middleware echo
cat ./templateAPI/middleware/organization.js > $FOLDER/middleware/organization.js
#utils echo
cat ./templateAPI/utils/helperFunctions.js > $FOLDER/utils/helperFunctions.js
cat ./templateAPI/utils/logger.js > $FOLDER/utils/logger.js
#secure routes echo
cat ./templateAPI/routes/auth/secureCategory.js > $FOLDER/routes/auth/$SECURE_DEFAULT.js
cat ./templateAPI/controllers/auth/secureCategory.js > $FOLDER/controllers/auth/$SECURE_DEFAULT.js
#setup npm and cleanup package
cd $FOLDER
npm init -y
cp ../skeleton/templateAPI/package.json ./
npm install