smnbbrv / ngx-grpc

Angular gRPC framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Provide option to run same command on unix and windows based system

valerio-lucantonio opened this issue · comments

At the moment this command:
./node_modules/.bin/grpc_tools_node_protoc --proto_path=../proto/public --proto_path=../proto --plugin=protoc-gen-ng=./node_modules/.bin/protoc-gen-ng --ng_out=./src/generated ../proto/public/**/**/**/*.proto does not work on windows based machines, as it seems the plugin protoc-gen-ng works only with mac or unix OS.

The only way to run it on windows is to point to protoc-gen-ng.cmd (and of course to change the way the relative path is calculated, but this is not a problem introducing ${PWD} instead of ./ makes it also compatible with other OS).

Since we are working in a platform-agnostic team, we would like to have only one same script for the different OS we have. Would that be possible somehow?

Thanks
Valerio

Hi @valerio-lucantonio

the plugin is cross-platform. The problem is how protoc itself treats the plugins.

There are two ways of defining them:

  • command line argument (the --plugin=name=path thing)
  • globally installed plugin application

What you can do is installing the @ngx-grpc/protoc-gen-ng globally and refer to it as --plugin=protoc-gen-ng (or similar, check the protoc docs). But in this case the version of @ngx-grpc/protoc-gen-ng will be detached from the project.

What we use for windows in one of the projects is

"proto:generate:win": "for /f %G in ('dir /b ..\\proto\\*.proto') do grpc_tools_node_protoc --plugin=protoc-gen-ng=.\\node_modules\\.bin\\protoc-gen-ng.cmd --ng_out=.\\output\\path -I ..\\proto ..\\proto\\%G",

but as you pointed out you need a separate command for that.

Anyway, this is how protoc works. The plugin itself cannot fix this problem in any way. At least I don't yet know one.

There are solutions to make protoc plugins work seamlessly across platforms. For npm you can see protoc-gen-grpc-web

Hi @paulius-p

As already pointed above, the plugin works seamlessly across the platforms. It works on windows. The way it is called is a totally different story. I have nothing more to add to #25 (comment) . If you know the way to improve, please kindly share.

For npm you can see protoc-gen-grpc-web

This project has no documentation, there is no description what it does and it is not clear how it is connected to this issue. Could you please add more info?

Hey @smnbbrv, that package adds a wrapper, which downloads the appropriate binary based on platform, and runs it with the correct path, so that you don't need to adjust the binary path for different platforms. As in now for linux we're fine to use --plugin=protoc-gen-ng=./node_modules/.bin/protoc-gen-ng, but on windows you have to specify --plugin=protoc-gen-ng=./node_modules/.bin/protoc-gen-ng.cmd