Skip to content

Commit

Permalink
Merge pull request #96 from JerryId/feat/add-buf-plugin-56
Browse files Browse the repository at this point in the history
Add buf plugin #56
  • Loading branch information
tsirysndr committed Oct 9, 2023
2 parents 4a27a3b + 0543458 commit bcf6f05
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Currently available plugins:
- [Git](https://git-scm.com/)
- [Terraform](https://terraform.io/)
- [Homebrew](https://brew.sh/)
- [Buf](https://buf.build/docs/ecosystem/cli-overview#buf-cli-commands)
- [Bun](https://bun.sh)
- [Pkgx](https://pkgx.sh)
- [Pulumi](https://pulumi.com)
Expand Down Expand Up @@ -74,4 +75,4 @@ Currently available plugins:
- [PlanetScale](https://planetscale.com/)
- [Grunt](https://gruntjs.com/)
- [Rtx](https://github.com/jdx/rtx)
- [Nx](https://nx.dev/)
- [Nx](https://nx.dev/)
53 changes: 53 additions & 0 deletions plugins/buf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { evaluateSystemCommand, spawn } from "../src/helpers.ts";
import Plugin from "../src/plugin.ts";
import Brew from "./brew.ts";

class Buf implements Plugin {
name = "buf";
commands: Record<string, (params: string[]) => Promise<void>>;
constructor() {
this.commands = {
build: (args: string[]) => spawn(this.name, ["build", ...args]),
generate: (args: string[]) => spawn(this.name, ["generate", ...args]),
breaking: (args: string[]) => spawn(this.name, ["breaking", ...args]),
lint: (args: string[]) => spawn(this.name, ["lint", ...args]),
format: (args: string[]) => spawn(this.name, ["format", ...args]),
curl: (args: string[]) => spawn(this.name, ["curl", ...args]),
convert: (args: string[]) => spawn(this.name, ["convert", ...args]),
mod: (args: string[]) => spawn(this.name, ["mod", ...args]),
registry: (args: string[]) => spawn(this.name, ["registry", ...args]),
push: (args: string[]) => spawn(this.name, ["push", ...args]),
export: (args: string[]) => spawn(this.name, ["export", ...args]),
help: () => {
console.log(` Common Commands:
build Build Protobuf files into a Buf image (key to many other buf operations)
generate Generate code stubs from Protobuf files using protoc plugins
breaking Verify no breaking changes have been made, to guard against compatibility issues
lint,format Lint and format your Protobuf files according to best practice and your org rules
curl Test your APIs by invoking an RPC endpoint, similar to using cURL
convert Convert a message from binary to JSON or vice versa—useful when debugging or testing
mod, registry, push, export Manage your repositories in the Buf Schema Registry`);
return Promise.resolve();
},
};
}

async evaluate(command: string): Promise<void> {
const [cmd, ...params] = command.split(" ");
if (this.commands[cmd]) {
await this.commands[cmd](params);
return;
}
if (cmd === "") {
return;
}
await evaluateSystemCommand(command);
}

async install(): Promise<void> {
await new Brew().install();
await spawn("sh", ["-c", "type buf > /dev/null || brew install buf"]);
}
}

export default Buf;
2 changes: 2 additions & 0 deletions plugins/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Git from "./git.ts";
import GithubCLI from "./github-cli.ts";
import Terraform from "./terraform.ts";
import Brew from "./brew.ts";
import Buf from "./buf.ts";
import Bun from "./bun.ts";
import Pkgx from "./pkgx.ts";
import Pulumi from "./pulumi.ts";
Expand Down Expand Up @@ -41,6 +42,7 @@ export const plugins = [
new GithubCLI(),
new Terraform(),
new Brew(),
new Buf(),
new Bun(),
new Pkgx(),
new Pulumi(),
Expand Down

0 comments on commit bcf6f05

Please sign in to comment.