Have ideas to improve npm?Join in the discussion! »

    protobuf-templates
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.6 • Public • Published

    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

    Install

    npm i protobuf-templates

    DownloadsWeekly Downloads

    2

    Version

    1.0.6

    License

    MIT

    Unpacked Size

    66 kB

    Total Files

    21

    Last publish

    Collaborators

    • avatar