-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwatchman
More file actions
executable file
·67 lines (55 loc) · 1.91 KB
/
watchman
File metadata and controls
executable file
·67 lines (55 loc) · 1.91 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
#!/bin/bash
# Function to handle the argument
handle_argument() {
case $1 in
upstream)
echo "Watching lambda for upstream..."
# Add your commands for "upstream" here
;;
midstream)
echo "Watching lambda for midstream..."
# Add your commands for "midstream" here
;;
downstream)
echo "Watching lambda for downstream..."
# Add your commands for "downstream" here
;;
*)
echo "Invalid argument. Please provide one of the following arguments: upstream, midstream, downstream."
exit 1
;;
esac
}
# Function to watch a directory and build the binary on every file change
watch_and_build() {
# Function name
FUNC_NAME=$1
# Watchman configuration
WATCHMAN_CONFIG=".watchmanconfig"
# Create a Watchman configuration file if it doesn't exist
if [ ! -f "$WATCHMAN_CONFIG" ]; then
echo "{}" > "$WATCHMAN_CONFIG"
fi
# Build the binary once before starting the loop
GOOS=linux GOARCH=amd64 go build -C ./lambda/src/$FUNC_NAME -o ../../dist/$FUNC_NAME/bootstrap
# Start watching the directory
watchman watch "lambda/src/$FUNC_NAME"
# Loop indefinitely
while true; do
# Wait for changes
watchman-wait "lambda/src/$FUNC_NAME" -p '*.go'
# Trigger a build after changes
sh -c "GOOS=linux GOARCH=amd64 go build -C ./lambda/src/$FUNC_NAME -o ../../dist/$FUNC_NAME/bootstrap && echo 'compilation done'"
# Add a sleep to allow for easy script exit
sleep 1
done
}
# Check if an argument was provided
if [ $# -eq 0 ]; then
echo "No arguments provided. Please provide one of the following arguments: upstream, midstream, downstream."
exit 1
fi
# Handle the argument
handle_argument $1
# Watch the directory and build the binary on every file change
watch_and_build $1