Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grpc-tools: add grpc_js param to grpc_out #1380

Merged
merged 1 commit into from
May 11, 2020
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
3 changes: 2 additions & 1 deletion packages/grpc-tools/src/node_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ void PrintService(const ServiceDescriptor* service, Printer* out,
void PrintImports(const FileDescriptor* file, Printer* out,
const Parameters& params) {
if (!params.generate_package_definition) {
out->Print("var grpc = require('grpc');\n");
grpc::string package = params.grpc_js ? "@grpc/grpc-js" : "grpc";
out->Print("var grpc = require('$package$');\n", "package", package);
}
if (file->message_type_count() > 0) {
grpc::string file_path =
Expand Down
2 changes: 2 additions & 0 deletions packages/grpc-tools/src/node_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ namespace grpc_node_generator {
struct Parameters {
// Generate a package definition object instead of Client classes
bool generate_package_definition;
// Use pure JavaScript gRPC Client
bool grpc_js;
};

grpc::string GenerateFile(const grpc::protobuf::FileDescriptor* file,
Expand Down
9 changes: 6 additions & 3 deletions packages/grpc-tools/src/node_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@ class NodeGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
grpc::string* error) const {
grpc_node_generator::Parameters generator_parameters;
generator_parameters.generate_package_definition = false;
generator_parameters.grpc_js = false;
if (!parameter.empty()) {
std::vector<grpc::string> parameters_list =
grpc_generator::tokenize(parameter, ",");
for (auto parameter_string = parameters_list.begin();
std::vector<grpc::string> parameters_list =
grpc_generator::tokenize(parameter, ",");
for (auto parameter_string = parameters_list.begin();
parameter_string != parameters_list.end(); parameter_string++) {
if (*parameter_string == "generate_package_definition") {
generator_parameters.generate_package_definition = true;
} else if (*parameter_string == "grpc_js") {
generator_parameters.grpc_js = true;
}
}
}
Expand Down