Skip to content

Commit bc9c2cb

Browse files
committed
Refactor: Update scripts to fetch schemas from bom core
1 parent 909a787 commit bc9c2cb

File tree

5 files changed

+90
-35
lines changed

5 files changed

+90
-35
lines changed

Diff for: .gitmodules

-4
This file was deleted.

Diff for: Makefile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.PHONY: help update_schemas setup
2+
3+
help:
4+
@echo "update_schemas - Update the schemas"
5+
@echo "setup - Generate dart code from the schemas"
6+
7+
update_schemas:
8+
./update_schemas.sh
9+
10+
setup:
11+
./setup.sh

Diff for: README.md

+7-24
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ $ cd flutter-deriv-api
108108
$ flutter pub get
109109
```
110110

111+
### Setup
112+
```bash
113+
$ make update_schemas
114+
$ make setup
115+
$ dart run build_runner build --delete-conflicting-outputs
116+
```
117+
111118
### Use this package as a library
112119

113120
Add this to your package's `pubspec.yaml` file:
@@ -121,30 +128,6 @@ dependencies:
121128
ref: master
122129
```
123130

124-
### Use this package as a submodule
125-
126-
```
127-
$ git submodule add https://github.com/regentmarkets/flutter-deriv-api.git
128-
```
129-
130-
Add this to your package's `pubspec.yaml` file:
131-
132-
```
133-
dependencies:
134-
...
135-
flutter_deriv_api:
136-
path: ./flutter-deriv-api/
137-
```
138-
139-
### Initialize and update submodule
140-
141-
```
142-
$ git submodule init
143-
$ git submodule update --remote
144-
$ ./setup.sh
145-
$ dart run build_runner build --delete-conflicting-outputs
146-
```
147-
148131
### Run the tests
149132

150133
```

Diff for: setup.sh

+34-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,38 @@
11
#!/bin/bash
22

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'
3+
# Exit immediately if a command exits with a non-zero status
4+
set -e
55

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
6+
# Define the source and target directories
7+
SOURCE_DIR="schemas"
8+
TARGET_DIR="lib/basic_api/generated"
89

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
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"

Diff for: update_schemas.sh

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
# Exit immediately if a command exits with a non-zero status
4+
set -e
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"
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"

0 commit comments

Comments
 (0)