|
1 | 1 | #!/bin/bash
|
2 | 2 |
|
3 |
| -# Exit immediately if a command exits with a non-zero status |
4 |
| -set -e |
| 3 | +# symlink files from submodule to lib/basic_api/generated |
| 4 | +ls binary-websocket-api/config/v3/**/{receive,send}.json | perl -lpe'my $base = s{^binary-websocket-api/config/v3/}{}r; my $target = "lib/basic_api/generated/" . ($base =~ s{/}{_}r); symlink "../../../$_" => $target or die "no luck with symlink on $_ - $!" unless -r $target' |
5 | 5 |
|
6 |
| -# Define the source and target directories |
7 |
| -SOURCE_DIR="schemas" |
8 |
| -TARGET_DIR="lib/basic_api/generated" |
| 6 | +# copy manually added json files to lib/basic_api/generated if not already there |
| 7 | +# cp -n lib/basic_api/manually/*.json lib/basic_api/generated |
9 | 8 |
|
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" |
14 |
| -fi |
15 |
| - |
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" |
| 9 | +# generates lib/basic_api/generated/api.dart |
| 10 | +ls lib/basic_api/generated | egrep '\.json$' | perl -lne'print qq{export "$_.dart";}' > lib/basic_api/generated/api.dart |
| 11 | +perl -pi -e 's/.json//g' lib/basic_api/generated/api.dart |
0 commit comments