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

feat: add plugin for neon #88

Merged
merged 1 commit into from
Oct 7, 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 @@ -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;