1.0.6 • Published 6 years ago

protobuf-templates v1.0.6

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

Protobuf Templates

Generate TypeScript code from proto files.

Circle CI npm Licence MIT

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

  • TypeScript interface
  • TypeScript abstract server class
  • 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.

  • int32, fixed32, uint32
  • int64, fixed64, uint64
  • float, double
  • bool
  • string
  • bytes
  • repeated
  • enums
  • map
  • nested types
  • google.protobuf.Any
  • google.protobuf.Timestamp
  • google.protobuf.Duration
  • google.protobuf.Empty
  • google.protobuf.Struct
  • google.protobuf.Wrapper
  • google.protobuf.FieldMask
  • google.protobuf.ListValue
  • google.protobuf.Value
  • google.protobuf.NullValue
  • Long

Features

  • package (namespaces)
  • default values
  • streaming messages
  • Any
  • Oneof