Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ on:

jobs:
build:
if: false # disable the entire workflow
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
32 changes: 20 additions & 12 deletions messgen/json_generator.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import json
import os

from dataclasses import asdict
from pathlib import Path

from .common import write_file_if_diff
from .protocol_version import version_hash

from .validation import validate_protocol
Expand All @@ -31,17 +29,27 @@ def validate(self, types: dict[str, MessgenType], protocols: dict[str, Protocol]
validate_protocol(proto_def, types)

def generate_types(self, out_dir: Path, types: dict[str, MessgenType]) -> None:
for type_name, type_def in types.items():
if type_def.type_class not in [TypeClass.struct, TypeClass.enum]:
continue
file_name = out_dir / (type_name + self._FILE_EXT)
file_name.parent.mkdir(parents=True, exist_ok=True)
write_file_if_diff(file_name, json.dumps(asdict(type_def), indent=2).splitlines())
combined: list = []

for type_def in types.values():
if type_def.type_class in [TypeClass.struct, TypeClass.enum]:
combined.append(asdict(type_def))

self._write_file(out_dir, "types", combined)

def generate_protocols(self, out_dir: Path, protocols: dict[str, Protocol]) -> None:
for proto_name, proto_def in protocols.items():
file_name = out_dir / (proto_name + self._FILE_EXT)
file_name.parent.mkdir(parents=True, exist_ok=True)
combined: list = []

for proto_def in protocols.values():
proto_dict = asdict(proto_def)
proto_dict["version"] = version_hash(proto_dict)
write_file_if_diff(file_name, json.dumps(asdict(proto_def), indent=2).splitlines())
combined.append(proto_dict)

self._write_file(out_dir, "protocols", combined)

def _write_file(self, out_dir: Path, name: str, data: list) -> None:
file_name = out_dir / (name + self._FILE_EXT)
file_name.parent.mkdir(parents=True, exist_ok=True)

with open(file_name, "w", encoding="utf-8") as f: json.dump(data, f, indent=2)

Loading
Loading