-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatch_source.sh
executable file
·58 lines (48 loc) · 1.21 KB
/
watch_source.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
#!/bin/bash
# Check if fswatch is installed
if ! command -v fswatch &> /dev/null
then
echo "fswatch could not be found. Please install it first."
exit 1
fi
# Check if browser-sync is installed
if ! command -v browser-sync &> /dev/null
then
echo "browser-sync could not be found. Please install it first."
exit 1
fi
# Check if a file to watch is provided
if [ -z "$1" ]
then
echo "Usage: $0 path_to_file"
exit 1
fi
FILE_TO_WATCH=$1
WASM_FILE="${FILE_TO_WATCH%.*}.wasm"
WASM_SOURCE_JSON="wasmSource.json"
# Function to run when file changes
run_command() {
echo "File changed: $FILE_TO_WATCH"
theta $FILE_TO_WATCH
echo "{ \"wasm\": \"$WASM_FILE\" }" > $WASM_SOURCE_JSON
}
# Function to kill both processes
cleanup() {
echo "Terminating processes..."
kill $FSWATCH_PID $BROWSER_SYNC_PID
exit 0
}
# Trap SIGINT and call cleanup
trap cleanup SIGINT
# Start browser-sync to watch the corresponding .wasm file
run_command
browser-sync start --server --files "$WASM_FILE" index.html &
BROWSER_SYNC_PID=$!
# Watch the original file for changes
fswatch -o $FILE_TO_WATCH | while read -r
do
run_command
done &
FSWATCH_PID=$!
# Wait for processes to finish
wait $FSWATCH_PID $BROWSER_SYNC_PID