|
16 | 16 | # |
17 | 17 |
|
18 | 18 | package(default_visibility = ["//visibility:public"]) |
19 | | -load("@stackb_rules_proto//node:node_grpc_compile.bzl", "node_grpc_compile") |
20 | 19 | load("@graknlabs_dependencies//tool/checkstyle:rules.bzl", "checkstyle_test") |
| 20 | +load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm", "nodejs_binary") |
| 21 | +load("@graknlabs_bazel_distribution//npm:rules.bzl", "assemble_npm", "deploy_npm") |
| 22 | +load("@graknlabs_dependencies//distribution:deployment.bzl", "deployment") |
| 23 | +load("//:deployment.bzl", github_deployment = "deployment") |
21 | 24 |
|
22 | | -node_grpc_compile( |
| 25 | + |
| 26 | +nodejs_binary( |
| 27 | + name = "grpc_tools_node_protoc", |
| 28 | + data = ["@npm//grpc-tools:grpc-tools"], |
| 29 | + entry_point = "@npm//:node_modules/grpc-tools/bin/protoc.js", |
| 30 | + templated_args = ["--nobazel_node_patches"], |
| 31 | +) |
| 32 | + |
| 33 | +nodejs_binary( |
| 34 | + name = "protoc-gen-ts", |
| 35 | + data = ["@npm//grpc_tools_node_protoc_ts:grpc_tools_node_protoc_ts"], |
| 36 | + entry_point = "@npm//:node_modules/grpc_tools_node_protoc_ts/bin/protoc-gen-ts", |
| 37 | + templated_args = ["--nobazel_node_patches"], |
| 38 | +) |
| 39 | + |
| 40 | + |
| 41 | +genrule( |
23 | 42 | name = "protocol", |
| 43 | + outs = [ |
| 44 | + "protobuf/answer_pb.d.ts", |
| 45 | + "protobuf/answer_pb.js", |
| 46 | + "protobuf/concept_pb.d.ts", |
| 47 | + "protobuf/concept_pb.js", |
| 48 | + "protobuf/database_pb.d.ts", |
| 49 | + "protobuf/database_pb.js", |
| 50 | + "protobuf/grakn_pb.d.ts", |
| 51 | + "protobuf/grakn_pb.js", |
| 52 | + "protobuf/grakn_grpc_pb.js", |
| 53 | + "protobuf/grakn_grpc_pb.d.ts", |
| 54 | + "protobuf/options_pb.d.ts", |
| 55 | + "protobuf/options_pb.js", |
| 56 | + "protobuf/query_pb.d.ts", |
| 57 | + "protobuf/query_pb.js", |
| 58 | + "protobuf/session_pb.d.ts", |
| 59 | + "protobuf/session_pb.js", |
| 60 | + "protobuf/transaction_pb.d.ts", |
| 61 | + "protobuf/transaction_pb.js", |
| 62 | + ], |
| 63 | + # The below command performs a protoc compilation of our proto files into typescript and javascript. Line by line: |
| 64 | + # Symlink the node modules required by the typescript plugin into the directory the command will be run from |
| 65 | + # Run the node.js protoc (protocol compiler) with the following flags: |
| 66 | + # Use the gen-ts plugin to generate typescript declaration files in addition to javascript |
| 67 | + # Output javascript with commonjs style exports, to the genrule output directory. |
| 68 | + # Output services to the genrule output directory (without this line, grakn_grpc_pb is omitted) |
| 69 | + # Output typescript to (you guessed it) the genrule output directory |
| 70 | + # Set the .proto file relative path to the WORKSPACE this command is being run from |
| 71 | + # Use the .proto files found in the :proto-raw-buffers filegroup as inputs. |
| 72 | + cmd = "ln -s $(execpath //grpc/nodejs:protoc-gen-ts).runfiles/npm/node_modules ./node_modules ;\ |
| 73 | + $(execpath //grpc/nodejs:grpc_tools_node_protoc) \ |
| 74 | + --plugin='protoc-gen-ts=$(rootpath @npm//:node_modules/grpc_tools_node_protoc_ts/bin/protoc-gen-ts)' \ |
| 75 | + --js_out='import_style=commonjs,binary:./$(@D)/' \ |
| 76 | + --grpc_out='grpc_js:./$(@D)/' \ |
| 77 | + --ts_out='grpc_js:./$(@D)/' \ |
| 78 | + --proto_path=`dirname $(execpath //:WORKSPACE)` \ |
| 79 | + $(execpaths //protobuf:proto-raw-buffers);", |
| 80 | + # Dependencies for the above command. the //:WORKSPACE label is required to locate the relative path for the .proto files so they can import each other. |
| 81 | + tools = [ |
| 82 | + "//grpc/nodejs:grpc_tools_node_protoc", |
| 83 | + "//grpc/nodejs:protoc-gen-ts", |
| 84 | + "@npm//:node_modules/grpc_tools_node_protoc_ts/bin/protoc-gen-ts", |
| 85 | + "@npm//grpc_tools_node_protoc_ts", |
| 86 | + "@npm//google-protobuf", |
| 87 | + "//protobuf:proto-raw-buffers", |
| 88 | + "//:WORKSPACE" |
| 89 | + ], |
| 90 | +) |
| 91 | + |
| 92 | +pkg_npm( |
| 93 | + name = "protocol-package", |
| 94 | + package_name = "graknlabs_protocol", |
| 95 | + srcs = glob([ |
| 96 | + "package.json", |
| 97 | + ]), |
24 | 98 | deps = [ |
25 | | - "//protobuf:answer-proto", |
26 | | - "//protobuf:concept-proto", |
27 | | - "//protobuf:database-proto", |
28 | | - "//protobuf:grakn-proto", |
29 | | - "//protobuf:options-proto", |
30 | | - "//protobuf:query-proto", |
31 | | - "//protobuf:session-proto", |
32 | | - "//protobuf:transaction-proto", |
33 | | - ] |
| 99 | + ":protocol", |
| 100 | + ], |
| 101 | +) |
| 102 | + |
| 103 | +assemble_npm( |
| 104 | + name = "assemble-npm", |
| 105 | + target = ":protocol-package", |
| 106 | +) |
| 107 | + |
| 108 | +deploy_npm( |
| 109 | + name = "deploy-npm", |
| 110 | + target = ":assemble-npm", |
| 111 | + snapshot = deployment["npm.snapshot"], |
| 112 | + release = deployment["npm.release"], |
34 | 113 | ) |
35 | 114 |
|
36 | 115 | checkstyle_test( |
37 | 116 | name = "checkstyle", |
38 | 117 | include = glob(["*"]), |
| 118 | + exclude = ["package.json"], |
39 | 119 | license_type = "agpl", |
40 | 120 | size = "small", |
41 | 121 | ) |
0 commit comments