@makoojs/cli 0.5.0 → 0.5.1

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/bin.js CHANGED
@@ -659,8 +659,8 @@ import { createLogUpdate } from "log-update";
659
659
  // src/vite/makooDev.ts
660
660
  var bindDevSession = /* @__PURE__ */ Symbol("makooDev.bindSession");
661
661
 
662
- // src/cli/tasks/renderTasks.ts
663
- import Table from "cli-table3";
662
+ // src/cli/injections/renderInjections.ts
663
+ import { stripVTControlCharacters } from "util";
664
664
 
665
665
  // src/cli/terminalColor.ts
666
666
  var ansi = {
@@ -675,21 +675,116 @@ var ansi = {
675
675
  };
676
676
  var colorize = (value, ...codes) => `${codes.join("")}${value}${ansi.reset}`;
677
677
 
678
- // src/cli/tasks/renderTasks.ts
679
- function renderTaskStatus(status) {
680
- switch (status) {
681
- case "active":
682
- return colorize("\u25CF active", ansi.green);
683
- case "pending":
684
- return colorize("\u25CF pending", ansi.yellow);
685
- case "idle":
686
- return colorize("\u25CF idle", ansi.dim);
678
+ // src/cli/injections/renderInjections.ts
679
+ var MAX_ERROR_LENGTH = 120;
680
+ var MAX_NAME_LENGTH = 40;
681
+ var COLUMN_GAP = 2;
682
+ var ATTACHED_INDENT = " ";
683
+ var STATUS_ORDER = ["mounted", "bound", "waiting", "failed", "idle"];
684
+ var STATUS_COLORS = {
685
+ mounted: ansi.green,
686
+ bound: ansi.green,
687
+ waiting: ansi.yellow,
688
+ failed: ansi.red,
689
+ idle: ansi.dim
690
+ };
691
+ function visibleLength(value) {
692
+ return stripVTControlCharacters(value).length;
693
+ }
694
+ function padEndVisible(value, width) {
695
+ const pad = width - visibleLength(value);
696
+ return pad > 0 ? `${value}${" ".repeat(pad)}` : value;
697
+ }
698
+ function truncateDisplayName(name) {
699
+ if (name.length <= MAX_NAME_LENGTH) return name;
700
+ return `${name.slice(0, MAX_NAME_LENGTH - 1)}\u2026`;
701
+ }
702
+ function attachedDisplayName(name) {
703
+ return `\u2514 ${truncateDisplayName(name)}`;
704
+ }
705
+ function renderStatus(status) {
706
+ return colorize(`\u25CF ${status}`, STATUS_COLORS[status]);
707
+ }
708
+ function renderError(error) {
709
+ let text = `${error.code}: ${error.message}`;
710
+ if (error.cause !== void 0) text += ` (cause: ${error.cause})`;
711
+ text = text.replaceAll("\n", " \xB7 ");
712
+ if (text.length > MAX_ERROR_LENGTH) text = `${text.slice(0, MAX_ERROR_LENGTH - 1)}\u2026`;
713
+ return text;
714
+ }
715
+ function kindLabel(injection) {
716
+ return injection.kind === "component" ? "component" : "standalone listener";
717
+ }
718
+ function columnWidths(injections) {
719
+ let status = visibleLength("STATUS");
720
+ let name = visibleLength("NAME");
721
+ let attachedName = 0;
722
+ for (const injection of injections) {
723
+ status = Math.max(status, visibleLength(renderStatus(injection.status)));
724
+ name = Math.max(name, visibleLength(truncateDisplayName(injection.name)));
725
+ if (injection.kind !== "component") continue;
726
+ for (const listener of injection.attachedListeners) {
727
+ status = Math.max(status, visibleLength(renderStatus(listener.status)));
728
+ attachedName = Math.max(
729
+ attachedName,
730
+ visibleLength(attachedDisplayName(listener.name))
731
+ );
732
+ }
733
+ }
734
+ return { status, name, attachedName };
735
+ }
736
+ function renderTopLevelRow(injection, widths) {
737
+ const status = padEndVisible(renderStatus(injection.status), widths.status);
738
+ const name = padEndVisible(
739
+ colorize(truncateDisplayName(injection.name), ansi.bold, ansi.cyan),
740
+ widths.name
741
+ );
742
+ const kind = colorize(kindLabel(injection), ansi.deepPink);
743
+ const gap = " ".repeat(COLUMN_GAP);
744
+ return `${status}${gap}${name}${gap}${kind}`;
745
+ }
746
+ function renderAttachedRow(listener, widths) {
747
+ const status = padEndVisible(renderStatus(listener.status), widths.status);
748
+ const name = padEndVisible(attachedDisplayName(listener.name), widths.attachedName);
749
+ const kind = colorize("attached listener", ansi.dim);
750
+ const gap = " ".repeat(COLUMN_GAP);
751
+ return `${ATTACHED_INDENT}${status}${gap}${name}${gap}${kind}`;
752
+ }
753
+ function renderInjectionBlock(injection, widths) {
754
+ const lines = [renderTopLevelRow(injection, widths)];
755
+ if (injection.status === "failed" && injection.lastError) {
756
+ lines.push(colorize(`${ATTACHED_INDENT}${renderError(injection.lastError)}`, ansi.red));
757
+ }
758
+ if (injection.kind !== "component") return lines;
759
+ for (const listener of injection.attachedListeners) {
760
+ lines.push(renderAttachedRow(listener, widths));
687
761
  }
762
+ return lines;
763
+ }
764
+ function renderHeader(widths) {
765
+ const gap = " ".repeat(COLUMN_GAP);
766
+ return [
767
+ padEndVisible(colorize("STATUS", ansi.bold), widths.status),
768
+ padEndVisible(colorize("NAME", ansi.bold), widths.name),
769
+ colorize("KIND", ansi.bold)
770
+ ].join(gap);
771
+ }
772
+ function renderDiagnostic(diagnostic) {
773
+ const error = colorize(renderError(diagnostic.error), ansi.red);
774
+ if (diagnostic.name === void 0) return ` ${error}`;
775
+ return ` ${colorize(diagnostic.name, ansi.bold, ansi.cyan)} ${error}`;
688
776
  }
689
- function renderTasksTable(sanpshots) {
690
- const tasks = sanpshots.flatMap((runtime) => runtime.tasks);
691
- const lines = [colorize("Makoo Tasks", ansi.bold, ansi.deepPink), ""];
692
- if (sanpshots.length === 0) {
777
+ function renderSummary(injections) {
778
+ const total = injections.length === 1 ? "1 injection" : `${injections.length} injections`;
779
+ const counts = STATUS_ORDER.flatMap((status) => {
780
+ const count = injections.filter((injection) => injection.status === status).length;
781
+ return count === 0 ? [] : [colorize(`${count} ${status}`, STATUS_COLORS[status])];
782
+ });
783
+ return [total, ...counts].join(" \xB7 ");
784
+ }
785
+ function renderInjectionsTable(snapshots) {
786
+ const lines = [colorize("Makoo Injections", ansi.bold, ansi.deepPink), ""];
787
+ if (snapshots.length === 0) {
693
788
  lines.push(
694
789
  colorize("\u25CF Runtime Session disconnected.", ansi.yellow),
695
790
  "",
@@ -697,45 +792,39 @@ function renderTasksTable(sanpshots) {
697
792
  );
698
793
  return lines.join("\n");
699
794
  }
700
- if (tasks.length === 0) {
701
- lines.push("No tasks registered.");
795
+ const visible = snapshots.filter(
796
+ (runtime) => runtime.injections.length > 0 || runtime.diagnostics.length > 0
797
+ );
798
+ if (visible.length === 0) {
799
+ lines.push("No injections registered.");
702
800
  return lines.join("\n");
703
801
  }
704
- const showLabel = sanpshots.length > 1;
705
- const showClient = new Set(sanpshots.map((runtime) => runtime.clientId)).size > 1;
706
- for (const [index, runtime] of sanpshots.entries()) {
707
- if (runtime.tasks.length === 0) continue;
802
+ const showLabel = snapshots.length > 1;
803
+ const showClient = new Set(snapshots.map((runtime) => runtime.clientId)).size > 1;
804
+ for (const [index, runtime] of visible.entries()) {
708
805
  if (showLabel) {
709
806
  let label = `Makoo${runtime.runtimeId}`;
710
- if (showClient) {
711
- label = `Client ${runtime.clientId} \xB7 ${label}`;
712
- }
807
+ if (showClient) label = `Client ${runtime.clientId} \xB7 ${label}`;
713
808
  lines.push(colorize(label, ansi.bold), "");
714
809
  }
715
- const table = new Table({
716
- head: ["STATUS", "ID", "KIND", "TARGET"].map((heading) => colorize(heading, ansi.bold)),
717
- style: { border: [], head: [] }
718
- });
719
- for (const task of runtime.tasks) {
720
- table.push([
721
- renderTaskStatus(task.status),
722
- colorize(task.taskId, ansi.bold, ansi.cyan),
723
- colorize(task.kind, ansi.deepPink),
724
- colorize(`\u2192 ${task.injectAt}`, ansi.dim)
725
- ]);
810
+ if (runtime.injections.length > 0) {
811
+ const widths = columnWidths(runtime.injections);
812
+ lines.push(renderHeader(widths));
813
+ for (const injection of runtime.injections) {
814
+ lines.push(...renderInjectionBlock(injection, widths));
815
+ }
726
816
  }
727
- lines.push(table.toString());
728
- if (index < sanpshots.length - 1) lines.push("");
729
- }
730
- const active = tasks.filter((task) => task.status === "active").length;
731
- const pending = tasks.filter((task) => task.status === "pending").length;
732
- const idle = tasks.filter((task) => task.status === "idle").length;
733
- let total = `${tasks.length} tasks`;
734
- if (tasks.length === 1) total = "1 task";
735
- lines.push(
736
- "",
737
- `${total} \xB7 ${colorize(`${active} active`, ansi.green)} \xB7 ${colorize(`${pending} pending`, ansi.yellow)} \xB7 ${colorize(`${idle} idle`, ansi.dim)}`
738
- );
817
+ if (runtime.diagnostics.length > 0) {
818
+ if (runtime.injections.length > 0) lines.push("");
819
+ lines.push(
820
+ colorize("Diagnostics", ansi.bold),
821
+ ...runtime.diagnostics.map(renderDiagnostic)
822
+ );
823
+ }
824
+ if (index < visible.length - 1) lines.push("");
825
+ }
826
+ const injections = visible.flatMap((runtime) => runtime.injections);
827
+ if (injections.length > 0) lines.push("", renderSummary(injections));
739
828
  return lines.join("\n");
740
829
  }
741
830
 
@@ -810,7 +899,7 @@ var DevTerminal = class {
810
899
  this.show("home");
811
900
  this.bindShortcuts();
812
901
  } else {
813
- const runtimes = this.session.getTasks();
902
+ const runtimes = this.session.getRuntimeSnapshots();
814
903
  this.runtimeCount = runtimes.length;
815
904
  this.logger.info(this.renderHome(runtimes));
816
905
  }
@@ -830,7 +919,7 @@ var DevTerminal = class {
830
919
  // Session events, navigation and new logs all redraw through this entry point.
831
920
  refresh = () => {
832
921
  if (!this.ready || this.closed || !this.session) return;
833
- const runtimes = this.session.getTasks();
922
+ const runtimes = this.session.getRuntimeSnapshots();
834
923
  this.selectedRuntime = runtimes.length === 0 ? 0 : this.selectedRuntime % runtimes.length;
835
924
  if (!this.interactive) {
836
925
  if (this.runtimeCount !== runtimes.length) {
@@ -846,9 +935,9 @@ var DevTerminal = class {
846
935
  "Press a key to select an action. Press Ctrl+C to stop."
847
936
  );
848
937
  break;
849
- case "tasks":
938
+ case "injections":
850
939
  this.draw(
851
- this.renderTasks(runtimes),
940
+ this.renderInjections(runtimes),
852
941
  "Press t or Esc to return home. Press Ctrl+C to stop."
853
942
  );
854
943
  break;
@@ -901,18 +990,18 @@ var DevTerminal = class {
901
990
  `
902
991
  ${colorize("Actions", ansi.bold)}`,
903
992
  ...this.hasInstallationPage() ? [` ${colorize("i", ansi.bold, ansi.cyan)} Open installation page`] : [],
904
- ` ${colorize("t", ansi.bold, ansi.cyan)} View runtime tasks`,
993
+ ` ${colorize("t", ansi.bold, ansi.cyan)} View runtime injections`,
905
994
  ` ${colorize("l", ansi.bold, ansi.cyan)} View logs`,
906
995
  ` ${colorize("r", ansi.bold, ansi.cyan)} Restart server`,
907
996
  ` ${colorize("h", ansi.bold, ansi.cyan)} Show help`
908
997
  ].join("\n");
909
998
  }
910
- renderTasks(runtimes) {
911
- if (runtimes.length === 0) return "Makoo Tasks\n\nWaiting for a browser runtime";
999
+ renderInjections(runtimes) {
1000
+ if (runtimes.length === 0) return "Makoo Injections\n\nWaiting for a browser runtime";
912
1001
  const runtime = runtimes[this.selectedRuntime];
913
1002
  return [
914
1003
  `Runtime ${this.selectedRuntime + 1}/${runtimes.length} \xB7 Client ${runtime.clientId} \xB7 Makoo${runtime.runtimeId}`,
915
- renderTasksTable([runtime]),
1004
+ renderInjectionsTable([runtime]),
916
1005
  ...runtimes.length > 1 ? ["Press n to view the next runtime."] : []
917
1006
  ].join("\n\n");
918
1007
  }
@@ -924,8 +1013,8 @@ var DevTerminal = class {
924
1013
  ` ${colorize("i", ansi.bold, ansi.cyan)} open development script installation page`
925
1014
  ] : [],
926
1015
  ...[
927
- ["t", "toggle Runtime tasks"],
928
- ["n", "view next runtime tasks"],
1016
+ ["t", "toggle runtime injections"],
1017
+ ["n", "view next runtime injections"],
929
1018
  ["l", "view logs / return home"],
930
1019
  ["r", "restart the server"],
931
1020
  ["u", "show server URLs"],
@@ -991,11 +1080,11 @@ var DevTerminal = class {
991
1080
  try {
992
1081
  switch (key.name) {
993
1082
  case "t":
994
- this.show(this.currentView === "tasks" ? "home" : "tasks");
1083
+ this.show(this.currentView === "injections" ? "home" : "injections");
995
1084
  break;
996
1085
  case "n":
997
1086
  this.selectedRuntime += 1;
998
- this.show("tasks");
1087
+ this.show("injections");
999
1088
  break;
1000
1089
  case "l":
1001
1090
  this.show(this.currentView === "logs" ? "home" : "logs");
@@ -1,6 +1,6 @@
1
1
  import { Logger, ViteDevServer } from 'vite';
2
2
  import { DevSession } from '../../../session/DevSession';
3
- type DevView = 'home' | 'tasks' | 'help' | 'logs';
3
+ type DevView = 'home' | 'injections' | 'help' | 'logs';
4
4
  export declare class DevTerminal {
5
5
  private readonly server;
6
6
  private readonly cliVersion;
@@ -34,7 +34,7 @@ export declare class DevTerminal {
34
34
  private renderBanner;
35
35
  private renderRuntimeStatus;
36
36
  private renderHome;
37
- private renderTasks;
37
+ private renderInjections;
38
38
  private renderHelp;
39
39
  private draw;
40
40
  private hasInstallationPage;
@@ -0,0 +1,2 @@
1
+ import { RuntimeSnapshot } from '../../session/types';
2
+ export declare function renderInjectionsTable(snapshots: RuntimeSnapshot[]): string;
@@ -1,14 +1,3 @@
1
- import { MakooError, MakooIssue } from '../../../../../core';
2
- export declare const ErrorCode: {
1
+ export declare const CliErrorCode: {
3
2
  readonly CLI_CONFIG_INVALID: "MAKOO_CLI_CONFIG_INVALID";
4
3
  };
5
- export type ErrorCodeValue = (typeof ErrorCode)[keyof typeof ErrorCode];
6
- export interface ValidationIssue {
7
- code: string;
8
- path: PropertyKey[];
9
- message: string;
10
- }
11
- export declare class ConfigValidationError extends MakooError {
12
- constructor(issues: MakooIssue[], code?: string, cause?: Error);
13
- }
14
- export declare function toMakooIssue(issue: ValidationIssue): MakooIssue;