Repository navigation
Expand file tree
/
Copy pathwatch-pivot
More file actions
executable file
·165 lines (149 loc) · 4.06 KB
/
Copy pathwatch-pivot
File metadata and controls
executable file
·165 lines (149 loc) · 4.06 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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/bin/bash
set -euo pipefail
unset PREFIX npm_config_prefix
export NVM_DIR="${NVM_DIR:-$HOME/.nvm}"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
nvm use --delete-prefix
npx lerna bootstrap --force-local
declare -a packageNames=(
"solid-logic"
"solid-ui"
"contacts-pane"
"profile-pane"
"solid-panes"
"mashlib"
"pivot"
)
startedPids=()
buildLogs=$(mktemp -d)
buildTimeout=${WATCH_PIVOT_BUILD_TIMEOUT:-300}
if ! [[ "$buildTimeout" =~ ^[1-9][0-9]*$ ]]; then
echo "WATCH_PIVOT_BUILD_TIMEOUT must be a positive number of seconds." >&2
rmdir "$buildLogs"
exit 1
fi
function stopProcess {
local pid=$1
local child
for child in $(ps -axo pid=,ppid= | awk -v parent="$pid" '$2 == parent { print $1 }'); do
stopProcess "$child"
done
kill "$pid" 2>/dev/null || true
}
function cleanup {
for pid in "${startedPids[@]}"; do
stopProcess "$pid"
done
for package in "${packageNames[@]}"; do
rm -f "$buildLogs/$package.log"
done
rmdir "$buildLogs"
}
trap cleanup EXIT
trap 'exit 130' INT
trap 'exit 143' TERM
function matchesBuildLog {
local log=$1
local pattern=$2
# Build tools may emit ANSI colors even when FORCE_COLOR is set to zero.
sed -E $'s/\033\\[[0-9;]*[[:alpha:]]//g' "$log" | grep -E "$pattern" > /dev/null
}
function waitForBuild {
local package=$1
local pid=$2
local log=$3
local successPattern=$4
local entry=$5
local deadline=$((SECONDS + buildTimeout))
echo "Waiting for $package's initial build..."
while true; do
if matchesBuildLog "$log" 'compiled with .*errors?|error during build|Error:'; then
echo "Initial build of $package failed. Stopping started watchers." >&2
return 1
fi
if ! kill -0 "$pid" 2>/dev/null; then
echo "Package $package exited before startup completed. Stopping started watchers." >&2
return 1
fi
if matchesBuildLog "$log" "$successPattern" && [[ -s "$entry" ]]; then
echo "Initial build of $package completed."
return 0
fi
if (( SECONDS >= deadline )); then
echo "Timed out after ${buildTimeout}s waiting for $package's initial build. Stopping started watchers." >&2
return 1
fi
sleep 0.2
done
}
for package in "${packageNames[@]}"; do
# Vite's watch completion differs from the one-shot styles build's "built in" message.
successPattern='(^|] )built in [0-9]+ms\.$'
entry="workspaces/$package/dist/index.esm.js"
case "$package" in
"solid-logic")
prestart=""
start='npx concurrently --no-clear -k -n npm,styles "npm run watch"'
;;
"solid-ui")
prestart=""
start='npm run watch'
;;
"contacts-pane")
prestart=""
start='npm run watch'
;;
"profile-pane")
prestart=""
start='npm run watch'
;;
"solid-panes")
prestart=""
start='npm run watch'
;;
"mashlib")
prestart=""
start='npx concurrently --no-clear -k -n babel,types,webpack "npm run watch"'
successPattern='webpack .* compiled (successfully|with [0-9]+ warnings?)( |$)'
entry="workspaces/$package/dist/mashlib.js"
;;
"pivot")
prestart=""
start="npx community-solid-server -c ./config/dev-http-suffix.json config/customise-me.json -f ./data -p 3100 -b http://localhost:3100 -m ."
;;
*)
echo "Unknown package: $package"
exit 1
;;
esac
echo "Preparing package $package..."
(
. "$NVM_DIR/nvm.sh"
cd "workspaces/$package"
nvm use --delete-prefix
if [[ -n "$prestart" ]]; then
eval "$prestart"
fi
)
echo "Starting package $package..."
log="$buildLogs/$package.log"
: > "$log"
(
. "$NVM_DIR/nvm.sh"
cd "workspaces/$package"
nvm use --delete-prefix
FORCE_COLOR=0 eval "$start" 2>&1 | tee "$log"
) &
pid=$!
startedPids+=("$pid")
if [[ "$package" != "pivot" ]]; then
waitForBuild "$package" "$pid" "$log" "$successPattern" "$entry"
else
sleep 1
if ! kill -0 "$pid" 2>/dev/null; then
echo "Package $package failed to start. Stopping started watchers." >&2
exit 1
fi
fi
done
wait "${startedPids[@]}"