# protobuf-templates

> Generate TypeScript code from proto files

Latest version **1.0.6** (published 2018-05-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install protobuf-templates
pnpm add protobuf-templates
yarn add protobuf-templates
bun add protobuf-templates
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2018-05-13 |
| First published | 2018-05-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=6.12.0 |
| Dependencies | 5 |
| Unpacked size | 64.5 KB |
| Known vulnerabilities | 0 (+11 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Rob Moran |
| Maintainers | thegecko |
| Keywords | protobuf, proto, protoc, protobufjs, template, templates, typescript, ts, gulp |

## Links

- npm: https://www.npmjs.com/package/protobuf-templates
- Repository: https://github.com/thegecko/protobuf-templates
- Issues: https://github.com/thegecko/protobuf-templates/issues
- npm.io page: https://npm.io/package/protobuf-templates

## Dependencies (5)

- [through2](https://npm.io/package/through2.md) ^2.0.3
- [handlebars](https://npm.io/package/handlebars.md) ^4.0.11
- [protobufjs](https://npm.io/package/protobufjs.md) ^6.8.6
- [plugin-error](https://npm.io/package/plugin-error.md) ^1.0.1
- [bufferstreams](https://npm.io/package/bufferstreams.md) ^2.0.1

## Alternatives

- [csv-to-markdown-table](https://npm.io/package/csv-to-markdown-table.md) — 47.0K weekly downloads
- [@sapphire/ratelimits](https://npm.io/package/@sapphire/ratelimits.md) — 4.4K weekly downloads
- [js-csvparser](https://npm.io/package/js-csvparser.md) — 2.0K weekly downloads
- [@adadapted/js-sdk](https://npm.io/package/@adadapted/js-sdk.md) — 251 weekly downloads
- [@grapecity/spread-sheets-sparklines](https://npm.io/package/@grapecity/spread-sheets-sparklines.md) — 103 weekly downloads

## Recent versions

- 1.0.6 (latest) — 2018-05-13
- 1.0.5 — 2018-05-11
- 1.0.4 — 2018-05-09
- 1.0.3 — 2018-05-06
- 1.0.2 — 2018-05-06
- 1.0.1 — 2018-05-06
- 1.0.0 — 2018-05-06

## README

# Protobuf Templates
Generate TypeScript code from proto files.

[![Circle CI](https://circleci.com/gh/thegecko/protobuf-templates.svg?style=shield)](https://circleci.com/gh/thegecko/protobuf-templates/)
[![npm](https://img.shields.io/npm/dm/protobuf-templates.svg)](https://www.npmjs.com/package/protobuf-templates)
[![Licence MIT](https://img.shields.io/badge/licence-MIT-blue.svg)](http://opensource.org/licenses/MIT)

This package uses the [protobufjs](http://dcode.io/protobuf.js) library to auto-generate TypeScript or JavaScript code using [handlebars](https://handlebarsjs.com/) 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](https://nodejs.org), which includes `npm`.

## Installation

```bash
$ npm install protobuf-templates
```

## Usage in gulp

First, import this task into your gulpfile:

```javascript
let protobuf = require("protobuf-templates");
```

Then pipe a stream of `.proto` files into the task and save the output:

```javascript
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](https://developers.google.com/protocol-buffers/docs/proto3#scalar), [enums](https://developers.google.com/protocol-buffers/docs/proto#enum), [maps](https://developers.google.com/protocol-buffers/docs/proto3#maps) and [nested types](https://developers.google.com/protocol-buffers/docs/proto3#nested).

- [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

---
_Source: https://npm.io/package/protobuf-templates · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
