@riventa/cli 1.1.2 → 1.2.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/dist/index.js CHANGED
@@ -1,27 +1,17 @@
1
1
  #!/usr/bin/env node
2
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
3
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
4
- }) : x)(function(x) {
5
- if (typeof require !== "undefined") return require.apply(this, arguments);
6
- throw Error('Dynamic require of "' + x + '" is not supported');
7
- });
8
-
9
- // src/index.ts
10
- import { Command } from "commander";
11
- import chalk15 from "chalk";
12
-
13
- // src/commands/login.ts
14
- import chalk2 from "chalk";
15
- import inquirer from "inquirer";
16
- import open from "open";
17
- import ora from "ora";
18
- import { exec } from "child_process";
19
- import { existsSync } from "fs";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __esm = (fn, res) => function __init() {
5
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
6
+ };
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
20
11
 
21
12
  // src/utils/api.ts
22
13
  import Conf from "conf";
23
14
  import chalk from "chalk";
24
- var config = new Conf({ projectName: "riventa-cli" });
25
15
  function getApiKey() {
26
16
  return config.get("apiKey");
27
17
  }
@@ -77,10 +67,20 @@ async function apiRequest(endpoint, options = {}) {
77
67
  }
78
68
  return response.json();
79
69
  }
70
+ var config;
71
+ var init_api = __esm({
72
+ "src/utils/api.ts"() {
73
+ "use strict";
74
+ config = new Conf({ projectName: "riventa-cli" });
75
+ }
76
+ });
80
77
 
