πββοΈ Fast Templating for Protobuf Generation with Handlebars and some Helpers
This project aims to be the simplest way to generate api, model and whatever based on protobuf for any languages. Protobuf based generation can really improve productivity of developers, and a lot of tools already exists in that way. But, it is really painful to generate custom things or create plugin with imperative languages. This is where template languages are useful. But there is another problem. After releasing and using pbhbs, I realised that every templates I did was not maintainable and this was a mess to re-create new ones. This is why this project exists.
- Developer Experience First
First, install protoc and yarn or npm
Then type:
yarn global add protoc-gen-hbs
or
npm install --global protoc-gen-hbs
protoc --hbs_out="[<template_dir>:]<out_dir>" [-I<proto_paths>...] <proto_files>..
Options:
out_dir Path where to generate output files
templates_dir Path where to store templates (default: ./templates)
proto_paths Paths where to find your protos
proto_files Proto files to use for generation
Path definition is very free to you, all you must know is that we parse it to send the right context and create the right path to generate files.
Some examples:
whatever.ext.hbs
will generatewhatever.ext
with allproto_files
as context{{file}}.ext.hbs
will generate one file byproto_files
and send the right file as context{{import}}.ext.hbs
will generate one file byimport
(don't know if it's really useful but yes it's possible){{file}}/{{message}}.ext.hbs
will generate one file bymessage
and send the message as context and<file>
as path{{file}}/{{service}}/{{rpc}}.ext.hbs
will generate one file by rpc with the right context and<file>/<service>
as path- ...
Protobuf helpers was thought as easy to use as possible
- They are all iterators
- They can take parameters as arguments to filter by name or specific field
- Parameters can be globs for strings
For helpers not related with protobuf
- All handlebars-helpers have been included
- Better string case helpers have been added too (see here)
Make PRs and have fun π»
No rules, if you see anything weird, open an issue :)
See examples directory here
This project is licensed under Apache 2.0 - see LICENSE file for details