chore: restructure bazel macros

This commit is contained in:
41666 2020-10-15 00:51:53 -04:00
parent a33aa3841c
commit a0b4392b05
54 changed files with 80 additions and 56 deletions

36
hack/bazel/js/proto.bzl Normal file
View file

@ -0,0 +1,36 @@
load("//src/ts-protoc-gen/rules:index.bzl", "typescript_proto_library")
load("@npm//@bazel/typescript:index.bzl", "ts_library")
def _generalize_pb_imports(name, srcs = [], grpc = False):
suffix_match = "pb"
if grpc:
suffix_match = ""
native.genrule(
name = name,
srcs = srcs,
outs = ["index.ts"],
cmd = """
echo $(SRCS) | tr ' ' '\n' | grep '""" + suffix_match + """\\.js$$' | xargs -l1 -I '{}' basename {} .js | xargs -l1 -I'{}' echo 'export * from "./{}"' > $(location index.ts)
""",
output_to_bindir = True,
)
def ts_proto(proto, name = "ts", grpc = False):
typescript_proto_library(
name = name + "_proto",
proto = proto,
visibility = ["//visibility:public"],
)
_generalize_pb_imports(
grpc = grpc,
name = name + "_proto_generalized",
srcs = [":" + name + "_proto"],
)
ts_library(
name = name,
srcs = [":" + name + "_proto_generalized"],
deps = [":" + name + "_proto"],
visibility = ["//visibility:public"],
)