protobuf-templates
v1.0.6
Published
Generate TypeScript code from proto files
Downloads
13
Maintainers
Readme
Protobuf Templates
Generate TypeScript code from proto files.
This package uses the protobufjs library to auto-generate TypeScript or JavaScript code using handlebars templates.
The package doesn't rely on the protoc
compiler and generates TypeScript code directly rather than inferring types from generated JavaScript code. This makes usage of the auto-generated code easier as it does not need to compile at the point of creation.
Example templates are included, but the user may specify their own custom templates if required.
Prerequisites
Node.js > v6.12.0, which includes npm
.
Installation
$ npm install protobuf-templates
Usage in gulp
First, import this task into your gulpfile:
let protobuf = require("protobuf-templates");
Then pipe a stream of .proto
files into the task and save the output:
gulp.task("protobuf-gen", () => {
return gulp.src(protoFiles)
.pipe(protobuf())
.pipe(gulp.dest(distDir));
});
Options
The following options are available:
template Specifies the template to use. Also accepts a path to a custom template
interface Generate a typescript interface (default)
type The target language to use
typescript Generate TypeScript code (default)
javascript Generate JavaScript code
keepCase Keeps field casing instead of converting to camel case
Implementation Status
Templates
- [x] TypeScript interface
- [x] TypeScript abstract server class
- [x] TypeScript client class
- [ ] JavaScript abstract server class
- [ ] JavaScript client class
Types
The library currently supports all of the proto3 scalar types, enums, maps and nested types.
- [x] int32, fixed32, uint32
- [x] int64, fixed64, uint64
- [x] float, double
- [x] bool
- [x] string
- [x] bytes
- [x] repeated
- [x] enums
- [x] map
- [x] nested types
- [x] google.protobuf.Any
- [x] google.protobuf.Timestamp
- [x] google.protobuf.Duration
- [x] google.protobuf.Empty
- [ ] google.protobuf.Struct
- [ ] google.protobuf.Wrapper
- [ ] google.protobuf.FieldMask
- [ ] google.protobuf.ListValue
- [ ] google.protobuf.Value
- [ ] google.protobuf.NullValue
- [ ] Long
Features
- [x] package (namespaces)
- [x] default values
- [x] streaming messages
- [ ] Any
- [ ] Oneof