This example shows how to write a custom plugin. It generates Twirp clients from service definitions in Protobuf files.
You need Node version 20.17.0 or later installed. Download the example project and install its dependencies:
curl -L https://github.com/bufbuild/protobuf-es/archive/refs/heads/main.zip > protobuf-es-main.zip
unzip protobuf-es-main.zip 'protobuf-es-main/packages/protoplugin-example/*'
cd protobuf-es-main/packages/protoplugin-example
npm install
To see the client in action:
npm start
Open http://127.0.0.1:3000/ in your browser.
To re-generate code:
npx buf generate
Test the generated code:
npm test
This example is a starting point—we encourage you to try it out and experiment.
Take a look at the code generation logic in protoc-gen-twirp-es.ts, and at buf.gen.yaml to see how it's invoked. To learn more, see our guide for writing plugins.