{"id":13740446,"url":"https://github.com/90dy/protoc-gen-hbs","last_synced_at":"2025-05-08T20:31:20.953Z","repository":{"id":65476072,"uuid":"259442199","full_name":"90dy/protoc-gen-hbs","owner":"90dy","description":"🏃‍♀️ Fast Templating for Protobuf Generation with Handlebars and some Helpers","archived":false,"fork":false,"pushed_at":"2023-07-23T09:32:40.000Z","size":160,"stargazers_count":9,"open_issues_count":8,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-19T14:17:04.779Z","etag":null,"topics":["codegen","easy-to-use","handlebars","protobuf","protoc"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/90dy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-04-27T20:18:58.000Z","updated_at":"2023-09-20T14:26:51.000Z","dependencies_parsed_at":"2023-08-19T10:15:45.134Z","dependency_job_id":null,"html_url":"https://github.com/90dy/protoc-gen-hbs","commit_stats":null,"previous_names":["gponsinet/protoc-gen-hbs"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/90dy%2Fprotoc-gen-hbs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/90dy%2Fprotoc-gen-hbs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/90dy%2Fprotoc-gen-hbs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/90dy%2Fprotoc-gen-hbs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/90dy","download_url":"https://codeload.github.com/90dy/protoc-gen-hbs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253144668,"owners_count":21861100,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["codegen","easy-to-use","handlebars","protobuf","protoc"],"created_at":"2024-08-03T04:00:47.968Z","updated_at":"2025-05-08T20:31:20.608Z","avatar_url":"https://github.com/90dy.png","language":"JavaScript","funding_links":[],"categories":["Tools"],"sub_categories":["Other"],"readme":"# protoc-gen-hbs\n\n🏃‍♀️ Fast Templating for Protobuf Generation with Handlebars and some Helpers\n\n## Why ?\n\nThis project aims to be the simplest way to generate api, model and whatever based on protobuf for any languages.\nProtobuf based generation can really improve productivity of developers, and a lot of tools already exists in that way.\nBut, it is really painful to generate custom things or create plugin with imperative languages.\nThis is where template languages are useful.\nBut there is another problem.\nAfter releasing and using [pbhbs](https://github.com/gponsinet/pbhbs), I realised that every templates I did was not maintainable and this was a mess to re-create new ones.\nThis is why this project exists.\n\n## Philosophy\n\n* Developer Experience First\n\n## Installation\n\nFirst, install [protoc](http://google.github.io/proto-lens/installing-protoc.html) and [yarn](https://yarnpkg.com/en/docs/install) or [npm](https://www.npmjs.com/get-npm)\n\nThen type:\n\n```bash\nyarn global add protoc-gen-hbs\n```\n\nor\n\n```bash\nnpm install --global protoc-gen-hbs\n```\n\n## Usage\n\n### CLI\n\n```\nprotoc --hbs_out=\"[\u003ctemplate_dir\u003e:]\u003cout_dir\u003e\" [-I\u003cproto_paths\u003e...] \u003cproto_files\u003e..\n\nOptions:\n  out_dir         Path where to generate output files\n  templates_dir   Path where to store templates (default: ./templates)\n  proto_paths     Paths where to find your protos\n  proto_files     Proto files to use for generation\n```\n\n### Templates\n\n#### Paths Definition\n\nPath 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.\n\nSome examples:\n\n* `whatever.ext.hbs` will generate `whatever.ext` with all `proto_files` as context\n* `{{file}}.ext.hbs` will generate one file by `proto_files` and send the right file as context\n* `{{import}}.ext.hbs` will generate one file by `import` (don't know if it's really useful but yes it's possible)\n* `{{file}}/{{message}}.ext.hbs` will generate one file by `message` and send the message as context and `\u003cfile\u003e` as path\n* `{{file}}/{{service}}/{{rpc}}.ext.hbs` will generate one file by rpc with the right context and `\u003cfile\u003e/\u003cservice\u003e` as path\n* ...\n\n### Helpers\n\n#### Protobuf\n\nProtobuf helpers was thought as easy to use as possible\n* They are all iterators\n* They can take parameters as arguments to filter by name or specific field\n* Parameters can be globs for strings\n\n##### [{{file}}](templates/examples/file.ts.hbs)\n\n```handlebars\n{{#file}}\n  {{@name}}\n{{/file}}\n```\n\n##### [{{import}}](templates/examples/import.ts.hbs)\n\n```handlebars\n{{#import}}\ninclude \"{{@name}}.pb.h\"\n{{/import}}\n```\n\n##### [{{package}}](templates/examples/package.ts.hbs)\n\n```handlebars\n// get root packages\n{{#package}}\nnamespace {{@name}} {\n  // ...\n}\n{{/package}}\n\n// get all packages\n{{#package recursive=true}}\nnamespace {{@name}} {\n  // ...\n}\n{{/package}}\n\n// get all packages recursively in their scope\n{{#package}}\nnamespace {{@name}} {\n  {{@recursive}}\n}\n{{/package}}\n\n// filter by name\n{{#package name=\"google*\" recursive=true}}\n  // {{@name}}\n{{else}}\n  // ...\n{{/package}}\n```\n\n##### [{{message}}](templates/examples/message.ts.hbs)\n\n```handlebars\n// Display messages name\n{{#message}}\n  {{@name}}\n{{/message}}\n\n// Filter by name\n{{#message name=\"google.protobuf.Timestamp\"}}\nclass {{@name}} extends DateTime {}\n{{else}}\nclass {{@name}} {}\n{{/message}}\n\n// By default children will get parents name as prefix\n{{#message}}\n  {{@name}}\n{{/message}}\n\n// Is equal to\n{{#package}}\n  {{#message}}\n  {{@service.name}}.{{@name}}\n  {{/message}}\n{{/package}}\n\n// You can access nested message this way\n{{#message}}\n  {{#nested}}\n    {{@name}}\n  {{/nested}}\n{{/message}}\n\n// Or recursively\n{{#message}}\n  {{@name}}\n  {{@recursive}}\n{{/message}}\n\n// Or recursively as param\n{{#message recursive=true}}\n  {{@name}}\n{{/message}}\n```\n\n##### [{{field}}](templates/examples/field.ts.hbs)\n\n```handlebars\n{{#message}}\n  {{#field}}\n    {{@name}}: {{@type}}\n  {{/field}}\n{{/message}}\n\n// You can filter fields by label and/or type\n{{#field label=\"repeated\"}}\n// TODO: convert type\nconst {{@name}}: Array\u003c{{@type}}\u003e = []\n{{/field}}\n\n{{#field type=\"string\"}}\nconst {{@name}}: string = ''\n{{/field}}\n\n{{#field label=\"optional\" type=\"number\"}}\nconst {{@name}}: number? = undefined\n{{/field}}\n```\n\n##### [{{extension}}](templates/examples/extension.ts.hbs)\n\n```handlebars\n// Work exactly like field\n{{#message}}\n  {{#extension}}\n    {{@name}}: {{@type}}\n  {{/extension}}\n{{/message}}\n```\n\n##### [{{enum}}](templates/examples/enum.ts.hbs)\n\n```handlebars\n{{#enum}}\nenum {{@name}} {\n  {{#value}}\n    {{@name}}: {{@number}}\n  {{/value}}\n}\n{{/enum}}\n```\n\n##### [{{service}}](templates/examples/service.ts.hbs)\n\n```handlebars\n{{#service}}\ninterface {{@name}} {\n  // do stuff\n}\n{{/service}}\n```\n\n##### [{{rpc}}](templates/examples/rpc.ts.hbs)\n\n```handlebars\n{{#rpc}}\n  // TODO: convert input and output type\n  const {{@name}} = (request: {{@input}}): Promise\u003c{{@output}}\u003e =\u003e {\n    // do stuff\n  }\n{{/rpc}}\n\n// You can filter by request/response type\n{{#rpc client=\"unary\" server=\"stream\"}}\n  // TODO: convert input and output type\n  const {{@name}} = (request: {{@input}}, (response: {{@output}} =\u003e void): Promise\u003cvoid\u003e\n{{/rpc}}\n\n{{#service}}\n  const {{@service.name}} = {\n    {{#rpc}}\n      {{@name}}: (request: {{@input}}, (response: {{@output}} =\u003e void): Promise\u003cvoid\u003e\n    {{/rpc}}\n  }\n{{/service}}\n```\n\n##### [{{option}}](templates/examples/option.ts.hbs)\n\n```handlebars\n// You can filter by option like this\n{{#service}}\n  {{#option deprecated=true}}\n    // Do stuff\n  {{/option}}\n{{/service}}\n\n// Or\n{{#service deprecated=true}}\n  // Do stuff\n{{/service}}\n\n// You can also access it directly\n{{#message}}\n  {{#field}}\n    {{@jsonName}}\n  {{/field}}\n{{/message}}\n```\n\n#### Others\n\nFor helpers not related with protobuf\n\n* All [handlebars-helpers](helpers/handlebars-helpers) have been included\n* Better string case helpers have been added too (see [here](src/case.js))\n\n## Contributing\n\nMake PRs and have fun 👻\n\n## Issues\n\nNo rules, if you see anything weird, [open an issue](https://github.com/90dy/protoc-gen-hbs/issues/new/choose) :)\n\n## Examples\n\nSee examples directory [here](examples)\n\n## License\n\nThis project is licensed under Apache 2.0 - see [LICENSE](LICENSE) file for details\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F90dy%2Fprotoc-gen-hbs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F90dy%2Fprotoc-gen-hbs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F90dy%2Fprotoc-gen-hbs/lists"}