Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add buf plugin #56 #96

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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