@nexusbloom/cli 0.3.1 → 0.3.3
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/package.json +1 -2
- package/src/run.js +8 -11
- package/src/ui.js +45 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexusbloom/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "NexusBloom CLI — run tools and workflows from your terminal",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -21,7 +21,6 @@
|
|
|
21
21
|
"@inquirer/prompts": "^8.7.2",
|
|
22
22
|
"chalk": "^5.3.0",
|
|
23
23
|
"commander": "^12.0.0",
|
|
24
|
-
"ora": "^8.0.0",
|
|
25
24
|
"qrcode": "^1.5.4"
|
|
26
25
|
}
|
|
27
26
|
}
|
package/src/run.js
CHANGED
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
import fs from "fs";
|
|
13
13
|
import path from "path";
|
|
14
14
|
import chalk from "chalk";
|
|
15
|
-
import ora from "ora";
|
|
16
15
|
import QRCode from "qrcode";
|
|
17
16
|
|
|
18
17
|
import {
|
|
@@ -42,7 +41,7 @@ export async function runRemote(slug, body, { apiKey, jsonMode, slugResolved })
|
|
|
42
41
|
return runLocal(slug, body, { jsonMode, slugResolved });
|
|
43
42
|
}
|
|
44
43
|
|
|
45
|
-
|
|
44
|
+
if (!jsonMode) console.log(chalk.dim(` Running ${slug}...`));
|
|
46
45
|
|
|
47
46
|
try {
|
|
48
47
|
const res = await fetch(`${API_BASE}/api/run/${slug}`, {
|
|
@@ -52,17 +51,14 @@ export async function runRemote(slug, body, { apiKey, jsonMode, slugResolved })
|
|
|
52
51
|
});
|
|
53
52
|
|
|
54
53
|
if (!res.ok && !res.headers.get("content-type")?.includes("json")) {
|
|
55
|
-
if (
|
|
54
|
+
if (!jsonMode) console.log(chalk.dim(" API not deployed — falling back to local"));
|
|
56
55
|
return runLocal(slug, body, { jsonMode, slugResolved });
|
|
57
56
|
}
|
|
58
57
|
|
|
59
58
|
const data = await res.json();
|
|
60
|
-
if (spinner) {
|
|
61
|
-
if (data.success) spinner.succeed(chalk.green(` ${slug} completed`));
|
|
62
|
-
else spinner.fail(chalk.red(` ${slug} failed`));
|
|
63
|
-
}
|
|
64
59
|
|
|
65
60
|
if (data.success) {
|
|
61
|
+
if (!jsonMode) console.log(chalk.green(` ✓ ${slug} completed`));
|
|
66
62
|
if (data.data && typeof data.data === "object" && data.data.svg) {
|
|
67
63
|
await renderQRCode(body.data || body.text || JSON.stringify(body), slug);
|
|
68
64
|
}
|
|
@@ -72,11 +68,12 @@ export async function runRemote(slug, body, { apiKey, jsonMode, slugResolved })
|
|
|
72
68
|
return;
|
|
73
69
|
}
|
|
74
70
|
|
|
71
|
+
if (!jsonMode) console.log(chalk.red(` ✗ ${slug} failed`));
|
|
75
72
|
if (jsonMode) return console.log(JSON.stringify({ success: false, error: data.error || "Unknown error" }, null, 2));
|
|
76
73
|
console.error(chalk.red(`\n Error: ${data.error || "Unknown error"}`));
|
|
77
74
|
process.exitCode = 1;
|
|
78
75
|
} catch (err) {
|
|
79
|
-
if (
|
|
76
|
+
if (!jsonMode) console.log(chalk.dim(" API unreachable — falling back to local"));
|
|
80
77
|
return runLocal(slug, body, { jsonMode, slugResolved });
|
|
81
78
|
}
|
|
82
79
|
}
|
|
@@ -131,10 +128,10 @@ export async function runLocal(slug, input, { jsonMode, slugResolved, source: sr
|
|
|
131
128
|
}
|
|
132
129
|
|
|
133
130
|
const timeoutMs = manifest.timeout_ms || 5000;
|
|
134
|
-
const spinner = !jsonMode ? ora(chalk.gray(` Executing ${slug} (local)`)).start() : null;
|
|
135
131
|
let result;
|
|
136
132
|
|
|
137
133
|
try {
|
|
134
|
+
if (!jsonMode) console.log(chalk.dim(` Executing ${slug} (local)...`));
|
|
138
135
|
if (isAsync) {
|
|
139
136
|
result = await Promise.race([
|
|
140
137
|
coreLogicFn(input),
|
|
@@ -143,7 +140,7 @@ export async function runLocal(slug, input, { jsonMode, slugResolved, source: sr
|
|
|
143
140
|
} else {
|
|
144
141
|
result = coreLogicFn(input);
|
|
145
142
|
}
|
|
146
|
-
if (
|
|
143
|
+
if (!jsonMode) console.log(chalk.green(` ✓ ${slug} completed`));
|
|
147
144
|
|
|
148
145
|
// Fire-and-forget telemetry
|
|
149
146
|
const apiKey = process.env.NEXUSBLOOM_API_KEY || configGet("apiKey") || configGet("key");
|
|
@@ -155,7 +152,7 @@ export async function runLocal(slug, input, { jsonMode, slugResolved, source: sr
|
|
|
155
152
|
console.log(chalk.green("\n Result (local):"));
|
|
156
153
|
console.log(` ${JSON.stringify(result, null, 2)}`);
|
|
157
154
|
} catch (err) {
|
|
158
|
-
if (
|
|
155
|
+
if (!jsonMode) console.log(chalk.red(` ✗ Execution error`));
|
|
159
156
|
if (jsonMode) return console.log(JSON.stringify({ error: err.message }));
|
|
160
157
|
console.error(chalk.red(`\n Local execution error: ${err.message}`));
|
|
161
158
|
process.exitCode = 1;
|
package/src/ui.js
CHANGED
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
|
|
18
18
|
// ─── Constants ───────────────────────────────────────────────────────────────
|
|
19
19
|
|
|
20
|
-
export const PAGE_SIZE =
|
|
20
|
+
export const PAGE_SIZE = 30;
|
|
21
21
|
|
|
22
22
|
// ─── Simple helpers ──────────────────────────────────────────────────────────
|
|
23
23
|
|
|
@@ -42,13 +42,17 @@ export function renderHeader(title, { subtitle, color = "cyan" } = {}) {
|
|
|
42
42
|
*/
|
|
43
43
|
export function renderBox(title, lines = [], { width = 60 } = {}) {
|
|
44
44
|
const inner = Math.max(width - 4, 30);
|
|
45
|
-
const top = chalk.gray(
|
|
45
|
+
const top = chalk.gray(
|
|
46
|
+
`┌─ ${chalk.bold(title)} ${"─".repeat(Math.max(0, inner - title.length - 2))}┐`,
|
|
47
|
+
);
|
|
46
48
|
console.log(`\n${top}`);
|
|
47
49
|
for (const line of lines) {
|
|
48
50
|
if (line === "") {
|
|
49
51
|
console.log(chalk.gray(`│ ${" ".repeat(inner)} │`));
|
|
50
52
|
} else {
|
|
51
|
-
console.log(
|
|
53
|
+
console.log(
|
|
54
|
+
`${chalk.gray("│ ")}${String(line).padEnd(inner)}${chalk.gray(" │")}`,
|
|
55
|
+
);
|
|
52
56
|
}
|
|
53
57
|
}
|
|
54
58
|
const bottom = chalk.gray(`└${"─".repeat(inner + 2)}┘\n`);
|
|
@@ -113,7 +117,12 @@ export function paginate(items, pageSize = PAGE_SIZE, currentPage = 1) {
|
|
|
113
117
|
* Interactive paginator: renders via `renderPage`, offers prev/next/done/cancel.
|
|
114
118
|
* Returns the last page result or null on cancel.
|
|
115
119
|
*/
|
|
116
|
-
export async function paginateInteractive(
|
|
120
|
+
export async function paginateInteractive(
|
|
121
|
+
items,
|
|
122
|
+
pageSize,
|
|
123
|
+
renderPage,
|
|
124
|
+
options = {},
|
|
125
|
+
) {
|
|
117
126
|
const all = items || [];
|
|
118
127
|
if (all.length === 0) {
|
|
119
128
|
renderPage(paginate([], pageSize, 1));
|
|
@@ -135,7 +144,9 @@ export async function paginateInteractive(items, pageSize, renderPage, options =
|
|
|
135
144
|
nav.push({ name: "✕ Cancel", value: "cancel" });
|
|
136
145
|
|
|
137
146
|
const action = await select({
|
|
138
|
-
message: chalk.gray(
|
|
147
|
+
message: chalk.gray(
|
|
148
|
+
`Page ${result.page}/${result.totalPages} · ${result.total} items`,
|
|
149
|
+
),
|
|
139
150
|
choices: [new Separator(), ...nav],
|
|
140
151
|
pageSize: 8,
|
|
141
152
|
});
|
|
@@ -151,11 +162,24 @@ export async function paginateInteractive(items, pageSize, renderPage, options =
|
|
|
151
162
|
// ─── Prompt wrappers ─────────────────────────────────────────────────────────
|
|
152
163
|
|
|
153
164
|
export async function promptSelect(message, choices, opts = {}) {
|
|
154
|
-
return select({
|
|
165
|
+
return select({
|
|
166
|
+
message: chalk.cyan(message),
|
|
167
|
+
choices,
|
|
168
|
+
pageSize: opts.pageSize || 10,
|
|
169
|
+
...opts,
|
|
170
|
+
});
|
|
155
171
|
}
|
|
156
172
|
|
|
157
|
-
export async function promptInput(
|
|
158
|
-
|
|
173
|
+
export async function promptInput(
|
|
174
|
+
message,
|
|
175
|
+
{ defaultValue, validate, ...opts } = {},
|
|
176
|
+
) {
|
|
177
|
+
return input({
|
|
178
|
+
message: chalk.cyan(message),
|
|
179
|
+
default: defaultValue,
|
|
180
|
+
...(validate ? { validate } : {}),
|
|
181
|
+
...opts,
|
|
182
|
+
});
|
|
159
183
|
}
|
|
160
184
|
|
|
161
185
|
export async function promptConfirm(message, { default: def = true } = {}) {
|
|
@@ -163,13 +187,23 @@ export async function promptConfirm(message, { default: def = true } = {}) {
|
|
|
163
187
|
}
|
|
164
188
|
|
|
165
189
|
export async function promptNumber(message, { min, max, ...opts } = {}) {
|
|
166
|
-
return number({
|
|
190
|
+
return number({
|
|
191
|
+
message: chalk.cyan(message),
|
|
192
|
+
...(min != null ? { min } : {}),
|
|
193
|
+
...(max != null ? { max } : {}),
|
|
194
|
+
...opts,
|
|
195
|
+
});
|
|
167
196
|
}
|
|
168
197
|
|
|
169
198
|
export async function promptCheckbox(message, choices, opts = {}) {
|
|
170
|
-
return checkbox({
|
|
199
|
+
return checkbox({
|
|
200
|
+
message: chalk.cyan(message),
|
|
201
|
+
choices,
|
|
202
|
+
pageSize: opts.pageSize || 10,
|
|
203
|
+
...opts,
|
|
204
|
+
});
|
|
171
205
|
}
|
|
172
206
|
|
|
173
207
|
export function sep(label = "") {
|
|
174
208
|
return new Separator(label ? ` — ${label} — ` : "");
|
|
175
|
-
}
|
|
209
|
+
}
|