main.ts (view raw)
1import { Client } from "npm:ssh2";
2import { Select } from "https://deno.land/x/cliffy@v1.0.0-rc.4/prompt/select.ts";
3import { tty } from "https://deno.land/x/cliffy@v1.0.0-rc.4/ansi/tty.ts";
4import { colors } from "https://deno.land/x/cliffy@v1.0.0-rc.4/ansi/colors.ts";
5
6const instances = (
7 await import("./instances.json", {
8 with: { type: "json" },
9 })
10).default;
11const actions = (
12 await import("./actions.json", {
13 with: { type: "json" },
14 })
15).default;
16
17const baseConfig = {
18 host: "gate.hidora.com",
19 port: 3022,
20 privateKey: Deno.readTextFileSync("/home/tim/.ssh/id_rsa"),
21};
22
23const selectedConfig = await Select.prompt<(typeof instances)[number]>({
24 message: "🚀 Instance",
25 options: instances.map(c => ({ name: c.name, value: c })),
26});
27
28const selectedAction = await Select.prompt<(typeof actions)[number]>({
29 message: "⚡️ Action",
30 options: actions.map(c => ({ name: c.name, value: c })),
31});
32
33const secondaryText = colors.gray;
34const client = new Client().connect({ ...selectedConfig, ...baseConfig });
35console.log(`✨ Connecting to ${selectedConfig.name}...`);
36client.on("ready", () => {
37 tty.eraseScreen();
38 console.log(secondaryText(`✅ Connected to ${selectedConfig.name}`));
39 console.log(secondaryText(`$ ${selectedAction.cmd}`));
40 client.exec(selectedAction.cmd, (err: Error, stream: any) => {
41 if (err) throw err;
42 stream
43 .on("close", () => {
44 client.end();
45 })
46 .on("data", (data: string) => {
47 console.log("STDOUT" + data);
48 })
49 .stderr.on("data", (data: string) => {
50 console.log("STDERR" + data);
51 });
52 });
53});