-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrun.sh
More file actions
69 lines (68 loc) · 1.7 KB
/
run.sh
File metadata and controls
69 lines (68 loc) · 1.7 KB
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
#!/bin/bash
# wasnt made by me dont remember where this was from.
RED="\e[31m"
GREEN="\e[32m"
YELLOW="\e[33m"
BLUE="\e[34m"
RESET="\e[0m"
log() {
echo -e "${BLUE}[INFO]${RESET} $1"
}
ok() {
echo -e "${GREEN}[OK]${RESET} $1"
}
warn() {
echo -e "${YELLOW}[WARN]${RESET} $1"
}
err() {
echo -e "${RED}[ERROR]${RESET} $1"
}
if ! command -v node > /dev/null 2>&1; then
err "Node.js is not installed!"
echo -e "${YELLOW}Download it here:${RESET} https://nodejs.org"
exit 1
fi
ok "Node.js found."
REQUIRED_VERSION=18
NODE_MAJOR=$(node -v | sed 's/v\([0-9]\+\).*/\1/')
if [ "$NODE_MAJOR" -lt "$REQUIRED_VERSION" ]; then
err "Node version $NODE_MAJOR detected, but $REQUIRED_VERSION or higher required!"
exit 1
fi
ok "Node version $(node -v) is compatible."
if ! command -v npm > /dev/null 2>&1; then
err "npm not found!"
echo -e "${YELLOW}Please install npm.${RESET}"
exit 1
fi
ok "npm found."
if [ ! -f package.json ]; then
warn "No package.json found!"
warn "Skipping dependency installation."
else
if [ ! -d node_modules ]; then
warn "node_modules missing - installing packages..."
npm install
ok "Packages installed!"
else
log "node_modules exists - checking integrity..."
if ! npm ls >/dev/null 2>&1; then
warn "Dependency tree broken - reinstalling clean!"
rm -rf node_modules package-lock.json
npm install
ok "Packages reinstalled successfully."
else
ok "Dependencies look good."
fi
fi
fi
log "Starting..."
echo ""
node app.js
EXIT_CODE=$?
if [ $EXIT_CODE -ne 0 ]; then
err "App exited with code $EXIT_CODE"
exit $EXIT_CODE
else
ok "App finished"
fi