-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·66 lines (53 loc) · 1.19 KB
/
setup.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
#!/usr/bin/env bash
set -ex
if [ ! $(command -v npm) ]
then
echo "Error: npm is not installed. Please install npm first."
exit 1
fi
BASEDIR=$(dirname $(realpath $0))
cd $BASEDIR
# Write .env file from .env.development
if [ -f .env ]
then
rm .env
fi
while IFS= read -r line
do
# Skip empty lines or comments
if [[ -z "$line" || ${line:0:1} == '#' ]]
then
continue
fi
name=${line%%=*}
value=${line#*=}
if [[ -v "$name" ]]
then
echo "$name=${!name}" >> .env
else
echo "$name=$value" >> .env
fi
done < .env.development
# If dotenv schema is not updated, remove the file
if [ -f backend/.env ] && grep -q DATABASE_URL backend/.env
then
rm backend/.env
fi
# If .env does not exist, create one
if [ ! -f backend/.env ]
then
echo "JWT_SECRET=$(head -c 64 /dev/urandom | LC_ALL=C tr -dc A-Za-z0-9 | sha256sum | head -c 64)" >> backend/.env
fi
npm install -g pnpm@latest
pnpm install
pnpm install -g prisma
# Apply database migration
for i in {1..5}
do
pnpm --filter backend exec prisma migrate dev && break # break if migration succeed
echo -e '\n⚠️ Failed to migrate. Waiting for db to be ready...\n'
sleep 5
done
# Allow direnv
cd $BASEDIR
direnv allow