node package manager

ts-protoc-gen

ts-protoc-gen

Protoc Plugin for TypeScript Declarations

Master Build NPM Apache 2.0 License quality: alpha

This repository contains a protoc plugin that generates TypeScript declarations (.d.ts files) that match the JavaScript output of protoc --js_out=import_style=commonjs,binary. This plugin can also output service definitions as .ts files in the structure required by grpc-web.

This repository also contains a plugin for generating service definitions as .js files in the structure required by grpc-web.

TypeScript Usage (with services)

  • Install this repository using npm install ts-protoc-gen or clone this repository and run npm install && npm run build
  • Invoke protoc with:
    • --plugin - define where the plugin needed for ts_out can be found
    • --js_out - the standard argument to protoc that generates .js files in the specified directory
    • --ts_out - the params and directory to output to (service=true enables outputting .ts files for services).
      • This directory must match js_out
      protoc \
      --plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts \
      --js_out=import_style=commonjs,binary:generated \
      --ts_out=service=true:generated \
      -I ./proto \
      proto/*.proto
      

JavaScript Service Usage

  • Install this repository using npm install ts-protoc-gen or clone this repository and run npm install && npm run build
  • Invoke protoc with:
    • --plugin - define where the plugin needed for js_service_out can be found
    • --js_out - the standard argument to protoc that generates .js files in the specified directory
    • --js_service_out - define the directory to output the service definitions to.
      • This directory must match js_out
      protoc \
      --plugin=protoc-gen-js_service=./node_modules/.bin/protoc-gen-js_service \
      --js_out=import_style=commonjs,binary:generated \
      --js_service_out=generated \
      -I ./proto \
      proto/*.proto
      
      
      

TODO

  • Add tests for extensions