forked from temporalio/documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make.sh
executable file
·102 lines (86 loc) · 2.71 KB
/
make.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
#!/bin/bash
# My adaptation of Patrick's script
cleanup() {
read -p "Shut down workers? (Y/n)" -n 1 yn
if [[ -z $yn ]]; then yn="Y"; fi
if [[ $yn =~ [Yy].* ]]; then
pkill "temporal" > /dev/null 2>&1
pkill "worker.js" > /dev/null 2>&1
pkill "npm" > /dev/null 2>&1 # Fixed: Use "npm" instead of "npm run serve"
fi
exit 0
}
# Handle SIGINT
trap 'echo "^C detected. Cleaning up"; cleanup' SIGINT
# Pre-requisite: dprint
if ! command -v dprint > /dev/null 2>&1; then # Fixed: Use command -v instead of which
echo "Missing: required 'dprint' utility."; exit 0
else
echo "Required 'dprint' utility: Available"
fi
# Linux and Window Installs
if command -v temporal > /dev/null 2>&1; then # Fixed: Use command -v instead of which
echo "Temporal command-line tool: Available"
else
echo "Temporal CLI not found. Installing..."
case "$(uname -s)" in
Linux*|Darwin*)
curl -sSf https://temporal.download/cli.sh | sh ;;
MINGW*|CYGWIN*|MSYS*)
echo "Run 'scoop install temporal-cli'" \
"from your Windows environment."; exit 1 ;;
*)
echo "Unsupported OS for automatic installation."
exit 1 ;;
esac
fi
# Start Temporal CLI server
if pgrep "temporal" >/dev/null; then
echo "Temporal development server: Running."
else
echo "Starting Temporal CLI server"
temporal server start-dev > /dev/null 2>&1 &
sleep 1
fi
# Check or start Worker.js
if pgrep "worker.js" >/dev/null; then
echo "Background worker.js: Running"
else
echo "Background worker.js: Starting"
pushd assembly > /dev/null 2>&1
yarn > /dev/null 2>&1 && node ./worker.js > /dev/null 2>&1 &
popd > /dev/null 2>&1
fi
echo "Docs assembly: Starting"
node ./assemble.js
yarn format
echo "Docs assembly: Complete"
# Serve the site?
echo; echo "[Optional Web Service]"
read -p "Serve the site (N/y)? " yn
if [[ -z $yn ]]; then yn="N"; fi
if [[ $yn =~ [Nn].* ]]; then cleanup; fi
echo "Site: Building. May take several moments."
pushd websites/docs.temporal.io > /dev/null 2>&1
yarn && yarn build
echo "Site: Serving"
default_port=3000
port=$default_port
# Check if the default port is in use
while nc -z localhost $port >/dev/null 2>&1; do
port=$((port + 1))
done
# Serve the site on the available port
yarn serve --port $port >/dev/null 2>&1 &
popd > /dev/null 2>&1
if [ "$port" -ne "$default_port" ]; then
echo "The default port $default_port is in use. Serving the site on port $port instead."
else
echo "The site is being served on the default port $default_port."
fi
while true; do
read -p "Finished viewing site (Y/n)? " -n 1 yn
if [[ -z $yn ]]; then yn="Y"; fi
if [[ $yn =~ [Yy].* ]]; then break; fi
done
cleanup