81
- // src/commands/login.ts
78
+ // src/utils/browser.ts
79
+ import open from "open";
80
+ import { exec } from "child_process";
81
+ import { readFileSync, existsSync } from "fs";
82
82
  function openUrl(url) {
83
- const isWSL = existsSync("/proc/version") && __require("fs").readFileSync("/proc/version", "utf-8").toLowerCase().includes("microsoft");
83
+ const isWSL = existsSync("/proc/version") && readFileSync("/proc/version", "utf-8").toLowerCase().includes("microsoft");
84
84
  if (isWSL) {
85
85
  return new Promise((resolve, reject) => {
86
86
  exec(`cmd.exe /c start "" "${url.replace(/&/g, "^&")}"`, (err) => {
@@ -92,6 +92,16 @@ function openUrl(url) {
92
92
  return open(url).then(() => {
93
93
  });
94
94
  }
95
+ var init_browser = __esm({
96
+ "src/utils/browser.ts"() {
97
+ "use strict";
98
+ }
99
+ });
100
+
101
+ // src/commands/login.ts
102
+ import chalk2 from "chalk";
103
+ import inquirer from "inquirer";
104
+ import ora from "ora";
95
105
  async function loginCommand() {
96
106
  const existingKey = getApiKey();
97
107
  if (existingKey) {
@@ -262,6 +272,13 @@ async function verifyAndSaveKey(apiKey) {
262
272
  function sleep(ms) {
263
273
  return new Promise((resolve) => setTimeout(resolve, ms));
264
274
  }
275
+ var init_login = __esm({
276
+ "src/commands/login.ts"() {
277
+ "use strict";
278
+ init_api();
279
+ init_browser();
280
+ }
281
+ });
265
282
 
266
283
  // src/commands/init.ts
267
284
  import chalk3 from "chalk";
@@ -270,7 +287,6 @@ import fs from "fs";
270
287
  import path from "path";
271
288
  import Conf2 from "conf";
272
289
  import ora2 from "ora";
273
- var config2 = new Conf2({ projectName: "riventa-cli" });
274
290
  function analyzeLocalProject() {
275
291
  const analysis = {
276
292
  name: path.basename(process.cwd())
@@ -507,6 +523,14 @@ async function createNewProject() {
507
523
  spinner.succeed(`Created project: ${project.name}`);
508
524
  return project.id;
509
525
  }
526
+ var config2;
527
+ var init_init = __esm({
528
+ "src/commands/init.ts"() {
529
+ "use strict";
530
+ init_api();
531
+ config2 = new Conf2({ projectName: "riventa-cli" });
532
+ }
533
+ });
510
534
 
511
535
  // src/commands/deploy.ts
512
536
  import chalk4 from "chalk";
@@ -549,6 +573,12 @@ async function deployCommand(options) {
549
573
  process.exit(1);
550
574
  }
551
575
  }
576
+ var init_deploy = __esm({
577
+ "src/commands/deploy.ts"() {
578
+ "use strict";
579
+ init_api();
580
+ }
581
+ });
552
582
 
553
583
  // src/commands/review.ts
554
584
  import chalk5 from "chalk";
@@ -645,6 +675,12 @@ function getScoreEmoji(score) {
645
675
  if (score >= 50) return "\u{1F7E0}";
646
676
  return "\u{1F534}";
647
677
  }
678
+ var init_review = __esm({
679
+ "src/commands/review.ts"() {
680
+ "use strict";
681
+ init_api();
682
+ }
683
+ });
648
684
 
649
685
  // src/commands/status.ts
650
686
  import chalk6 from "chalk";
@@ -720,6 +756,12 @@ function getStatusIcon(status) {
720
756
  return "\u{1F535}";
721
757
  }
722
758
  }
759
+ var init_status = __esm({
760
+ "src/commands/status.ts"() {
761
+ "use strict";
762
+ init_api();
763
+ }
764
+ });
723
765
 
724
766
  // src/commands/logs.ts
725
767
  import chalk7 from "chalk";
@@ -805,6 +847,12 @@ async function followLogs(deploymentId) {
805
847
  };
806
848
  await poll();
807
849
  }
850
+ var init_logs = __esm({
851
+ "src/commands/logs.ts"() {
852
+ "use strict";
853
+ init_api();
854
+ }
855
+ });
808
856
 
809
857
  // src/commands/rollback.ts
810
858
  import chalk8 from "chalk";
@@ -890,6 +938,12 @@ async function rollbackCommand(options) {
890
938
  process.exit(1);
891
939
  }
892
940
  }
941
+ var init_rollback = __esm({
942
+ "src/commands/rollback.ts"() {
943
+ "use strict";
944
+ init_api();
945
+ }
946
+ });
893
947
 
894
948
  // src/commands/config.ts
895
949
  import chalk9 from "chalk";
@@ -1030,6 +1084,12 @@ function formatValue(value) {
1030
1084
  }
1031
1085
  return String(value);
1032
1086
  }
1087
+ var init_config = __esm({
1088
+ "src/commands/config.ts"() {
1089
+ "use strict";
1090
+ init_api();
1091
+ }
1092
+ });
1033
1093
 
1034
1094
  // src/commands/projects.ts
1035
1095
  import chalk10 from "chalk";
@@ -1098,6 +1158,12 @@ async function projectsCommand() {
1098
1158
  process.exit(1);
1099
1159
  }
1100
1160
  }
1161
+ var init_projects = __esm({
1162
+ "src/commands/projects.ts"() {
1163
+ "use strict";
1164
+ init_api();
1165
+ }
1166
+ });
1101
1167
 
1102
1168
  // src/commands/whoami.ts
1103
1169
  import chalk11 from "chalk";
@@ -1128,6 +1194,12 @@ async function whoamiCommand() {
1128
1194
  `));
1129
1195
  }
1130
1196
  }
1197
+ var init_whoami = __esm({
1198
+ "src/commands/whoami.ts"() {
1199
+ "use strict";
1200
+ init_api();
1201
+ }
1202
+ });
1131
1203
 
1132
1204
  // src/commands/security.ts
1133
1205
  import chalk12 from "chalk";
@@ -1225,6 +1297,12 @@ function getSeverityIcon(severity) {
1225
1297
  return chalk12.gray("INFO");
1226
1298
  }
1227
1299
  }
1300
+ var init_security = __esm({
1301
+ "src/commands/security.ts"() {
1302
+ "use strict";
1303
+ init_api();
1304
+ }
1305
+ });
1228
1306
 
1229
1307
  // src/commands/health.ts
1230
1308
  import chalk13 from "chalk";
@@ -1253,46 +1331,259 @@ async function healthCommand() {
1253
1331
  `));
1254
1332
  }
1255
1333
  }
1334
+ var init_health = __esm({
1335
+ "src/commands/health.ts"() {
1336
+ "use strict";
1337
+ init_api();
1338
+ }
1339
+ });
1256
1340
 
1257
- // src/banner.ts
1341
+ // src/commands/dashboard.ts
1258
1342
  import chalk14 from "chalk";
1343
+ async function dashboardCommand(options) {
1344
+ const page = options.page || "home";
1345
+ const path3 = pages[page];
1346
+ if (!path3) {
1347
+ console.log(chalk14.red(`
1348
+ Unknown page: ${page}`));
1349
+ console.log(chalk14.gray(" Available pages: ") + chalk14.white(Object.keys(pages).join(", ")));
1350
+ console.log();
1351
+ return;
1352
+ }
1353
+ const url = `${BASE}${path3}`;
1354
+ console.log(chalk14.gray(`
1355
+ Opening ${url}
1356
+ `));
1357
+ try {
1358
+ await openUrl(url);
1359
+ } catch {
1360
+ console.log(chalk14.yellow(` Could not open browser. Visit: ${chalk14.white(url)}
1361
+ `));
1362
+ }
1363
+ }
1364
+ var BASE, pages;
1365
+ var init_dashboard = __esm({
1366
+ "src/commands/dashboard.ts"() {
1367
+ "use strict";
1368
+ init_browser();
1369
+ BASE = "https://app.riventa.dev";
1370
+ pages = {
1371
+ home: "/dashboard",
1372
+ reviews: "/ci-cd?tab=reviews",
1373
+ deployments: "/deployments",
1374
+ analytics: "/analytics",
1375
+ security: "/code-quality?tab=security",
1376
+ settings: "/settings",
1377
+ "api-keys": "/settings?tab=api-keys",
1378
+ flags: "/flags",
1379
+ monitoring: "/monitoring"
1380
+ };
1381
+ }
1382
+ });
1383
+
1384
+ // src/banner.ts
1385
+ import chalk15 from "chalk";
1259
1386
  function printBanner(version, email) {
1260
1387
  console.log();
1261
1388
  console.log(
1262
- chalk14.bold.white("RIVENTA") + chalk14.bold.hex("#2563EB")(".DEV")
1389
+ chalk15.bold.white("RIVENTA") + chalk15.bold.hex("#2563EB")(".DEV")
1263
1390
  );
1264
1391
  console.log(
1265
- chalk14.gray(`Riventa CLI v${version} \xB7 AI-powered DevOps`)
1392
+ chalk15.gray(`Riventa CLI v${version} \xB7 AI-powered DevOps`)
1266
1393
  );
1267
1394
  if (email) {
1268
- console.log(chalk14.gray(`Logged in as `) + chalk14.white(email));
1395
+ console.log(chalk15.gray(`Logged in as `) + chalk15.white(email));
1269
1396
  }
1270
1397
  console.log();
1271
1398
  }
1399
+ var init_banner = __esm({
1400
+ "src/banner.ts"() {
1401
+ "use strict";
1402
+ }
1403
+ });
1404
+
1405
+ // src/repl.ts
1406
+ var repl_exports = {};
1407
+ __export(repl_exports, {
1408
+ startRepl: () => startRepl
1409
+ });
1410
+ import { createInterface } from "readline";
1411
+ import chalk16 from "chalk";
1412
+ function showHelp() {
1413
+ console.log();
1414
+ console.log(chalk16.bold(" Available commands:"));
1415
+ console.log();
1416
+ const maxLen = Math.max(...Object.keys(commands).map((k) => k.length));
1417
+ for (const [name, cmd] of Object.entries(commands)) {
1418
+ console.log(chalk16.cyan(` ${name.padEnd(maxLen + 2)}`) + chalk16.gray(cmd.description));
1419
+ }
1420
+ console.log();
1421
+ console.log(chalk16.gray(" help") + chalk16.gray("".padEnd(maxLen - 2)) + chalk16.gray("Show this help"));
1422
+ console.log(chalk16.gray(" clear") + chalk16.gray("".padEnd(maxLen - 3)) + chalk16.gray("Clear the screen"));
1423
+ console.log(chalk16.gray(" exit") + chalk16.gray("".padEnd(maxLen - 2)) + chalk16.gray("Exit the CLI"));
1424
+ console.log();
1425
+ }
1426
+ async function startRepl() {
1427
+ const user = getConfig("user");
1428
+ printBanner(VERSION, user?.email);
1429
+ const cwd = process.cwd().split("/").pop() || "~";
1430
+ const rl = createInterface({
1431
+ input: process.stdin,
1432
+ output: process.stdout,
1433
+ prompt: chalk16.hex("#2563EB")("riventa") + chalk16.gray(`:${cwd}`) + chalk16.white("> "),
1434
+ completer: (line) => {
1435
+ const completions = [...Object.keys(commands), "help", "clear", "exit"];
1436
+ const hits = completions.filter((c) => c.startsWith(line.trim()));
1437
+ return [hits.length ? hits : completions, line];
1438
+ }
1439
+ });
1440
+ rl.prompt();
1441
+ rl.on("line", async (line) => {
1442
+ const input = line.trim();
1443
+ const [cmd, ...args2] = input.split(/\s+/);
1444
+ if (!cmd) {
1445
+ rl.prompt();
1446
+ return;
1447
+ }
1448
+ if (cmd === "exit" || cmd === "quit") {
1449
+ console.log(chalk16.gray("\n Goodbye!\n"));
1450
+ process.exit(0);
1451
+ }
1452
+ if (cmd === "help") {
1453
+ showHelp();
1454
+ rl.prompt();
1455
+ return;
1456
+ }
1457
+ if (cmd === "clear") {
1458
+ console.clear();
1459
+ const u = getConfig("user");
1460
+ printBanner(VERSION, u?.email);
1461
+ rl.prompt();
1462
+ return;
1463
+ }
1464
+ if (cmd === "version") {
1465
+ console.log(chalk16.gray(`
1466
+ v${VERSION}
1467
+ `));
1468
+ rl.prompt();
1469
+ return;
1470
+ }
1471
+ const command = commands[cmd];
1472
+ if (!command) {
1473
+ console.log(chalk16.red(`
1474
+ Unknown command: ${cmd}`));
1475
+ console.log(chalk16.gray(" Type ") + chalk16.cyan("help") + chalk16.gray(" to see available commands.\n"));
1476
+ rl.prompt();
1477
+ return;
1478
+ }
1479
+ try {
1480
+ const originalExit = process.exit;
1481
+ process.exit = (() => {
1482
+ throw new Error("__REPL_EXIT__");
1483
+ });
1484
+ await command.action({ ...Object.fromEntries(args2.map((a, i) => [i, a])) });
1485
+ process.exit = originalExit;
1486
+ } catch (err) {
1487
+ if (err?.message !== "__REPL_EXIT__") {
1488
+ console.log(chalk16.red(`
1489
+ Error: ${err.message}
1490
+ `));
1491
+ }
1492
+ process.exit = (await import("process")).exit;
1493
+ }
1494
+ console.log();
1495
+ rl.prompt();
1496
+ });
1497
+ rl.on("close", () => {
1498
+ console.log(chalk16.gray("\n Goodbye!\n"));
1499
+ process.exit(0);
1500
+ });
1501
+ }
1502
+ var VERSION, commands;
1503
+ var init_repl = __esm({
1504
+ "src/repl.ts"() {
1505
+ "use strict";
1506
+ init_api();
1507
+ init_banner();
1508
+ init_login();
1509
+ init_init();
1510
+ init_deploy();
1511
+ init_review();
1512
+ init_status();
1513
+ init_logs();
1514
+ init_rollback();
1515
+ init_config();
1516
+ init_projects();
1517
+ init_whoami();
1518
+ init_security();
1519
+ init_health();
1520
+ init_dashboard();
1521
+ VERSION = "1.2.0";
1522
+ commands = {
1523
+ login: { description: "Sign in via browser", action: loginCommand },
1524
+ logout: { description: "Log out and clear credentials", action: async () => {
1525
+ const Conf3 = (await import("conf")).default;
1526
+ const config3 = new Conf3({ projectName: "riventa-cli" });
1527
+ config3.clear();
1528
+ console.log(chalk16.green("\n Logged out successfully. Credentials cleared.\n"));
1529
+ } },
1530
+ whoami: { description: "Show current authenticated user", action: whoamiCommand },
1531
+ init: { description: "Initialize Riventa in current directory", action: initCommand },
1532
+ projects: { description: "List and switch between projects", action: projectsCommand },
1533
+ deploy: { description: "Deploy current branch", action: deployCommand },
1534
+ status: { description: "View project and deployment status", action: statusCommand },
1535
+ logs: { description: "View deployment logs", action: logsCommand },
1536
+ rollback: { description: "Rollback to a previous deployment", action: rollbackCommand },
1537
+ review: { description: "Run AI code review on changes", action: reviewCommand },
1538
+ security: { description: "Security scanning and score", action: securityCommand },
1539
+ config: { description: "Manage CLI configuration", action: configCommand },
1540
+ health: { description: "Check API connectivity and status", action: healthCommand },
1541
+ dashboard: { description: "Open dashboard in browser", action: dashboardCommand },
1542
+ open: { description: "Open dashboard in browser", action: () => dashboardCommand({}) }
1543
+ };
1544
+ }
1545
+ });
1272
1546
 
1273
1547
  // src/index.ts
1274
- var VERSION = "1.1.2";
1548
+ init_login();
1549
+ init_init();
1550
+ init_deploy();
1551
+ init_review();
1552
+ init_status();
1553
+ init_logs();
1554
+ init_rollback();
1555
+ init_config();
1556
+ init_projects();
1557
+ init_whoami();
1558
+ init_security();
1559
+ init_health();
1560
+ init_dashboard();
1561
+ init_api();
1562
+ init_banner();
1563
+ import { Command } from "commander";
1564
+ import chalk17 from "chalk";
1565
+ var VERSION2 = "1.2.0";
1275
1566
  var program = new Command();
1276
- program.name("riventa").description(chalk15.cyan("Riventa.Dev CLI") + chalk15.gray(" \u2014 AI-powered DevOps automation")).version(VERSION).addHelpText("beforeAll", () => {
1567
+ program.name("riventa").description(chalk17.cyan("Riventa.Dev CLI") + chalk17.gray(" \u2014 AI-powered DevOps automation")).version(VERSION2).addHelpText("beforeAll", () => {
1277
1568
  const user = getConfig("user");
1278
- printBanner(VERSION, user?.email);
1569
+ printBanner(VERSION2, user?.email);
1279
1570
  return "";
1280
1571
  }).addHelpText("after", `
1281
- ${chalk15.bold("Quick Start:")}
1282
- ${chalk15.gray("$")} riventa login Sign in via browser
1283
- ${chalk15.gray("$")} riventa init Initialize a project
1284
- ${chalk15.gray("$")} riventa review Run AI code review
1285
- ${chalk15.gray("$")} riventa deploy Deploy to production
1572
+ ${chalk17.bold("Quick Start:")}
1573
+ ${chalk17.gray("$")} riventa login Sign in via browser
1574
+ ${chalk17.gray("$")} riventa init Initialize a project
1575
+ ${chalk17.gray("$")} riventa review Run AI code review
1576
+ ${chalk17.gray("$")} riventa deploy Deploy to production
1286
1577
 
1287
- ${chalk15.bold("Documentation:")}
1288
- ${chalk15.gray("https://riventa.dev/developers/cli")}
1578
+ ${chalk17.bold("Documentation:")}
1579
+ ${chalk17.gray("https://riventa.dev/developers/cli")}
1289
1580
  `);
1290
1581
  program.command("login").description("Authenticate with Riventa.Dev").action(loginCommand);
1291
1582
  program.command("logout").description("Log out and clear credentials").action(async () => {
1292
1583
  const Conf3 = (await import("conf")).default;
1293
1584
  const config3 = new Conf3({ projectName: "riventa-cli" });
1294
1585
  config3.clear();
1295
- console.log(chalk15.green("\n Logged out successfully. Credentials cleared.\n"));
1586
+ console.log(chalk17.green("\n Logged out successfully. Credentials cleared.\n"));
1296
1587
  });
1297
1588
  program.command("whoami").description("Show current authenticated user").action(whoamiCommand);
1298
1589
  program.command("init").description("Initialize Riventa in current directory").action(initCommand);
@@ -1306,4 +1597,11 @@ program.command("security").description("Security scanning and score").option("-
1306
1597
  program.command("config").description("Manage CLI configuration").option("--get <key>", "Get a config value").option("--set <key=value>", "Set a config value").option("--list", "List all config values").action(configCommand);
1307
1598
  program.command("config:update <instruction>").description("Update .riventa.yml with AI").action(configUpdateCommand);
1308
1599
  program.command("health").description("Check API connectivity and status").action(healthCommand);
1309
- program.parse();
1600
+ program.command("dashboard").description("Open dashboard in browser").option("-p, --page <page>", "Page to open (reviews, deployments, analytics, settings, api-keys, flags, monitoring)").action(dashboardCommand);
1601
+ program.command("open").description("Open current project in browser").action(() => dashboardCommand({}));
1602
+ var args = process.argv.slice(2);
1603
+ if (args.length === 0) {
1604
+ Promise.resolve().then(() => (init_repl(), repl_exports)).then(({ startRepl: startRepl2 }) => startRepl2());
1605
+ } else {
1606
+ program.parse();
1607
+ }
@@ -0,0 +1,134 @@
1
+ import {
2
+ configCommand,
3
+ deployCommand,
4
+ getConfig,
5
+ healthCommand,
6
+ initCommand,
7
+ loginCommand,
8
+ logsCommand,
9
+ printBanner,
10
+ projectsCommand,
11
+ reviewCommand,
12
+ rollbackCommand,
13
+ securityCommand,
14
+ statusCommand,
15
+ whoamiCommand
16
+ } from "./chunk-BMS2NG3R.js";
17
+
18
+ // src/repl.ts
19
+ import { createInterface } from "readline";
20
+ import chalk from "chalk";
21
+ var VERSION = "1.1.2";
22
+ var commands = {
23
+ login: { description: "Sign in via browser", action: loginCommand },
24
+ logout: { description: "Log out and clear credentials", action: async () => {
25
+ const Conf = (await import("conf")).default;
26
+ const config = new Conf({ projectName: "riventa-cli" });
27
+ config.clear();
28
+ console.log(chalk.green("\n Logged out successfully. Credentials cleared.\n"));
29
+ } },
30
+ whoami: { description: "Show current authenticated user", action: whoamiCommand },
31
+ init: { description: "Initialize Riventa in current directory", action: initCommand },
32
+ projects: { description: "List and switch between projects", action: projectsCommand },
33
+ deploy: { description: "Deploy current branch", action: deployCommand },
34
+ status: { description: "View project and deployment status", action: statusCommand },
35
+ logs: { description: "View deployment logs", action: logsCommand },
36
+ rollback: { description: "Rollback to a previous deployment", action: rollbackCommand },
37
+ review: { description: "Run AI code review on changes", action: reviewCommand },
38
+ security: { description: "Security scanning and score", action: securityCommand },
39
+ config: { description: "Manage CLI configuration", action: configCommand },
40
+ health: { description: "Check API connectivity and status", action: healthCommand }
41
+ };
42
+ function showHelp() {
43
+ console.log();
44
+ console.log(chalk.bold(" Available commands:"));
45
+ console.log();
46
+ const maxLen = Math.max(...Object.keys(commands).map((k) => k.length));
47
+ for (const [name, cmd] of Object.entries(commands)) {
48
+ console.log(chalk.cyan(` ${name.padEnd(maxLen + 2)}`) + chalk.gray(cmd.description));
49
+ }
50
+ console.log();
51
+ console.log(chalk.gray(" help") + chalk.gray("".padEnd(maxLen - 2)) + chalk.gray("Show this help"));
52
+ console.log(chalk.gray(" clear") + chalk.gray("".padEnd(maxLen - 3)) + chalk.gray("Clear the screen"));
53
+ console.log(chalk.gray(" exit") + chalk.gray("".padEnd(maxLen - 2)) + chalk.gray("Exit the CLI"));
54
+ console.log();
55
+ }
56
+ async function startRepl() {
57
+ const user = getConfig("user");
58
+ printBanner(VERSION, user?.email);
59
+ const cwd = process.cwd().split("/").pop() || "~";
60
+ const rl = createInterface({
61
+ input: process.stdin,
62
+ output: process.stdout,
63
+ prompt: chalk.hex("#2563EB")("riventa") + chalk.gray(`:${cwd}`) + chalk.white("> "),
64
+ completer: (line) => {
65
+ const completions = [...Object.keys(commands), "help", "clear", "exit"];
66
+ const hits = completions.filter((c) => c.startsWith(line.trim()));
67
+ return [hits.length ? hits : completions, line];
68
+ }
69
+ });
70
+ rl.prompt();
71
+ rl.on("line", async (line) => {
72
+ const input = line.trim();
73
+ const [cmd, ...args] = input.split(/\s+/);
74
+ if (!cmd) {
75
+ rl.prompt();
76
+ return;
77
+ }
78
+ if (cmd === "exit" || cmd === "quit") {
79
+ console.log(chalk.gray("\n Goodbye!\n"));
80
+ process.exit(0);
81
+ }
82
+ if (cmd === "help") {
83
+ showHelp();
84
+ rl.prompt();
85
+ return;
86
+ }
87
+ if (cmd === "clear") {
88
+ console.clear();
89
+ const u = getConfig("user");
90
+ printBanner(VERSION, u?.email);
91
+ rl.prompt();
92
+ return;
93
+ }
94
+ if (cmd === "version") {
95
+ console.log(chalk.gray(`
96
+ v${VERSION}
97
+ `));
98
+ rl.prompt();
99
+ return;
100
+ }
101
+ const command = commands[cmd];
102
+ if (!command) {
103
+ console.log(chalk.red(`
104
+ Unknown command: ${cmd}`));
105
+ console.log(chalk.gray(" Type ") + chalk.cyan("help") + chalk.gray(" to see available commands.\n"));
106
+ rl.prompt();
107
+ return;
108
+ }
109
+ try {
110
+ const originalExit = process.exit;
111
+ process.exit = (() => {
112
+ throw new Error("__REPL_EXIT__");
113
+ });
114
+ await command.action({ ...Object.fromEntries(args.map((a, i) => [i, a])) });
115
+ process.exit = originalExit;
116
+ } catch (err) {
117
+ if (err?.message !== "__REPL_EXIT__") {
118
+ console.log(chalk.red(`
119
+ Error: ${err.message}
120
+ `));
121
+ }
122
+ process.exit = (await import("process")).exit;
123
+ }
124
+ console.log();
125
+ rl.prompt();
126
+ });
127
+ rl.on("close", () => {
128
+ console.log(chalk.gray("\n Goodbye!\n"));
129
+ process.exit(0);
130
+ });
131
+ }
132
+ export {
133
+ startRepl
134
+ };
package/dist/repl.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ declare function startRepl(): Promise<void>;
2
+
3
+ export { startRepl };