Skip to content

Commit

Permalink
Merge pull request #88 from tsirysndr/feat/plugin/neon
Browse files Browse the repository at this point in the history
feat: add plugin for `neon`
  • Loading branch information
tsirysndr committed Oct 7, 2023
2 parents 8d13f42 + 63469f3 commit 31aebdc
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,5 @@ Currently available plugins:
- [Flox](https://flox.dev/)
- [Devenv](https://devenv.sh/)
- [Turbo](https://turbo.build/)
- [Turso](https://turso.tech/)
- [Turso](https://turso.tech/)
- [Neon](https://neon.tech/)
2 changes: 2 additions & 0 deletions plugins/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import Flox from "./flox.ts";
import Devenv from "./devenv.ts";
import Turbo from "./turbo.ts";
import Turso from "./turso.ts";
import Neon from "./neon.ts";

export const plugins = [
new Docker(),
Expand Down Expand Up @@ -62,4 +63,5 @@ export const plugins = [
new Devenv(),
new Turbo(),
new Turso(),
new Neon(),
];
74 changes: 74 additions & 0 deletions plugins/neon.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { evaluateSystemCommand, spawn } from "../src/helpers.ts";
import Plugin from "../src/plugin.ts";
import Brew from "./brew.ts";

class Neon implements Plugin {
name = "neonctl";
commands: Record<string, (params: string[]) => Promise<void>>;

constructor() {
this.commands = {
auth: (args: string[]) => spawn("bunx", [this.name, "auth", ...args]),
me: (args: string[]) => spawn("bunx", [this.name, "me", ...args]),
projects: (args: string[]) =>
spawn("bunx", [this.name, "projects", ...args]),
branches: (args: string[]) =>
spawn("bunx", [this.name, "branches", ...args]),
databases: (args: string[]) =>
spawn("bunx", [this.name, "databases", ...args]),
roles: (args: string[]) => spawn("bunx", [this.name, "roles", ...args]),
operations: (args: string[]) =>
spawn("bunx", [this.name, "operations", ...args]),
"connection-string": (args: string[]) =>
spawn("bunx", [this.name, "connection-string", ...args]),
completion: (args: string[]) =>
spawn("bunx", [this.name, "completion", ...args]),
version: (args: string[]) =>
spawn("bunx", [this.name, "--version", ...args]),
help: () => {
console.log(`
Commands:
neonctl auth
└────────────────> Authenticate
neonctl me
└────────────────> Show current user
neonctl projects
└────────────────> Manage projects
neonctl branches
└────────────────> Manage branches
neonctl databases
└────────────────> Manage databases
neonctl roles
└────────────────> Manage roles
neonctl operations
└────────────────> Manage operations
neonctl connection-string [branch]
└────────────────> Get connection string
neonctl completion
└────────────────> generate completion script
`);
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 node > /dev/null || brew install node"]);
await spawn("sh", ["-c", "type bun > /dev/null || brew install bun"]);
}
}

export default Neon;

0 comments on commit 31aebdc

Please sign in to comment.