-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.sh
61 lines (51 loc) · 2.03 KB
/
init.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
#!/bin/bash
# Browser Version
PREFIX="[🚀 (LJAS) init.sh]"
echo "${PREFIX} Starting the initialization script..."
# Navigate to script directory just in case working directory is not the same
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd $SCRIPT_DIR
# Read possible CLI flags
while [ $# -gt 0 ] ; do
case $1 in
--install-playwright) INSTALL_PLAYWRIGHT=true ;;
--skip-env-file) SKIP_ENV_FILE=true ;;
--skip-npm-ci) SKIP_NPM_CI=true ;;
esac
shift
done
if [ "$SKIP_ENV_FILE" != "true" ]; then
# Create .env file if it doesn't already exist
if [ -f ".env.example" ]; then
if [ ! -f ".env" ]; then
cp .env.example .env
echo "${PREFIX} New .env file was created."
else
echo "${PREFIX} Existing .env file was found, so skip the .env creation process."
fi
elif [ ! -f ".env" ]; then
echo ".env file could not be created because .env.example was not found."
fi
fi
if [ "$SKIP_NPM_CI" != "true" ]; then
if [ "${NODE_ENV}" == "production" ]; then
# Always install npm dependencies if the environment is production
echo "${PREFIX} Installing production npm dependencies..."
npm ci
echo "${PREFIX} npm dependency installation completed!"
elif [ -d "./node_modules" ]; then
echo "${PREFIX} The node_modules directory already exists, so skip npm dependency installation."
else
# Install npm dependencies if node_modules doesn't exist and environment is not production
echo "${PREFIX} Installing all npm dependencies..."
npm ci
echo "${PREFIX} npm dependency installation completed!"
fi
fi
if [ "$INSTALL_PLAYWRIGHT" == "true" ]; then
# Install Playwright browser binaries and dependencies
echo "${PREFIX} Installing Playwright browser binaries and dependencies..."
npm run test:e2e:install
echo "${PREFIX} Playwright browser binary and dependency installation completed!"
fi
echo "${PREFIX} Initialization script completed!"