forked from LIT-Protocol/js-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bun-link.sh
executable file
·96 lines (83 loc) · 2.6 KB
/
bun-link.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
#!/bin/bash
# Usage:
# -- Dry run mode
# ./bun-link.sh --dry-run
# -- Link all packages (except those ending with "-vanilla") or specific packages
# ./bun-link.sh --link
# ./bun-link.sh --link <project-directory-name1> <project-directory-name2> ...
# eg. ./bun-link.sh --link lit-node-client another-project
# -- Unlink all packages (except those ending with "-vanilla") or specific packages
# ./bun-link.sh --unlink
# ./bun-link.sh --unlink <project-directory-name1> <project-directory-name2> ...
# -- Specify base directory
# ./bun-link.sh --dir <base-directory-path>
# Define the base directory
BASE_DIR="./dist/packages"
# Flags
DRY_RUN=0
LINK=0
UNLINK=0
declare -a SPECIFIC_PACKAGES=()
# Process arguments
while [[ "$#" -gt 0 ]]; do
case $1 in
--dry-run)
DRY_RUN=1
echo "❗️ Dry run mode activated. No actual linking will be performed."
;;
--dir)
shift
BASE_DIR="$1"
;;
--link|--unlink)
if [[ $1 == "--link" ]]; then
LINK=1
else
UNLINK=1
fi
shift
while [[ "$1" && ! "$1" =~ ^-- ]]; do
SPECIFIC_PACKAGES+=("$1")
shift
done
continue # Skip the shift at the end of the loop
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
shift # Move to the next argument
done
# Function to process directories
process_directory() {
for dir in "$1"/*; do
# Check if it's a directory
if [[ -d "$dir" ]]; then
# Extract the directory name
dir_name=$(basename "$dir")
# If specific packages are provided, skip others
if [[ ${#SPECIFIC_PACKAGES[@]} -ne 0 && ! " ${SPECIFIC_PACKAGES[@]} " =~ " $dir_name " ]]; then
continue
fi
# Check if directory name does not end with "vanilla"
if [[ ! $dir_name =~ .*-vanilla$ ]]; then
echo "Processing directory: $dir_name"
# Check if dry run mode is off
if [[ $DRY_RUN -eq 0 ]]; then
if [[ $LINK -eq 1 ]]; then
cd "$dir"
bun link
cd - > /dev/null
elif [[ $UNLINK -eq 1 ]]; then
cd "$dir"
bun unlink
cd - > /dev/null
fi
fi
fi
fi
done
}
# Start processing from the base directory
process_directory "$BASE_DIR"