diff --git a/.bazelrc b/.bazelrc new file mode 100644 index 0000000..53505af --- /dev/null +++ b/.bazelrc @@ -0,0 +1 @@ +build --workspace_status_command=hack/workspace_status.sh \ No newline at end of file diff --git a/WORKSPACE b/WORKSPACE index 95f0862..ceddcea 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,5 +1,6 @@ workspace( name = "roleypoly", + managed_directories = {"@npm": ["node_modules"]}, ) ### BAZEL @@ -39,18 +40,22 @@ git_repository( http_archive( name = "rules_proto", - sha256 = "4d421d51f9ecfe9bf96ab23b55c6f2b809cbaf0eea24952683e397decfbd0dd0", - strip_prefix = "rules_proto-f6b8d89b90a7956f6782a4a3609b2f0eee3ce965", + sha256 = "602e7161d9195e50246177e7c55b2f39950a9cf7366f74ed5f22fd45750cd208", + strip_prefix = "rules_proto-97d8af4dc474595af3900dd85cb3a29ad28cc313", urls = [ - "https://github.com/bazelbuild/rules_proto/archive/f6b8d89b90a7956f6782a4a3609b2f0eee3ce965.tar.gz", + "https://mirror.bazel.build/github.com/bazelbuild/rules_proto/archive/97d8af4dc474595af3900dd85cb3a29ad28cc313.tar.gz", + "https://github.com/bazelbuild/rules_proto/archive/97d8af4dc474595af3900dd85cb3a29ad28cc313.tar.gz", ], ) -git_repository( - name = "rules_typescript_proto", - commit = "692cbfb909c8972250bc6b378a3c1f14f36b9c54", - remote = "https://github.com/Dig-Doug/rules_typescript_proto", - shallow_since = "1599865339 -0400", +### NODE + +load("@build_bazel_rules_nodejs//:index.bzl", "yarn_install") + +yarn_install( + name = "npm", + package_json = "//:package.json", + yarn_lock = "//:yarn.lock", ) ### PROTO @@ -60,18 +65,14 @@ rules_proto_dependencies() rules_proto_toolchains() -### NODE +### ts proto -load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories", "yarn_install") - -node_repositories( - package_json = ["//:package.json"], -) - -yarn_install( - name = "npm", - package_json = "//:package.json", - yarn_lock = "//:yarn.lock", +git_repository( + name = "rules_typescript_proto", + # branch = "test/ts_library", + commit = "34f22e81a0b1dc66de18b729bcc77e1485ded337", + remote = "https://github.com/roleypoly/rules_typescript_proto.git", + shallow_since = "1602400942 -0400", ) load("@rules_typescript_proto//:index.bzl", "rules_typescript_proto_dependencies") diff --git a/hack/tsproto.bzl b/hack/tsproto.bzl new file mode 100644 index 0000000..744d0f5 --- /dev/null +++ b/hack/tsproto.bzl @@ -0,0 +1,36 @@ +load("@rules_typescript_proto//: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"], + ) diff --git a/package.json b/package.json index 5d0c053..5481c24 100644 --- a/package.json +++ b/package.json @@ -33,8 +33,6 @@ }, "devDependencies": { "@babel/core": "^7.11.6", - "@bazel/karma": "^2.2.1", - "@bazel/labs": "^2.2.1", "@bazel/typescript": "^2.2.1", "@storybook/addon-actions": "^6.0.26", "@storybook/addon-essentials": "^6.0.26", @@ -47,7 +45,9 @@ "@types/styled-components": "5.1.4", "babel-loader": "^8.1.0", "prettier": "^2.1.2", + "protoc-gen-ts": "^0.3.4", "react-is": "^16.13.1", + "ts-protoc-gen": "^0.13.0", "tsconfig-paths-webpack-plugin": "^3.3.0", "tslint": "6.1.3", "tslint-config-prettier": "^1.18.0", @@ -55,4 +55,4 @@ "tslint-plugin-prettier": "^2.3.0", "typescript": "^4.0.3" } -} +} \ No newline at end of file diff --git a/src/rpc/auth/BUILD.bazel b/src/rpc/auth/BUILD.bazel index ea65256..ddb44f5 100644 --- a/src/rpc/auth/BUILD.bazel +++ b/src/rpc/auth/BUILD.bazel @@ -1,7 +1,7 @@ load("@rules_proto//proto:defs.bzl", "proto_library") load("@io_bazel_rules_go//go:def.bzl", "go_library") load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") -load("@rules_typescript_proto//:index.bzl", "typescript_proto_library") +load("//:hack/tsproto.bzl", "ts_proto") proto_library( name = "auth_proto", @@ -23,7 +23,6 @@ go_library( visibility = ["//visibility:public"], ) -typescript_proto_library( - name = "ts", +ts_proto( proto = ":auth_proto", ) diff --git a/src/rpc/auth/backend/BUILD.bazel b/src/rpc/auth/backend/BUILD.bazel index 2f993bd..ebf8999 100644 --- a/src/rpc/auth/backend/BUILD.bazel +++ b/src/rpc/auth/backend/BUILD.bazel @@ -1,7 +1,7 @@ load("@rules_proto//proto:defs.bzl", "proto_library") load("@io_bazel_rules_go//go:def.bzl", "go_library") load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") -load("@rules_typescript_proto//:index.bzl", "typescript_proto_library") +load("//:hack/tsproto.bzl", "ts_proto") proto_library( name = "backend_proto", @@ -32,7 +32,6 @@ go_library( visibility = ["//visibility:public"], ) -typescript_proto_library( - name = "ts", +ts_proto( proto = ":backend_proto", ) diff --git a/src/rpc/auth/client/BUILD.bazel b/src/rpc/auth/client/BUILD.bazel index b92d739..341805b 100644 --- a/src/rpc/auth/client/BUILD.bazel +++ b/src/rpc/auth/client/BUILD.bazel @@ -1,7 +1,7 @@ load("@rules_proto//proto:defs.bzl", "proto_library") load("@io_bazel_rules_go//go:def.bzl", "go_library") load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") -load("@rules_typescript_proto//:index.bzl", "typescript_proto_library") +load("//:hack/tsproto.bzl", "ts_proto") proto_library( name = "client_proto", @@ -10,7 +10,6 @@ proto_library( deps = [ "//src/rpc/auth:auth_proto", "//src/rpc/shared:shared_proto", - "@com_google_protobuf//:empty_proto", ], ) @@ -33,7 +32,6 @@ go_library( visibility = ["//visibility:public"], ) -typescript_proto_library( - name = "ts", +ts_proto( proto = ":client_proto", ) diff --git a/src/rpc/auth/client/auth-client.proto b/src/rpc/auth/client/auth-client.proto index a57a4b7..2e4aa84 100644 --- a/src/rpc/auth/client/auth-client.proto +++ b/src/rpc/auth/client/auth-client.proto @@ -4,12 +4,12 @@ package roleypoly.auth.client; option go_package = "github.com/roleypoly/roleypoly/src/auth/client"; import "src/rpc/shared/internal.proto"; -import "google/protobuf/empty.proto"; +import "src/rpc/shared/shared.proto"; import "src/rpc/auth/shared.proto"; service AuthClient { - rpc GetClientToken(google.protobuf.Empty) returns (roleypoly.auth.Token) {} - rpc GetUserSession(google.protobuf.Empty) returns (roleypoly.RoleypolySession) {} + rpc GetClientToken(roleypoly.Empty) returns (roleypoly.auth.Token) {} + rpc GetUserSession(roleypoly.Empty) returns (roleypoly.RoleypolySession) {} rpc ResolveSessionKey(roleypoly.auth.Token) returns (roleypoly.auth.Token) {} rpc AuthorizeChallenge(roleypoly.auth.AuthChallenge) returns (roleypoly.auth.Token) {} } \ No newline at end of file diff --git a/src/rpc/ctf/BUILD.bazel b/src/rpc/ctf/BUILD.bazel index ca8aeac..0e0bb7e 100644 --- a/src/rpc/ctf/BUILD.bazel +++ b/src/rpc/ctf/BUILD.bazel @@ -1,13 +1,13 @@ load("@rules_proto//proto:defs.bzl", "proto_library") load("@io_bazel_rules_go//go:def.bzl", "go_library") load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") -load("@rules_typescript_proto//:index.bzl", "typescript_proto_library") +load("//:hack/tsproto.bzl", "ts_proto") proto_library( name = "ctf_proto", srcs = ["ctf.proto"], visibility = ["//visibility:public"], - deps = ["@com_google_protobuf//:empty_proto"], + deps = ["//src/rpc/shared:shared_proto"], ) go_proto_library( @@ -16,6 +16,7 @@ go_proto_library( importpath = "github.com/roleypoly/roleypoly/src/rpc/ctf", proto = ":ctf_proto", visibility = ["//visibility:public"], + deps = ["//src/rpc/shared"], ) go_library( @@ -25,7 +26,6 @@ go_library( visibility = ["//visibility:public"], ) -typescript_proto_library( - name = "ts", +ts_proto( proto = ":ctf_proto", ) diff --git a/src/rpc/ctf/ctf.proto b/src/rpc/ctf/ctf.proto index 7ce280f..650def8 100644 --- a/src/rpc/ctf/ctf.proto +++ b/src/rpc/ctf/ctf.proto @@ -3,13 +3,13 @@ syntax = "proto3"; package roleypoly.ctf; option go_package = "github.com/roleypoly/roleypoly/src/rpc/ctf"; -import "google/protobuf/empty.proto"; +import "src/rpc/shared/shared.proto"; service CTF { rpc GetRingFlags (Ring) returns (Flags) {} rpc CreateFlag (Flag) returns (Flag) {} rpc PromoteFlag (Flag) returns (Flag) {} - rpc RemoveFlag (Flag) returns (google.protobuf.Empty) {} + rpc RemoveFlag (Flag) returns (roleypoly.Empty) {} } message Flags { diff --git a/src/rpc/discord/BUILD.bazel b/src/rpc/discord/BUILD.bazel index fa8b2d1..b85706c 100644 --- a/src/rpc/discord/BUILD.bazel +++ b/src/rpc/discord/BUILD.bazel @@ -1,16 +1,17 @@ load("@rules_proto//proto:defs.bzl", "proto_library") load("@io_bazel_rules_go//go:def.bzl", "go_library") load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") -load("@rules_typescript_proto//:index.bzl", "typescript_proto_library") +load("//:hack/tsproto.bzl", "ts_proto") + +package(default_visibility = [ + "//hack/fixtures:__subpackages__", +]) proto_library( name = "discord_proto", srcs = ["discord.proto"], visibility = ["//visibility:public"], - deps = [ - "//src/rpc/shared:shared_proto", - "@com_google_protobuf//:empty_proto", - ], + deps = ["//src/rpc/shared:shared_proto"], ) go_proto_library( @@ -29,7 +30,6 @@ go_library( visibility = ["//visibility:public"], ) -typescript_proto_library( - name = "ts", +ts_proto( proto = ":discord_proto", ) diff --git a/src/rpc/discord/discord.proto b/src/rpc/discord/discord.proto index fec6a6e..e3bf71e 100644 --- a/src/rpc/discord/discord.proto +++ b/src/rpc/discord/discord.proto @@ -3,11 +3,10 @@ syntax = "proto3"; package roleypoly.discord; option go_package = "github.com/roleypoly/roleypoly/src/rpc/discord"; -import "google/protobuf/empty.proto"; import "src/rpc/shared/shared.proto"; service Discord { - rpc ListGuilds(google.protobuf.Empty) returns (GuildList) {} + rpc ListGuilds(roleypoly.Empty) returns (GuildList) {} rpc GetGuild(roleypoly.IDQuery) returns (Guild) {} rpc GetGuildRoles(roleypoly.IDQuery) returns (GuildRoles) {} rpc GetGuildsByMember(roleypoly.IDQuery) returns (GuildList) {} @@ -17,7 +16,7 @@ service Discord { rpc UpdateMember(Member) returns (Member) {} // deprecated 4 MAR 2020 rpc UpdateMemberRoles(RoleTransaction) returns (RoleTransactionResult) {} - rpc OwnUser(google.protobuf.Empty) returns (roleypoly.DiscordUser) {} + rpc OwnUser(roleypoly.Empty) returns (roleypoly.DiscordUser) {} } message GuildMembers { diff --git a/src/rpc/platform/BUILD.bazel b/src/rpc/platform/BUILD.bazel index df12192..74ea01c 100644 --- a/src/rpc/platform/BUILD.bazel +++ b/src/rpc/platform/BUILD.bazel @@ -1,7 +1,7 @@ load("@rules_proto//proto:defs.bzl", "proto_library") load("@io_bazel_rules_go//go:def.bzl", "go_library") load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") -load("@rules_typescript_proto//:index.bzl", "typescript_proto_library") +load("//:hack/tsproto.bzl", "ts_proto") proto_library( name = "platform_proto", @@ -10,7 +10,6 @@ proto_library( deps = [ "//src/rpc/discord:discord_proto", "//src/rpc/shared:shared_proto", - "@com_google_protobuf//:empty_proto", ], ) @@ -33,7 +32,6 @@ go_library( visibility = ["//visibility:public"], ) -typescript_proto_library( - name = "ts", +ts_proto( proto = ":platform_proto", ) diff --git a/src/rpc/platform/platform.proto b/src/rpc/platform/platform.proto index 7f9cc31..2be72cb 100644 --- a/src/rpc/platform/platform.proto +++ b/src/rpc/platform/platform.proto @@ -5,15 +5,14 @@ option go_package = "github.com/roleypoly/roleypoly/src/rpc/platform"; import "src/rpc/shared/shared.proto"; import "src/rpc/discord/discord.proto"; -import "google/protobuf/empty.proto"; service Platform { - rpc EnumerateMyGuilds(google.protobuf.Empty) returns (GuildEnumeration) {} + rpc EnumerateMyGuilds(roleypoly.Empty) returns (GuildEnumeration) {} rpc GetGuildSlug(roleypoly.IDQuery) returns (roleypoly.Guild) {} rpc GetGuild(roleypoly.IDQuery) returns (PresentableGuild) {} - rpc UpdateMyRoles(UpdateRoles) returns (google.protobuf.Empty) {} - rpc UpdateGuildData(GuildData) returns (google.protobuf.Empty) {} + rpc UpdateMyRoles(UpdateRoles) returns (roleypoly.Empty) {} + rpc UpdateGuildData(GuildData) returns (roleypoly.Empty) {} } message GuildEnumeration { repeated PresentableGuild guilds = 1; } diff --git a/src/rpc/shared/BUILD.bazel b/src/rpc/shared/BUILD.bazel index 045f3cf..9c8ad13 100644 --- a/src/rpc/shared/BUILD.bazel +++ b/src/rpc/shared/BUILD.bazel @@ -1,7 +1,12 @@ load("@rules_proto//proto:defs.bzl", "proto_library") load("@io_bazel_rules_go//go:def.bzl", "go_library") load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") -load("@rules_typescript_proto//:index.bzl", "typescript_proto_library") +load("//:hack/tsproto.bzl", "ts_proto") + +package(default_visibility = [ + "//hack/fixtures:__subpackages__", + "//src/design-system/atoms/role:__subpackages__", +]) proto_library( name = "shared_proto", @@ -26,7 +31,6 @@ go_library( visibility = ["//visibility:public"], ) -typescript_proto_library( - name = "ts", +ts_proto( proto = ":shared_proto", ) diff --git a/src/rpc/shared/shared.proto b/src/rpc/shared/shared.proto index 215a407..0fe82bb 100644 --- a/src/rpc/shared/shared.proto +++ b/src/rpc/shared/shared.proto @@ -2,6 +2,8 @@ syntax = "proto3"; package roleypoly; option go_package = "github.com/roleypoly/roleypoly/src/rpc/shared"; +message Empty {} + message IDQuery { string MemberID = 1; string GuildID = 2; diff --git a/yarn.lock b/yarn.lock index e370372..75397ca 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1120,18 +1120,6 @@ resolved "https://registry.yarnpkg.com/@base2/pretty-print-object/-/pretty-print-object-1.0.0.tgz#860ce718b0b73f4009e153541faff2cb6b85d047" integrity sha512-4Th98KlMHr5+JkxfcoDT//6vY8vM+iSPrLNpHhRyLx2CFYi8e2RfqPLdpbnpo0Q5lQC5hNB79yes07zb02fvCw== -"@bazel/karma@^2.2.1": - version "2.2.1" - resolved "https://registry.yarnpkg.com/@bazel/karma/-/karma-2.2.1.tgz#f59bf39fe044940c87c5ab00cc0e0dcdfe522cd9" - integrity sha512-4rOeweI9IaQ60/T1igk6IcqmX6v+OyIQFLzieeYrb/EYs+iNirw8sZtsVjMKoZ59dA1zSjxDIVWH0yRJI/SAwQ== - dependencies: - tmp "0.1.0" - -"@bazel/labs@^2.2.1": - version "2.2.1" - resolved "https://registry.yarnpkg.com/@bazel/labs/-/labs-2.2.1.tgz#0bae2b6a053e55884a98a44ca45eccc06aa149cd" - integrity sha512-0BveUK2MqFbYFkj7sfrwDQAA8OMa/YlNNO+PReOJ8VoQZIenWl8mQO3THTtsoRWbFN7zl8S3z0CLutrb35BPmA== - "@bazel/typescript@^2.2.1": version "2.2.1" resolved "https://registry.yarnpkg.com/@bazel/typescript/-/typescript-2.2.1.tgz#46d6dcedd91a7fd0421e9286790aff94ec45bece" @@ -5782,7 +5770,7 @@ good-listener@^1.2.2: dependencies: delegate "^3.1.2" -google-protobuf@3.13.0, google-protobuf@^3.13.0: +google-protobuf@3.13.0, google-protobuf@^3.13.0, google-protobuf@^3.6.1: version "3.13.0" resolved "https://registry.yarnpkg.com/google-protobuf/-/google-protobuf-3.13.0.tgz#909c5983d75dd6101ed57c79e0528d000cdc3251" integrity sha512-ZIf3qfLFayVrPvAjeKKxO5FRF1/NwRxt6Dko+fWEMuHwHbZx8/fcaAao9b0wCM6kr8qeg2te8XTpyuvKuD9aKw== @@ -8352,6 +8340,11 @@ protobufjs@6.8.8: "@types/node" "^10.1.0" long "^4.0.0" +protoc-gen-ts@^0.3.4: + version "0.3.4" + resolved "https://registry.yarnpkg.com/protoc-gen-ts/-/protoc-gen-ts-0.3.4.tgz#231de77a9ce1b748e666d5db85a1ca933d02ca71" + integrity sha512-j2oawQXhg+xAK/FbMVHYDyyvjCpX3VdgWXIDQm/3UzzNPXGzpwCMU9r4jexr0fWccuahFPnaqQGOhY0FuOwV2g== + proxy-addr@~2.0.5: version "2.0.6" resolved "https://registry.yarnpkg.com/proxy-addr/-/proxy-addr-2.0.6.tgz#fdc2336505447d3f2f2c638ed272caf614bbb2bf" @@ -9940,13 +9933,6 @@ tinycolor2@^1.4.1: resolved "https://registry.yarnpkg.com/tinycolor2/-/tinycolor2-1.4.2.tgz#3f6a4d1071ad07676d7fa472e1fac40a719d8803" integrity sha512-vJhccZPs965sV/L2sU4oRQVAos0pQXwsvTLkWYdqJ+a8Q5kPFzJTuOFwy7UniPli44NKQGAglksjvOcpo95aZA== -tmp@0.1.0: - version "0.1.0" - resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.1.0.tgz#ee434a4e22543082e294ba6201dcc6eafefa2877" - integrity sha512-J7Z2K08jbGcdA1kkQpJSqLF6T0tdQqpR2pnSUXsIchbPdTI9v3e85cLW0d6WDhwuAleOV71j2xWs8qMPfK7nKw== - dependencies: - rimraf "^2.6.3" - tmp@^0.0.33: version "0.0.33" resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9" @@ -10053,6 +10039,13 @@ ts-pnp@^1.1.6: resolved "https://registry.yarnpkg.com/ts-pnp/-/ts-pnp-1.2.0.tgz#a500ad084b0798f1c3071af391e65912c86bca92" integrity sha512-csd+vJOb/gkzvcCHgTGSChYpy5f1/XKNsmvBGO4JXS+z1v2HobugDz4s1IeFXM3wZB44uczs+eazB5Q/ccdhQw== +ts-protoc-gen@^0.13.0: + version "0.13.0" + resolved "https://registry.yarnpkg.com/ts-protoc-gen/-/ts-protoc-gen-0.13.0.tgz#2763ae4e4a1a7d7001d53d2f3043357c691701ea" + integrity sha512-j18X4rkDBbG/ZHUJy88WFeZP6mStGow5uREaohowlHXTu3/N7WcpyPhb7Vh6wN38ERmc/AkT9gqT98+vtlRhJA== + dependencies: + google-protobuf "^3.6.1" + tsconfig-paths-webpack-plugin@^3.3.0: version "3.3.0" resolved "https://registry.yarnpkg.com/tsconfig-paths-webpack-plugin/-/tsconfig-paths-webpack-plugin-3.3.0.tgz#a7461723c20623ca9148621a5ce36532682ad2ff"