-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated script based on leo feedback
- Loading branch information
1 parent
1e1ed8a
commit 610fd8d
Showing
1 changed file
with
23 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,48 @@ | ||
#!/bin/bash | ||
# convient script to run the docs server. It automatically rebuilds and restarts when you change code. You just need to refresh your browser. | ||
cd "$(dirname "$0")" | ||
WATCH_PATH="." | ||
START_SERVER_CMD="make develop-docs-comprehensive" | ||
|
||
while true; do | ||
$START_SERVER_CMD & | ||
SERVER_PID=$! | ||
|
||
echo "Server started with PID: $SERVER_PID" | ||
echo "Server started" | ||
|
||
echo "Waiting for 15 seconds before starting to watch for file changes..." | ||
sleep 15 | ||
|
||
if [[ "$OSTYPE" == "darwin"* ]]; then | ||
fswatch -1 --exclude 'docs/static/api-reference-docs' --exclude 'build/' --exclude '/docs/.docusaurus' --exclude 'changes.log' --exclude 'docs/node_modules/.cache/webpack' --exclude '.git/' $WATCH_PATH | tee -a changes.log | ||
CHANGED_FILE=$(fswatch -1 --exclude 'docs/static/api-reference-docs' --exclude 'build/' --exclude '/docs/.docusaurus' --exclude 'changes.log' --exclude 'docs/node_modules/.cache/webpack' --exclude '.git/' $WATCH_PATH) | ||
echo "Detected changes in: $CHANGED_FILE" | ||
else | ||
echo "OS not supported" | ||
exit 1 | ||
fi | ||
|
||
echo "Code changed. Attempting to kill server with PID: $SERVER_PID..." | ||
|
||
# Attempt to kill the npm process directly. | ||
pkill -f "npm" | ||
sleep 2 | ||
|
||
if pgrep -f "npm" > /dev/null; then | ||
echo "WARNING: npm process is still running!" | ||
# If npm process is still running, try killing it harder | ||
pkill -9 -f "npm" | ||
echo "Code changed. Attempting to kill server on port 3000..." | ||
|
||
# Send SIGTERM to the process listening on port 3000 | ||
lsof -ti:3000 | xargs kill | ||
|
||
# Wait for a bit to give the process a chance to shut down gracefully | ||
sleep 5 | ||
|
||
# Check if any process is still listening on port 3000 | ||
if lsof -ti:3000 > /dev/null; then | ||
echo "Process didn't shut down gracefully. Force killing..." | ||
lsof -ti:3000 | xargs kill -9 | ||
sleep 2 | ||
if pgrep -f "npm" > /dev/null; then | ||
echo "ERROR: Unable to kill the npm process. Exiting..." | ||
exit 1 | ||
|
||
# Final check | ||
if lsof -ti:3000 > /dev/null; then | ||
echo "ERROR: Unable to kill the process running on port 3000. Exiting..." | ||
exit 1 | ||
fi | ||
fi | ||
fi | ||
|
||
|
||
# Additional sleep to ensure port is released before restarting the server. | ||
echo "Waiting for an additional 5 seconds before restarting server..." | ||
sleep 5 | ||
|
||
# Clear the log file to avoid reading old changes | ||
> changes.log | ||
|
||
done |