mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-06-16 01:29:09 +00:00
chore: restructure bazel macros
This commit is contained in:
parent
a33aa3841c
commit
a0b4392b05
54 changed files with 80 additions and 56 deletions
1
hack/bazel/BUILD.bazel
Normal file
1
hack/bazel/BUILD.bazel
Normal file
|
@ -0,0 +1 @@
|
|||
package(default_visibility = ["//visibility:public"])
|
1
hack/bazel/docker/BUILD.bazel
Normal file
1
hack/bazel/docker/BUILD.bazel
Normal file
|
@ -0,0 +1 @@
|
|||
package(default_visibility = ["//visibility:public"])
|
17
hack/bazel/docker/publish.bzl
Normal file
17
hack/bazel/docker/publish.bzl
Normal file
|
@ -0,0 +1,17 @@
|
|||
load("@io_bazel_rules_docker//container:container.bzl", "container_push")
|
||||
|
||||
def publish(
|
||||
service,
|
||||
name = "+publish",
|
||||
image = ":image",
|
||||
prefix = "roleypoly/roleypoly/",
|
||||
registry = "docker.pkg.github.com",
|
||||
):
|
||||
container_push(
|
||||
name = name,
|
||||
format = "Docker",
|
||||
image = image,
|
||||
registry = registry,
|
||||
repository = prefix + service,
|
||||
tag = "{STABLE_URL_SAFE_TAG}",
|
||||
)
|
1
hack/bazel/js/BUILD.bazel
Normal file
1
hack/bazel/js/BUILD.bazel
Normal file
|
@ -0,0 +1 @@
|
|||
package(default_visibility = ["//visibility:public"])
|
58
hack/bazel/js/jest.bzl
Normal file
58
hack/bazel/js/jest.bzl
Normal file
|
@ -0,0 +1,58 @@
|
|||
# Copied from https://github.com/bazelbuild/rules_nodejs/blob/stable/examples/jest/jest.bzl
|
||||
# Licensed under Apache-2.0, modifications made:
|
||||
# - improved dependency resolution
|
||||
|
||||
load("@npm//jest-cli:index.bzl", "jest", _jest_test = "jest_test")
|
||||
load("//hack/bazel:utils.bzl", "render_deps")
|
||||
|
||||
DEFAULT_DEPS = [
|
||||
"@npm//ts-jest",
|
||||
"@npm//enzyme",
|
||||
"@npm//enzyme-adapter-react-16",
|
||||
"@npm//@types/enzyme",
|
||||
"@npm//jest-environment-enzyme",
|
||||
"@npm//jsdom",
|
||||
"@npm//jest",
|
||||
"@npm//jest-enzyme",
|
||||
"@npm//jest-styled-components",
|
||||
"@npm//enzyme-to-json",
|
||||
"@npm//react-dom",
|
||||
"@npm//@types/react-dom",
|
||||
"//:tsconfig.json",
|
||||
]
|
||||
|
||||
def _impl_jest_test(name, srcs, deps, jest_config, **kwargs):
|
||||
"A macro around the autogenerated jest_test rule"
|
||||
templated_args = [
|
||||
"--no-cache",
|
||||
"--no-watchman",
|
||||
"--ci",
|
||||
"--no-colors",
|
||||
]
|
||||
templated_args.extend(["--config", "$(rootpath %s)" % jest_config])
|
||||
for src in srcs:
|
||||
templated_args.extend(["--runTestsByPath", "$(rootpath %s)" % src])
|
||||
|
||||
data = [jest_config] + srcs + deps + ["//:jest-reporter.js"]
|
||||
_jest_test(
|
||||
name = name,
|
||||
data = data,
|
||||
templated_args = templated_args,
|
||||
**kwargs
|
||||
)
|
||||
|
||||
# This rule is used specifically to update snapshots via `bazel run`
|
||||
jest(
|
||||
name = "%s.update" % name,
|
||||
data = data,
|
||||
templated_args = templated_args + ["-u"],
|
||||
**kwargs
|
||||
)
|
||||
|
||||
def jest_test(src, deps = []):
|
||||
_impl_jest_test(
|
||||
name = src[1:] + "_test",
|
||||
srcs = native.glob(["*.spec.ts", "*.spec.tsx"]),
|
||||
deps = [src] + render_deps(deps) + DEFAULT_DEPS,
|
||||
jest_config = "//:jest.config.js",
|
||||
)
|
36
hack/bazel/js/proto.bzl
Normal file
36
hack/bazel/js/proto.bzl
Normal 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"],
|
||||
)
|
20
hack/bazel/js/react.bzl
Normal file
20
hack/bazel/js/react.bzl
Normal file
|
@ -0,0 +1,20 @@
|
|||
load("@npm//@bazel/typescript:index.bzl", "ts_library")
|
||||
load("//hack/bazel:utils.bzl", "render_deps")
|
||||
|
||||
def react_library(name, deps = [], **kwargs):
|
||||
ts_library(
|
||||
name = name,
|
||||
srcs = native.glob(
|
||||
[
|
||||
"*.ts",
|
||||
"*.tsx",
|
||||
],
|
||||
exclude = native.glob([
|
||||
"*.spec.ts*",
|
||||
"*.story.tsx",
|
||||
"*.stories.tsx",
|
||||
]),
|
||||
),
|
||||
deps = render_deps(deps),
|
||||
**kwargs
|
||||
)
|
22
hack/bazel/utils.bzl
Normal file
22
hack/bazel/utils.bzl
Normal file
|
@ -0,0 +1,22 @@
|
|||
def render_deps(deps = []):
|
||||
output_deps = []
|
||||
|
||||
has_added_grpc_deps = False
|
||||
|
||||
for dep in deps:
|
||||
if dep.startswith("//src/rpc"):
|
||||
output_deps.append(dep + ":ts")
|
||||
output_deps.append(dep + ":ts_proto")
|
||||
if has_added_grpc_deps == False:
|
||||
output_deps.extend([
|
||||
"@npm//google-protobuf",
|
||||
"@npm//@types/google-protobuf",
|
||||
"@npm//@improbable-eng/grpc-web",
|
||||
])
|
||||
has_added_grpc_deps = True
|
||||
elif dep.startswith("//") or dep.startswith("@npm//"):
|
||||
output_deps.append(dep)
|
||||
else:
|
||||
output_deps.append("@npm//" + dep)
|
||||
|
||||
return output_deps
|
Loading…
Add table
Add a link
Reference in a new issue