@camposcloud/cli 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +153 -2
- package/dist/commands/apps.js +197 -0
- package/dist/commands/auth.js +194 -0
- package/dist/commands/completion.js +94 -0
- package/dist/commands/create.js +220 -0
- package/dist/commands/dashboard.js +44 -0
- package/dist/commands/db.js +85 -0
- package/dist/commands/deploy.js +104 -0
- package/dist/commands/env.js +103 -0
- package/dist/commands/files.js +101 -0
- package/dist/commands/lang.js +34 -0
- package/dist/commands/manage.js +121 -0
- package/dist/commands/teams.js +127 -0
- package/dist/commands/utils.js +102 -0
- package/dist/core/api.js +157 -0
- package/dist/core/apiErrors.js +38 -0
- package/dist/core/apps.js +98 -0
- package/dist/core/config.js +34 -0
- package/dist/core/context.js +43 -0
- package/dist/core/credentials.js +90 -0
- package/dist/core/databases.js +53 -0
- package/dist/core/detect.js +75 -0
- package/dist/core/deviceLogin.js +49 -0
- package/dist/core/env.js +71 -0
- package/dist/core/files.js +51 -0
- package/dist/core/help.js +193 -0
- package/dist/core/i18n.js +581 -0
- package/dist/core/logs.js +87 -0
- package/dist/core/output.js +27 -0
- package/dist/core/project.js +119 -0
- package/dist/core/prompt.js +29 -0
- package/dist/core/session.js +21 -0
- package/dist/core/suggest.js +28 -0
- package/dist/core/teams.js +39 -0
- package/dist/core/update.js +48 -0
- package/dist/index.js +223 -0
- package/dist/tui/App.js +400 -0
- package/dist/tui/App.test.js +189 -0
- package/dist/tui/Picker.js +87 -0
- package/dist/tui/clickable.js +64 -0
- package/dist/tui/mouse.js +65 -0
- package/dist/tui/run.js +27 -0
- package/package.json +57 -4
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { Box, render, Text, useInput } from "ink";
|
|
4
|
+
import pc from "picocolors";
|
|
5
|
+
import { t } from "../core/i18n.js";
|
|
6
|
+
const BLUE = "#4f86ff";
|
|
7
|
+
const MUTED = "#8d8d93";
|
|
8
|
+
const FAINT = "#5f5f66";
|
|
9
|
+
const VISIBLE = 10;
|
|
10
|
+
function Picker({ title, items, filter = true, onDone }) {
|
|
11
|
+
const [query, setQuery] = useState("");
|
|
12
|
+
const [index, setIndex] = useState(0);
|
|
13
|
+
const filtered = items.filter((item) => item.label.toLowerCase().includes(query.toLowerCase()));
|
|
14
|
+
const selected = Math.min(index, Math.max(0, filtered.length - 1));
|
|
15
|
+
const start = Math.max(0, Math.min(selected - Math.floor(VISIBLE / 2), filtered.length - VISIBLE));
|
|
16
|
+
const finish = (value) => onDone(value);
|
|
17
|
+
useInput((input, key) => {
|
|
18
|
+
if (key.escape)
|
|
19
|
+
return finish(null);
|
|
20
|
+
if (key.return)
|
|
21
|
+
return finish(filtered[selected]?.value ?? null);
|
|
22
|
+
if (key.upArrow)
|
|
23
|
+
return setIndex(Math.max(0, selected - 1));
|
|
24
|
+
if (key.downArrow)
|
|
25
|
+
return setIndex(Math.min(filtered.length - 1, selected + 1));
|
|
26
|
+
if (key.backspace || key.delete)
|
|
27
|
+
return setQuery((value) => value.slice(0, -1));
|
|
28
|
+
if (filter && input && !key.ctrl && !key.meta && input >= " ") {
|
|
29
|
+
setQuery((value) => value + input);
|
|
30
|
+
setIndex(0);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { bold: true, children: title }), filter && _jsxs(Text, { color: MUTED, children: [query ? _jsx(Text, { color: "white", children: query }) : t("picker.typeToFilter"), _jsx(Text, { color: BLUE, children: "\u258F" })] }), _jsxs(Box, { flexDirection: "column", marginTop: 1, children: [filtered.length === 0 && _jsx(Text, { color: FAINT, children: t("picker.none") }), filtered.slice(start, start + VISIBLE).map((item, offset) => {
|
|
34
|
+
const isSelected = start + offset === selected;
|
|
35
|
+
return (_jsxs(Text, { wrap: "truncate-end", children: [_jsx(Text, { color: BLUE, children: isSelected ? "› " : " " }), _jsx(Text, { bold: isSelected, color: isSelected ? "white" : undefined, children: item.label }), item.detail && _jsxs(Text, { color: FAINT, children: [" ", item.detail] })] }, `${item.label}-${start + offset}`));
|
|
36
|
+
}), filtered.length > VISIBLE && _jsx(Text, { color: FAINT, children: t("picker.more", { total: String(filtered.length) }) })] }), _jsx(Box, { marginTop: 1, children: _jsx(Text, { color: FAINT, children: t("picker.hint") }) })] }));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Shows a question until it is answered, then takes it off the screen and leaves one short line in its place
|
|
40
|
+
* ("✓ Ambiente Node.js"), so a sequence of questions does not pile up in the terminal.
|
|
41
|
+
*/
|
|
42
|
+
function askOnce(element, answered) {
|
|
43
|
+
return new Promise((resolve) => {
|
|
44
|
+
let app = null;
|
|
45
|
+
let settled = false;
|
|
46
|
+
const done = (value) => {
|
|
47
|
+
if (settled)
|
|
48
|
+
return;
|
|
49
|
+
settled = true;
|
|
50
|
+
app?.clear();
|
|
51
|
+
app?.unmount();
|
|
52
|
+
app?.cleanup();
|
|
53
|
+
const line = value === null ? null : answered(value);
|
|
54
|
+
if (line !== null)
|
|
55
|
+
process.stdout.write(`${line}\n`);
|
|
56
|
+
resolve(value);
|
|
57
|
+
};
|
|
58
|
+
app = render(element(done));
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
const answeredLine = (title, answer) => `${pc.green("✓")} ${title} ${pc.bold(answer)}`;
|
|
62
|
+
/** Shows the list and resolves with the chosen value, or null when the person pressed Esc. */
|
|
63
|
+
export function pick(title, items, options = {}) {
|
|
64
|
+
return askOnce((done) => _jsx(Picker, { title: title, items: items, filter: options.filter !== false, onDone: done }), (value) => (options.keep === false ? null : answeredLine(title, items.find((item) => item.value === value)?.label ?? String(value))));
|
|
65
|
+
}
|
|
66
|
+
/** A line of text: typing, Backspace, paste; Enter keeps the default when nothing was typed; Esc cancels. */
|
|
67
|
+
function TextPrompt({ question, fallback, mask, onDone }) {
|
|
68
|
+
const [value, setValue] = useState("");
|
|
69
|
+
const finish = (result) => onDone(result);
|
|
70
|
+
useInput((input, key) => {
|
|
71
|
+
if (key.escape)
|
|
72
|
+
return finish(null);
|
|
73
|
+
if (key.return)
|
|
74
|
+
return finish(value.trim() || fallback);
|
|
75
|
+
if (key.backspace || key.delete)
|
|
76
|
+
return setValue((current) => current.slice(0, -1));
|
|
77
|
+
if (input && !key.ctrl && !key.meta)
|
|
78
|
+
setValue((current) => current + input.replace(/[\r\n]/g, ""));
|
|
79
|
+
});
|
|
80
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { children: [_jsx(Text, { bold: true, children: question }), fallback && !value ? _jsxs(Text, { color: FAINT, children: [" ", fallback] }) : null] }), _jsxs(Text, { children: [_jsx(Text, { color: BLUE, children: "\u203A " }), _jsx(Text, { children: mask ? "•".repeat(Math.min(value.length, 40)) : value }), _jsx(Text, { color: BLUE, children: "\u258F" })] })] }));
|
|
81
|
+
}
|
|
82
|
+
/** Asks for a line of text; resolves with the answer (the default when empty), or null on Esc. */
|
|
83
|
+
export function askText(question, fallback = "", options = {}) {
|
|
84
|
+
return askOnce((done) => _jsx(TextPrompt, { question: question, fallback: fallback, mask: options.mask, onDone: done }),
|
|
85
|
+
// A secret never stays on screen: only that it was given.
|
|
86
|
+
(value) => answeredLine(question, options.mask ? "•".repeat(8) : value));
|
|
87
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useLayoutEffect, useRef } from "react";
|
|
3
|
+
import { Box, measureElement } from "ink";
|
|
4
|
+
/**
|
|
5
|
+
* Every `<Clickable>` on screen registers itself here. A click is matched against their boxes at the moment
|
|
6
|
+
* it happens (measured from the live layout, so resizes and scrolling are always current), and the innermost
|
|
7
|
+
* box under the pointer wins.
|
|
8
|
+
*/
|
|
9
|
+
export class ClickRegistry {
|
|
10
|
+
next = 0;
|
|
11
|
+
items = new Map();
|
|
12
|
+
onWheel = null;
|
|
13
|
+
add(node, onClick) {
|
|
14
|
+
const id = this.next++;
|
|
15
|
+
this.items.set(id, { node, onClick });
|
|
16
|
+
return () => this.items.delete(id);
|
|
17
|
+
}
|
|
18
|
+
/** True when something took the event. */
|
|
19
|
+
dispatch(event) {
|
|
20
|
+
if (event.kind === "wheel") {
|
|
21
|
+
this.onWheel?.(event.button === 64 ? -1 : 1);
|
|
22
|
+
return this.onWheel !== null;
|
|
23
|
+
}
|
|
24
|
+
if (event.kind !== "release" || event.button !== 0)
|
|
25
|
+
return false;
|
|
26
|
+
let best = null;
|
|
27
|
+
for (const item of this.items.values()) {
|
|
28
|
+
const node = item.node();
|
|
29
|
+
if (!node)
|
|
30
|
+
continue;
|
|
31
|
+
const box = measureElement(node);
|
|
32
|
+
const inside = event.x >= box.x && event.x < box.x + box.width && event.y >= box.y && event.y < box.y + box.height;
|
|
33
|
+
const area = box.width * box.height;
|
|
34
|
+
if (inside && area > 0 && (!best || area < best.area))
|
|
35
|
+
best = { area, onClick: item.onClick };
|
|
36
|
+
}
|
|
37
|
+
best?.onClick();
|
|
38
|
+
return best !== null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export const ClickContext = createContext(null);
|
|
42
|
+
/** A Box that runs `onClick` when clicked with the left button. */
|
|
43
|
+
export function Clickable({ onClick, children, ...props }) {
|
|
44
|
+
const registry = useContext(ClickContext);
|
|
45
|
+
const ref = useRef(null);
|
|
46
|
+
const handler = useRef(onClick);
|
|
47
|
+
handler.current = onClick;
|
|
48
|
+
// A layout effect: registered in the same commit that puts the box on screen. A passive effect can run
|
|
49
|
+
// only after the next render under Ink, and a click in between would miss a box that is already visible.
|
|
50
|
+
useLayoutEffect(() => registry?.add(() => ref.current, () => handler.current()), [registry]);
|
|
51
|
+
return _jsx(Box, { ref: ref, ...props, children: children });
|
|
52
|
+
}
|
|
53
|
+
/** The mouse wheel, for the screen that is showing: up is -1, down is 1. */
|
|
54
|
+
export function useWheel(onWheel) {
|
|
55
|
+
const registry = useContext(ClickContext);
|
|
56
|
+
const handler = useRef(onWheel);
|
|
57
|
+
handler.current = onWheel;
|
|
58
|
+
useLayoutEffect(() => {
|
|
59
|
+
if (!registry)
|
|
60
|
+
return;
|
|
61
|
+
registry.onWheel = (direction) => handler.current(direction);
|
|
62
|
+
return () => { registry.onWheel = null; };
|
|
63
|
+
}, [registry]);
|
|
64
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { PassThrough } from "node:stream";
|
|
2
|
+
// eslint-disable-next-line no-control-regex
|
|
3
|
+
const SGR_MOUSE = /\x1b\[<(\d+);(\d+);(\d+)([Mm])/g;
|
|
4
|
+
// eslint-disable-next-line no-control-regex
|
|
5
|
+
const PARTIAL_AT_END = /\x1b(\[(<[\d;]*)?)?$/;
|
|
6
|
+
/** Takes the mouse reports out of a chunk of input; a report cut at the end waits for the next chunk. */
|
|
7
|
+
export class MouseParser {
|
|
8
|
+
pending = "";
|
|
9
|
+
push(chunk) {
|
|
10
|
+
let text = this.pending + chunk;
|
|
11
|
+
this.pending = "";
|
|
12
|
+
const partial = PARTIAL_AT_END.exec(text);
|
|
13
|
+
// A lone ESC at the end is the Escape key, not the start of a report: only hold "ESC [ <...".
|
|
14
|
+
if (partial && partial[0].startsWith("\x1b[<")) {
|
|
15
|
+
this.pending = partial[0];
|
|
16
|
+
text = text.slice(0, partial.index);
|
|
17
|
+
}
|
|
18
|
+
const events = [];
|
|
19
|
+
const rest = text.replace(SGR_MOUSE, (_, button, column, row, final) => {
|
|
20
|
+
const code = Number(button);
|
|
21
|
+
const isWheel = code === 64 || code === 65;
|
|
22
|
+
// Motion and modifier bits are not used; keep the plain button.
|
|
23
|
+
events.push({
|
|
24
|
+
button: isWheel ? code : code & 3,
|
|
25
|
+
x: Number(column) - 1,
|
|
26
|
+
y: Number(row) - 1,
|
|
27
|
+
kind: isWheel ? "wheel" : final === "M" ? "press" : "release",
|
|
28
|
+
});
|
|
29
|
+
return "";
|
|
30
|
+
});
|
|
31
|
+
return { events, rest };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export const ENABLE_MOUSE = "\x1b[?1000h\x1b[?1006h";
|
|
35
|
+
export const DISABLE_MOUSE = "\x1b[?1000l\x1b[?1006l";
|
|
36
|
+
/**
|
|
37
|
+
* A stdin for Ink that filters the mouse out. It looks like a TTY to Ink (raw mode, ref/unref go to the
|
|
38
|
+
* real stdin), so keys, Ctrl+C and paste work as usual.
|
|
39
|
+
*/
|
|
40
|
+
export function createInputProxy(stdin, onMouse) {
|
|
41
|
+
const parser = new MouseParser();
|
|
42
|
+
const proxy = new PassThrough();
|
|
43
|
+
proxy.isTTY = true;
|
|
44
|
+
proxy.setRawMode = (enabled) => {
|
|
45
|
+
stdin.setRawMode?.(enabled);
|
|
46
|
+
return proxy;
|
|
47
|
+
};
|
|
48
|
+
proxy.ref = () => { stdin.ref(); return proxy; };
|
|
49
|
+
proxy.unref = () => { stdin.unref(); return proxy; };
|
|
50
|
+
const onData = (chunk) => {
|
|
51
|
+
const { events, rest } = parser.push(chunk.toString());
|
|
52
|
+
for (const event of events)
|
|
53
|
+
onMouse(event);
|
|
54
|
+
if (rest)
|
|
55
|
+
proxy.write(rest);
|
|
56
|
+
};
|
|
57
|
+
stdin.on("data", onData);
|
|
58
|
+
return {
|
|
59
|
+
stream: proxy,
|
|
60
|
+
close: () => {
|
|
61
|
+
stdin.off("data", onData);
|
|
62
|
+
proxy.end();
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
package/dist/tui/run.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { render } from "ink";
|
|
3
|
+
import { ClickContext, ClickRegistry } from "./clickable.js";
|
|
4
|
+
import { createInputProxy, DISABLE_MOUSE, ENABLE_MOUSE } from "./mouse.js";
|
|
5
|
+
import { Dashboard } from "./App.js";
|
|
6
|
+
/**
|
|
7
|
+
* Opens the dashboard full screen (the terminal's alternate screen, so the scrollback comes back as it was)
|
|
8
|
+
* with the mouse on, and resolves when the person leaves it.
|
|
9
|
+
*/
|
|
10
|
+
export async function runDashboard(props) {
|
|
11
|
+
const registry = new ClickRegistry();
|
|
12
|
+
const input = createInputProxy(process.stdin, (event) => registry.dispatch(event));
|
|
13
|
+
// Whatever happens, the terminal must not keep reporting the mouse after we leave.
|
|
14
|
+
const restoreMouse = () => process.stdout.write(DISABLE_MOUSE);
|
|
15
|
+
process.once("exit", restoreMouse);
|
|
16
|
+
process.stdout.write(ENABLE_MOUSE);
|
|
17
|
+
const app = render(_jsx(ClickContext.Provider, { value: registry, children: _jsx(Dashboard, { ...props }) }), { stdin: input.stream, alternateScreen: true, exitOnCtrlC: true, patchConsole: true });
|
|
18
|
+
try {
|
|
19
|
+
await app.waitUntilExit();
|
|
20
|
+
}
|
|
21
|
+
finally {
|
|
22
|
+
restoreMouse();
|
|
23
|
+
process.off("exit", restoreMouse);
|
|
24
|
+
input.close();
|
|
25
|
+
process.stdin.pause();
|
|
26
|
+
}
|
|
27
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,59 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@camposcloud/cli",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Campos Cloud CLI (campos): manage applications, databases and teams from the terminal.",
|
|
5
|
+
"bugs": {
|
|
6
|
+
"url": "https://github.com/camposcloud/camposcloud-cli/issues",
|
|
7
|
+
"email": "contato@camposcloud.com"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/camposcloud/camposcloud-cli/issues"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"discord-host",
|
|
15
|
+
"camposcloud",
|
|
16
|
+
"hosting",
|
|
17
|
+
"discord-bot",
|
|
18
|
+
"host-discord",
|
|
19
|
+
"host-api",
|
|
20
|
+
"campos cloud",
|
|
21
|
+
"campos cloud cli",
|
|
22
|
+
"host cli"
|
|
23
|
+
],
|
|
24
|
+
"type": "module",
|
|
25
|
+
"bin": {
|
|
26
|
+
"campos": "dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist"
|
|
30
|
+
],
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=22.12.0"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"dev": "tsx src/index.ts",
|
|
36
|
+
"build": "tsc -p tsconfig.build.json",
|
|
37
|
+
"typecheck": "tsc --noEmit -p .",
|
|
38
|
+
"test": "tsx --test --test-force-exit \"src/**/*.test.ts\" \"src/**/*.test.tsx\""
|
|
39
|
+
},
|
|
40
|
+
"license": "UNLICENSED",
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@napi-rs/keyring": "^2.1.2",
|
|
43
|
+
"commander": "^15.1.0",
|
|
44
|
+
"fflate": "^0.8.3",
|
|
45
|
+
"ink": "^8.0.0",
|
|
46
|
+
"open": "^11.0.4",
|
|
47
|
+
"picocolors": "^1.1.1",
|
|
48
|
+
"react": "^19.3.1",
|
|
49
|
+
"semver": "^7.8.6"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@types/node": "^24.19.2",
|
|
53
|
+
"@types/react": "^19.3.0",
|
|
54
|
+
"@types/semver": "^7.8.0",
|
|
55
|
+
"ink-testing-library": "^4.0.0",
|
|
56
|
+
"tsx": "^4.23.15",
|
|
57
|
+
"typescript": "^5.9.3"
|
|
58
|
+
}
|
|
59
|
+
}
|