protoc-gen-stmp

command
v0.0.0-...-7f180d0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 14, 2020 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

protoc-gen-stmp is a plugin for the Google protocol buffer compiler to generate stmp relative code, supported languages: golang and javascript.

To use protoc-gen-stmp, you need to build the project and put the result to your path, the most simple way is run the command with go:

go get -u github.com/acrazing/stmp-go/protoc-gen-stmp

For golang, protoc-gen-stmp dependents on any one go code generate, such as protoc-gen-go, or protoc-gen-gogo, you can choose according to your preference. the emitted file name ends with `.stmp.go`, and the path is same to `protoc-gen-go`, if with the output configuration. There is no custom options for emit go code. for example, with protoc-gen-go:

protoc --go_out=$GOPATH/src --stmp_out=lang=go:$GOPATH/src ./pb/*.proto

For javascript, protoc-gen-stmp supports emit .js and .d.ts for TypeScript. It dependents on protobufjs (https://www.npmjs.com/package/protobufjs). Like protobufjs, protoc-gen-stmp merges all input .proto files to one file, the file name is specified by custom option js.out. We recommend you to let the file name ends with .stmp.js. At the same time, protoc-gen-stmp will emit types declaration file automatically, the file name is replace the end of the js.out with .d.ts. For example:

pbjs -o ./pb/chat.pb.js ./pb/*.proto
pbts -o ./pb/chat.pb.d.ts ./pb/chat.pb.js
protoc --stmp_out=lang=js,js.pb=./pb/chat.pb.js,js.out=./pb/chat.stmp.js:. ./pb/*.proto

As the example upon, protoc-gen-stmp supports some custom options for javascript, includes:

js.pb: string,               required, the pbjs emitted file path relative to current directory
js.out: string,              required, the output file path relative to the current directory
js.dts: "" | "0",            optional, if set as "0", will not emit .d.ts file
js.module: "esm" | "cjs",    optional, the module kind, default is "esm", you can set as "cjs" to run the generated code in Node.js directly
js.root: string,             optional, the root namespace name, default is "stmp", it is useful for avoid .d.ts ns conflict

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL