-
Notifications
You must be signed in to change notification settings - Fork 0
/
app-creator.sh
executable file
·103 lines (84 loc) · 2.29 KB
/
app-creator.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
#!/bin/sh
if [ -z "$APPNAME" ]; then
APPNAME='my-app'
fi
BASEDIR=$(cd "$(dirname "$0")" && pwd)
export BASEDIR
DEVCONTAINER_APP=false
if [ "$APPTYPE" = "node" ] || [ "$APPTYPE" = "rails" ]; then
DEVCONTAINER_APP=true
fi
IS_NODE_APP=false
if [ "$APPTYPE" = "node" ] || [ "$APPTYPE" = "nextjs" ] || [ "$APPTYPE" = "react" ] || [ "$APPTYPE" = "express" ]; then
IS_NODE_APP=true
fi
[ $DEVCONTAINER_APP = false ] && [ $IS_NODE_APP = true ] && FRONTEND_APP=true || FRONTEND_APP=false
if [ "$STYLING" = "styled-components" ] || [ "$STYLING" = "material-ui" ]; then
export STYLING
fi
create_app_folder() {
# In case location isn't set
if [ -z "$APPPATH" ]; then
APPPATH=$APPNAME
fi
# Create app location if it doesn't exist
if [ ! -d "$APPPATH" ]; then
mkdir -p "$APPPATH"
fi
}
installs_frontend_local_dependencies() {
if [ "$FRONTEND_APP" = true ]; then
# Installs nvm if it's not installed
if ! [ -x "$(command -v nvm)" ]; then
echo 'nvm is not installed.'
# shellcheck disable=SC1091
. "$BASEDIR/helpers/nvm-installer.sh"
echo 'nvm installed!'
fi
# Exit if nvm hasn't been successfully instaled
if [ -z "nvm -v" ]; then
echo "Error: nvm not installed correctly."
exit 1
fi
# Install lastest node version as default
echo "$NODEVERSION"
if [ -z "$NODEVERSION" ]; then
nvm install --lts
else
nvm install "$NODEVERSION"
fi
# Exit if node hasn't been successfully instaled
if [ -z "node -v" ]; then
echo "Error: node not installed correctly."
exit 2
fi
fi
}
create_env_rc_files() {
if [ "$FRONTEND_APP" = true ]; then
# Creates node-version file
if [ -e ".node-version" ]; then
rm ".node-version"
fi
NODEINSTALLED=$(command node -v)
# shellcheck disable=SC3057
touch ".node-version" && echo "${NODEINSTALLED:1}" >> .node-version
# Creates nvmrc file
if [ -e ".nvmrc" ]; then
rm ".nvmrc"
fi
NODEINSTALLED=$(command node -v)
touch ".nvmrc" && echo "$NODEINSTALLED" >> .nvmrc
fi
}
main() {
create_app_folder
installs_frontend_local_dependencies
# Installs app depending on its type
cd "$APPPATH" || exit 3
# shellcheck disable=SC1090
. "$BASEDIR/helpers/create-$APPTYPE-app.sh"
create_env_rc_files
exit 0
}
main