-
Notifications
You must be signed in to change notification settings - Fork 8
/
dev.sh
executable file
·88 lines (65 loc) · 1.71 KB
/
dev.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
#!/bin/bash
# install deps if not exists
if [ ! -d admin/node_modules ]; then
npm ci --prefix admin
fi
if [ ! -d site/node_modules ]; then
npm ci --prefix site
fi
# check env
if [ ! -f admin/.env ]; then
cp admin/.env.example admin/.env
fi
# default token
npm run default_user --prefix admin
# start strapi
npm run develop --prefix admin &
echo "run strapi on http://localhost:1337"
# save pid of strapi
echo $! > strapi.pid
# wait for strapi to start curl it to check
echo "wait for strapi to start"
while true; do
sleep 1
echo "try curl"
curl http://localhost:1337/admin
if [ $? -eq 0 ]; then
break
fi
done
# create token for admin
# check exists .api_token
if [ ! -f admin/.api_token ]; then
echo "create token for admin"
cd admin
token=$(./create_token.sh admin@nil.foundation XYgiXDOcg4Lfpv6g)
if [ $? -eq 0 ]; then
echo $token > .api_token
else
echo "error creating token"
exit 1
fi
cd ..
fi
token=$(cat admin/.api_token)
echo Token: $token
# start site
# check exists .env
if [ ! -f site/.env ]; then
echo "create .env for site"
echo "STRAPI_API_URL=http://127.0.0.1:1337/api" >> site/.env
echo "STRAPI_URL=http://127.0.0.1:1337" >> site/.env
# add token
echo "STRAPI_API_KEY=$token" >> site/.env
echo "NEXT_PUBLIC_BASE_URL=http://localhost:3000" >> site/.env
echo "FRESHTEAM_API_URL=http://nil.freshteam.com" >> site/.env
fi
npm run build --prefix site
# run in another thread
npm run dev --prefix site &
echo "run site on http://localhost:3000"
# save pid of site
echo $! > site.pid
# wait till ctrl+c is pressed
( trap "kill $(cat strapi.pid) $(cat site.pid); exit" SIGINT ; read -r -d '' _ </dev/tty ) ## wait for Ctrl-C
echo "Press Ctrl+C to stop"