|
3 | 3 | # Exit immediately if a command exits with a non-zero status
|
4 | 4 | set -e
|
5 | 5 |
|
6 |
| -# Define the source and target directories |
7 |
| -SOURCE_DIR="schemas" |
8 |
| -TARGET_DIR="lib/basic_api/generated" |
9 |
| - |
10 |
| -# Remove the target directory if it exists |
11 |
| -if [ -d "$TARGET_DIR" ]; then |
12 |
| - echo "Removing existing directory: $TARGET_DIR" |
13 |
| - rm -rf "$TARGET_DIR" |
| 6 | +# Define the path for the submodule within the main repository |
| 7 | +SUBMODULE_PATH="binary-websocket-api" |
| 8 | +TARGET_PATH="schemas" |
| 9 | + |
| 10 | +# Create a temporary directory |
| 11 | +TEMP_DIR=$(mktemp -d) |
| 12 | + |
| 13 | +# Function to clean up the temporary directory on exit |
| 14 | +cleanup() { |
| 15 | + rm -rf "$TEMP_DIR" |
| 16 | +} |
| 17 | +trap cleanup EXIT |
| 18 | + |
| 19 | +# Clone the bom-core repository into the temporary directory |
| 20 | +git clone --depth 1 [email protected]:regentmarkets/bom-core.git "$TEMP_DIR/bom-core" |
| 21 | + |
| 22 | +# Check if the binary-websocket-api directory exists in the cloned repository |
| 23 | +if [ ! -d "$TEMP_DIR/bom-core/$SUBMODULE_PATH" ]; then |
| 24 | + echo "Directory $SUBMODULE_PATH does not exist in the bom-core repository. Aborting." |
| 25 | + exit 1 |
14 | 26 | fi
|
15 | 27 |
|
16 |
| -# Ensure the target directory exists |
17 |
| -mkdir -p "$TARGET_DIR" |
18 |
| - |
19 |
| -# Create symlinks for the JSON files |
20 |
| -find "$SOURCE_DIR" -type f \( -name 'receive.json' -o -name 'send.json' \) | while read -r file; do |
21 |
| - base=$(echo "$file" | sed "s|^$SOURCE_DIR/||") |
22 |
| - target="$TARGET_DIR/$(echo "$base" | tr '/' '_')" |
23 |
| - if [ ! -e "$target" ]; then |
24 |
| - ln -s "../../../$file" "$target" |
25 |
| - echo "Symlink created: $target -> $file" |
26 |
| - else |
27 |
| - echo "Symlink already exists: $target" |
28 |
| - fi |
29 |
| -done |
30 |
| - |
31 |
| -# Uncomment the following line if you want to copy manually added JSON files to the target directory if not already there |
32 |
| -# cp -n lib/basic_api/manually/*.json "$TARGET_DIR" |
33 |
| - |
34 |
| -# Generate lib/basic_api/generated/api.dart |
35 |
| -ls "$TARGET_DIR" | grep '\.json$' | awk '{print "export \"" $0 ".dart\";"}' > "$TARGET_DIR/api.dart" |
36 |
| -perl -pi -e 's/.json//g' "$TARGET_DIR/api.dart" |
37 |
| - |
38 |
| -echo "api.dart generated at $TARGET_DIR/api.dart" |
| 28 | +# Remove existing submodule directory if necessary |
| 29 | +if [ -d "$TARGET_PATH" ]; then |
| 30 | + echo "Removing existing directory: $TARGET_PATH" |
| 31 | + rm -rf "$TARGET_PATH" |
| 32 | +fi |
| 33 | + |
| 34 | +# Copy the binary-websocket-api directory from the temporary directory to the current directory |
| 35 | +cp -r "$TEMP_DIR/bom-core/$SUBMODULE_PATH/config/v3/" "$TARGET_PATH" |
| 36 | + |
| 37 | + |
| 38 | +echo "Submodule 'binary-websocket-api' successfully copied into the main repository." |
0 commit comments