@makoojs/cli 0.5.1 → 0.6.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/DevTerminal-BtHO2wRA.js +2396 -0
- package/dist/DevTerminal-DNh8U_O4.cjs +30 -0
- package/dist/bin.js +29 -580
- package/dist/bridge/protocol.d.ts +64 -0
- package/dist/bridge/runtime.cjs +1 -0
- package/dist/bridge/runtime.d.ts +38 -0
- package/dist/bridge/runtime.js +168 -0
- package/dist/bridge/server.d.ts +15 -0
- package/dist/bridge/store.d.ts +17 -0
- package/dist/commands/version.d.ts +1 -0
- package/dist/config/resolve.d.ts +1 -5
- package/dist/config/types.d.ts +40 -9
- package/dist/errors.d.ts +766 -0
- package/dist/index.cjs +2 -149
- package/dist/index.d.ts +1 -1
- package/dist/index.js +216 -2934
- package/dist/monkey/clipboard.d.ts +2 -0
- package/dist/monkey/download.d.ts +2 -0
- package/dist/monkey/index.d.ts +1 -0
- package/dist/monkey/info.d.ts +3 -0
- package/dist/monkey/menu.d.ts +3 -0
- package/dist/monkey/notification.d.ts +2 -0
- package/dist/monkey/request.d.ts +8 -0
- package/dist/monkey/resource.d.ts +3 -0
- package/dist/monkey/storage.d.ts +10 -0
- package/dist/monkey/style.d.ts +3 -0
- package/dist/monkey/tab.d.ts +5 -0
- package/dist/protocol-D8uLFi4g.cjs +1 -0
- package/dist/protocol-ZRHs80xs.js +4 -0
- package/dist/{cli/commands/dev → tui}/DevTerminal.d.ts +12 -6
- package/dist/{cli/injections → tui}/renderInjections.d.ts +1 -1
- package/dist/version-DiRsgSMp.js +19 -0
- package/dist/version-ENbM57wf.cjs +1 -0
- package/dist/vite/makoo.d.ts +3 -0
- package/dist/vite/makooDev.d.ts +28 -6
- package/package.json +5 -6
- package/dist/cli/version.d.ts +0 -1
- package/dist/config/defaults.d.ts +0 -5
- package/dist/config/errors.d.ts +0 -3
- package/dist/config/validation.d.ts +0 -11
- package/dist/session/DevSession.d.ts +0 -14
- package/dist/session/types.d.ts +0 -47
- /package/dist/{cli → commands}/bin.d.ts +0 -0
- /package/dist/{cli/commands → commands}/build.d.ts +0 -0
- /package/dist/{cli/commands/dev → commands}/dev.d.ts +0 -0
- /package/dist/{cli/commands → commands}/preview.d.ts +0 -0
- /package/dist/{cli → tui}/terminalColor.d.ts +0 -0
package/dist/bin.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
// src/
|
|
4
|
-
import {
|
|
3
|
+
// src/commands/bin.ts
|
|
4
|
+
import { isMakooError } from "@makoojs/core";
|
|
5
5
|
|
|
6
6
|
// ../../node_modules/.pnpm/cac@7.0.0/node_modules/cac/dist/index.js
|
|
7
7
|
function toArr(any) {
|
|
@@ -619,22 +619,39 @@ var CAC = class extends EventTarget {
|
|
|
619
619
|
};
|
|
620
620
|
var cac = (name = "") => new CAC(name);
|
|
621
621
|
|
|
622
|
-
// src/
|
|
622
|
+
// src/commands/build.ts
|
|
623
623
|
import { build } from "vite";
|
|
624
624
|
async function buildCommand(config) {
|
|
625
625
|
await build(config);
|
|
626
626
|
}
|
|
627
627
|
|
|
628
|
-
// src/
|
|
628
|
+
// src/commands/dev.ts
|
|
629
629
|
import { createServer } from "vite";
|
|
630
|
+
async function devCommand(config) {
|
|
631
|
+
const server = await createServer(config);
|
|
632
|
+
try {
|
|
633
|
+
await server.listen();
|
|
634
|
+
server.printUrls();
|
|
635
|
+
server.bindCLIShortcuts({ print: true });
|
|
636
|
+
} catch (error) {
|
|
637
|
+
await server.close();
|
|
638
|
+
throw error;
|
|
639
|
+
}
|
|
640
|
+
}
|
|
630
641
|
|
|
631
|
-
// src/
|
|
642
|
+
// src/commands/preview.ts
|
|
643
|
+
import { preview } from "vite";
|
|
644
|
+
async function previewCommand(config) {
|
|
645
|
+
const server = await preview(config);
|
|
646
|
+
server.printUrls();
|
|
647
|
+
server.bindCLIShortcuts({ print: true });
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
// src/commands/version.ts
|
|
632
651
|
import { readFile } from "fs/promises";
|
|
633
652
|
import { dirname, join } from "path";
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
if (cliVersionCache) return cliVersionCache;
|
|
637
|
-
let currentDir = dirname(fileURLToPath(import.meta.url));
|
|
653
|
+
async function loadCliVersion() {
|
|
654
|
+
let currentDir = import.meta.dirname ?? (typeof __dirname !== "undefined" ? __dirname : process.cwd());
|
|
638
655
|
while (true) {
|
|
639
656
|
const packagePath = join(currentDir, "package.json");
|
|
640
657
|
try {
|
|
@@ -652,575 +669,7 @@ async function loadCliVersion(cliVersionCache) {
|
|
|
652
669
|
return "0.0.0";
|
|
653
670
|
}
|
|
654
671
|
|
|
655
|
-
// src/
|
|
656
|
-
import { emitKeypressEvents } from "readline";
|
|
657
|
-
import { createLogUpdate } from "log-update";
|
|
658
|
-
|
|
659
|
-
// src/vite/makooDev.ts
|
|
660
|
-
var bindDevSession = /* @__PURE__ */ Symbol("makooDev.bindSession");
|
|
661
|
-
|
|
662
|
-
// src/cli/injections/renderInjections.ts
|
|
663
|
-
import { stripVTControlCharacters } from "util";
|
|
664
|
-
|
|
665
|
-
// src/cli/terminalColor.ts
|
|
666
|
-
var ansi = {
|
|
667
|
-
reset: "\x1B[0m",
|
|
668
|
-
bold: "\x1B[1m",
|
|
669
|
-
cyan: "\x1B[36m",
|
|
670
|
-
deepPink: "\x1B[38;5;162m",
|
|
671
|
-
green: "\x1B[32m",
|
|
672
|
-
red: "\x1B[31m",
|
|
673
|
-
yellow: "\x1B[33m",
|
|
674
|
-
dim: "\x1B[2m"
|
|
675
|
-
};
|
|
676
|
-
var colorize = (value, ...codes) => `${codes.join("")}${value}${ansi.reset}`;
|
|
677
|
-
|
|
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));
|
|
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}`;
|
|
776
|
-
}
|
|
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) {
|
|
788
|
-
lines.push(
|
|
789
|
-
colorize("\u25CF Runtime Session disconnected.", ansi.yellow),
|
|
790
|
-
"",
|
|
791
|
-
colorize("Waiting for reconnection.", ansi.dim)
|
|
792
|
-
);
|
|
793
|
-
return lines.join("\n");
|
|
794
|
-
}
|
|
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.");
|
|
800
|
-
return lines.join("\n");
|
|
801
|
-
}
|
|
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()) {
|
|
805
|
-
if (showLabel) {
|
|
806
|
-
let label = `Makoo${runtime.runtimeId}`;
|
|
807
|
-
if (showClient) label = `Client ${runtime.clientId} \xB7 ${label}`;
|
|
808
|
-
lines.push(colorize(label, ansi.bold), "");
|
|
809
|
-
}
|
|
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
|
-
}
|
|
816
|
-
}
|
|
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));
|
|
828
|
-
return lines.join("\n");
|
|
829
|
-
}
|
|
830
|
-
|
|
831
|
-
// src/cli/commands/dev/DevTerminal.ts
|
|
832
|
-
var ENTER_ALT_SCREEN = "\x1B[?1049h";
|
|
833
|
-
var LEAVE_ALT_SCREEN = "\x1B[?1049l";
|
|
834
|
-
var MAX_BUFFERED_LOGS = 1e3;
|
|
835
|
-
var DevTerminal = class {
|
|
836
|
-
constructor(server, cliVersion) {
|
|
837
|
-
this.server = server;
|
|
838
|
-
this.cliVersion = cliVersion;
|
|
839
|
-
this.session = server.config.plugins.find(
|
|
840
|
-
(plugin) => plugin.name === "makoo:dev"
|
|
841
|
-
)?.api?.session;
|
|
842
|
-
this.logger = server.config.logger;
|
|
843
|
-
this.originalInfo = this.logger.info;
|
|
844
|
-
this.originalWarn = this.logger.warn;
|
|
845
|
-
this.originalWarnOnce = this.logger.warnOnce;
|
|
846
|
-
this.originalError = this.logger.error;
|
|
847
|
-
this.originalClearScreen = this.logger.clearScreen;
|
|
848
|
-
this.logger.info = (message, options) => this.writeLog({ type: "info", message, options });
|
|
849
|
-
this.logger.warn = (message, options) => this.writeLog({ type: "warn", message, options });
|
|
850
|
-
this.logger.warnOnce = (message, options) => this.writeLog({ type: "warnOnce", message, options });
|
|
851
|
-
this.logger.error = (message, options) => this.writeLog({ type: "error", message, options });
|
|
852
|
-
this.logger.clearScreen = (type) => {
|
|
853
|
-
if (this.currentView === "logs") this.originalClearScreen.call(this.logger, type);
|
|
854
|
-
};
|
|
855
|
-
}
|
|
856
|
-
server;
|
|
857
|
-
cliVersion;
|
|
858
|
-
interactive = Boolean(
|
|
859
|
-
process.stdin.isTTY && process.stdout.isTTY && !process.env.CI
|
|
860
|
-
);
|
|
861
|
-
session;
|
|
862
|
-
unsubscribe;
|
|
863
|
-
currentView = "logs";
|
|
864
|
-
previousView = "home";
|
|
865
|
-
selectedRuntime = 0;
|
|
866
|
-
runtimeCount = -1;
|
|
867
|
-
ready = false;
|
|
868
|
-
restarting = false;
|
|
869
|
-
actionRunning = false;
|
|
870
|
-
closed = false;
|
|
871
|
-
stopInput;
|
|
872
|
-
bufferedLogs = [];
|
|
873
|
-
omittedLogs = 0;
|
|
874
|
-
unreadErrors = 0;
|
|
875
|
-
screenOutput = createLogUpdate(process.stdout, { showCursor: true });
|
|
876
|
-
logger;
|
|
877
|
-
originalInfo;
|
|
878
|
-
originalWarn;
|
|
879
|
-
originalWarnOnce;
|
|
880
|
-
originalError;
|
|
881
|
-
originalClearScreen;
|
|
882
|
-
async start() {
|
|
883
|
-
process.once("exit", this.close);
|
|
884
|
-
if (this.session) {
|
|
885
|
-
this.server.config.inlineConfig.customLogger = this.logger;
|
|
886
|
-
this.server.config.inlineConfig[bindDevSession] = this.attachSession;
|
|
887
|
-
this.attachSession(this.session);
|
|
888
|
-
process.once("SIGINT", this.shutdown);
|
|
889
|
-
}
|
|
890
|
-
try {
|
|
891
|
-
await this.server.listen();
|
|
892
|
-
this.ready = true;
|
|
893
|
-
if (!this.session) {
|
|
894
|
-
this.logger.info(this.renderBanner());
|
|
895
|
-
this.server.bindCLIShortcuts({ print: true });
|
|
896
|
-
return;
|
|
897
|
-
}
|
|
898
|
-
if (this.interactive) {
|
|
899
|
-
this.show("home");
|
|
900
|
-
this.bindShortcuts();
|
|
901
|
-
} else {
|
|
902
|
-
const runtimes = this.session.getRuntimeSnapshots();
|
|
903
|
-
this.runtimeCount = runtimes.length;
|
|
904
|
-
this.logger.info(this.renderHome(runtimes));
|
|
905
|
-
}
|
|
906
|
-
} catch (error) {
|
|
907
|
-
this.close();
|
|
908
|
-
await this.server.close();
|
|
909
|
-
throw error;
|
|
910
|
-
}
|
|
911
|
-
}
|
|
912
|
-
attachSession = (session) => {
|
|
913
|
-
this.unsubscribe?.();
|
|
914
|
-
this.session = session;
|
|
915
|
-
this.selectedRuntime = 0;
|
|
916
|
-
this.unsubscribe = session.subscribe(this.refresh);
|
|
917
|
-
this.refresh();
|
|
918
|
-
};
|
|
919
|
-
// Session events, navigation and new logs all redraw through this entry point.
|
|
920
|
-
refresh = () => {
|
|
921
|
-
if (!this.ready || this.closed || !this.session) return;
|
|
922
|
-
const runtimes = this.session.getRuntimeSnapshots();
|
|
923
|
-
this.selectedRuntime = runtimes.length === 0 ? 0 : this.selectedRuntime % runtimes.length;
|
|
924
|
-
if (!this.interactive) {
|
|
925
|
-
if (this.runtimeCount !== runtimes.length) {
|
|
926
|
-
this.runtimeCount = runtimes.length;
|
|
927
|
-
this.logger.info(` Runtime ${this.renderRuntimeStatus(runtimes.length)}`);
|
|
928
|
-
}
|
|
929
|
-
return;
|
|
930
|
-
}
|
|
931
|
-
switch (this.currentView) {
|
|
932
|
-
case "home":
|
|
933
|
-
this.draw(
|
|
934
|
-
this.renderHome(runtimes),
|
|
935
|
-
"Press a key to select an action. Press Ctrl+C to stop."
|
|
936
|
-
);
|
|
937
|
-
break;
|
|
938
|
-
case "injections":
|
|
939
|
-
this.draw(
|
|
940
|
-
this.renderInjections(runtimes),
|
|
941
|
-
"Press t or Esc to return home. Press Ctrl+C to stop."
|
|
942
|
-
);
|
|
943
|
-
break;
|
|
944
|
-
case "help":
|
|
945
|
-
this.draw(this.renderHelp(), "Press h or Esc to return. Press Ctrl+C to stop.");
|
|
946
|
-
break;
|
|
947
|
-
case "logs":
|
|
948
|
-
break;
|
|
949
|
-
}
|
|
950
|
-
};
|
|
951
|
-
show(view) {
|
|
952
|
-
if (this.closed || !this.interactive) return;
|
|
953
|
-
const previous = this.currentView;
|
|
954
|
-
this.currentView = view;
|
|
955
|
-
if (previous === "logs" && view !== "logs") process.stdout.write(ENTER_ALT_SCREEN);
|
|
956
|
-
if (previous !== "logs" && view === "logs") {
|
|
957
|
-
this.screenOutput.clear();
|
|
958
|
-
process.stdout.write(LEAVE_ALT_SCREEN);
|
|
959
|
-
this.flushLogs();
|
|
960
|
-
this.originalInfo.call(
|
|
961
|
-
this.logger,
|
|
962
|
-
colorize("Press l or Esc to return home. Press Ctrl+C to stop.", ansi.dim)
|
|
963
|
-
);
|
|
964
|
-
}
|
|
965
|
-
this.refresh();
|
|
966
|
-
}
|
|
967
|
-
renderBanner() {
|
|
968
|
-
const urls = this.server.resolvedUrls;
|
|
969
|
-
return [
|
|
970
|
-
`
|
|
971
|
-
${colorize("\u25C6", ansi.deepPink)} ${colorize(`Makoo v${this.cliVersion}`, ansi.bold, ansi.cyan)} ${colorize("dev", ansi.dim)}
|
|
972
|
-
`,
|
|
973
|
-
` ${colorize("Local", ansi.dim)} ${colorize(urls?.local[0] ?? "unavailable", ansi.cyan)}`,
|
|
974
|
-
` ${colorize("Network", ansi.dim)} ${urls?.network[0] ?? colorize("use --host to expose", ansi.dim)}`
|
|
975
|
-
].join("\n");
|
|
976
|
-
}
|
|
977
|
-
renderRuntimeStatus(count) {
|
|
978
|
-
if (this.restarting) return "Restarting\u2026";
|
|
979
|
-
if (count === 0) return "Waiting for a browser runtime";
|
|
980
|
-
return `${count} browser runtime${count === 1 ? "" : "s"} connected`;
|
|
981
|
-
}
|
|
982
|
-
renderHome(runtimes) {
|
|
983
|
-
const waiting = this.restarting || runtimes.length === 0;
|
|
984
|
-
const total = this.bufferedLogs.length + this.omittedLogs;
|
|
985
|
-
const logs = `${total} new${this.unreadErrors ? ` \xB7 ${this.unreadErrors} error${this.unreadErrors === 1 ? "" : "s"}` : ""}`;
|
|
986
|
-
return [
|
|
987
|
-
this.renderBanner(),
|
|
988
|
-
` ${colorize("Runtime", ansi.dim)} ${colorize(waiting ? "\u25CB" : "\u25CF", waiting ? ansi.yellow : ansi.green)} ${this.renderRuntimeStatus(runtimes.length)}`,
|
|
989
|
-
` ${colorize("Logs", ansi.dim)} ${colorize(logs, this.unreadErrors ? ansi.red : ansi.dim)}`,
|
|
990
|
-
`
|
|
991
|
-
${colorize("Actions", ansi.bold)}`,
|
|
992
|
-
...this.hasInstallationPage() ? [` ${colorize("i", ansi.bold, ansi.cyan)} Open installation page`] : [],
|
|
993
|
-
` ${colorize("t", ansi.bold, ansi.cyan)} View runtime injections`,
|
|
994
|
-
` ${colorize("l", ansi.bold, ansi.cyan)} View logs`,
|
|
995
|
-
` ${colorize("r", ansi.bold, ansi.cyan)} Restart server`,
|
|
996
|
-
` ${colorize("h", ansi.bold, ansi.cyan)} Show help`
|
|
997
|
-
].join("\n");
|
|
998
|
-
}
|
|
999
|
-
renderInjections(runtimes) {
|
|
1000
|
-
if (runtimes.length === 0) return "Makoo Injections\n\nWaiting for a browser runtime";
|
|
1001
|
-
const runtime = runtimes[this.selectedRuntime];
|
|
1002
|
-
return [
|
|
1003
|
-
`Runtime ${this.selectedRuntime + 1}/${runtimes.length} \xB7 Client ${runtime.clientId} \xB7 Makoo${runtime.runtimeId}`,
|
|
1004
|
-
renderInjectionsTable([runtime]),
|
|
1005
|
-
...runtimes.length > 1 ? ["Press n to view the next runtime."] : []
|
|
1006
|
-
].join("\n\n");
|
|
1007
|
-
}
|
|
1008
|
-
renderHelp() {
|
|
1009
|
-
return [
|
|
1010
|
-
colorize("Shortcuts", ansi.bold),
|
|
1011
|
-
"",
|
|
1012
|
-
...this.hasInstallationPage() ? [
|
|
1013
|
-
` ${colorize("i", ansi.bold, ansi.cyan)} open development script installation page`
|
|
1014
|
-
] : [],
|
|
1015
|
-
...[
|
|
1016
|
-
["t", "toggle runtime injections"],
|
|
1017
|
-
["n", "view next runtime injections"],
|
|
1018
|
-
["l", "view logs / return home"],
|
|
1019
|
-
["r", "restart the server"],
|
|
1020
|
-
["u", "show server URLs"],
|
|
1021
|
-
["o", "open in browser"],
|
|
1022
|
-
["c", "clear console"],
|
|
1023
|
-
["q", "quit"],
|
|
1024
|
-
["h", "show help"]
|
|
1025
|
-
].map(
|
|
1026
|
-
([key, description]) => ` ${colorize(key, ansi.bold, ansi.cyan)} ${description}`
|
|
1027
|
-
)
|
|
1028
|
-
].join("\n");
|
|
1029
|
-
}
|
|
1030
|
-
draw(content, hint) {
|
|
1031
|
-
const lines = [content, ""];
|
|
1032
|
-
const total = this.bufferedLogs.length + this.omittedLogs;
|
|
1033
|
-
if (total > 0 && this.currentView !== "home") {
|
|
1034
|
-
const status = `${total} new dev log${total === 1 ? "" : "s"}`;
|
|
1035
|
-
const errors = this.unreadErrors > 0 ? ` \xB7 ${this.unreadErrors} error${this.unreadErrors === 1 ? "" : "s"}` : "";
|
|
1036
|
-
lines.push(colorize(status + errors, this.unreadErrors ? ansi.red : ansi.dim));
|
|
1037
|
-
}
|
|
1038
|
-
lines.push(colorize(hint, ansi.dim));
|
|
1039
|
-
this.screenOutput(lines.join("\n"));
|
|
1040
|
-
}
|
|
1041
|
-
hasInstallationPage() {
|
|
1042
|
-
return this.server.config.plugins.some((plugin) => plugin.name === "monkey:virtualHtml");
|
|
1043
|
-
}
|
|
1044
|
-
bindShortcuts() {
|
|
1045
|
-
const wasRaw = process.stdin.isRaw;
|
|
1046
|
-
const wasFlowing = process.stdin.readableFlowing;
|
|
1047
|
-
emitKeypressEvents(process.stdin);
|
|
1048
|
-
process.stdin.setRawMode(true);
|
|
1049
|
-
process.stdin.on("keypress", this.onKey);
|
|
1050
|
-
process.stdin.resume();
|
|
1051
|
-
this.stopInput = () => {
|
|
1052
|
-
process.stdin.off("keypress", this.onKey);
|
|
1053
|
-
process.stdin.setRawMode(wasRaw);
|
|
1054
|
-
if (!wasFlowing) process.stdin.pause();
|
|
1055
|
-
};
|
|
1056
|
-
}
|
|
1057
|
-
onKey = async (_text, key) => {
|
|
1058
|
-
if (key.ctrl && key.name === "c") {
|
|
1059
|
-
await this.shutdown();
|
|
1060
|
-
return;
|
|
1061
|
-
}
|
|
1062
|
-
if (this.actionRunning || key.ctrl) return;
|
|
1063
|
-
if (key.name === "escape") {
|
|
1064
|
-
this.show(this.currentView === "help" ? this.previousView : "home");
|
|
1065
|
-
return;
|
|
1066
|
-
}
|
|
1067
|
-
if (key.meta || key.sequence?.length !== 1) return;
|
|
1068
|
-
if (key.name === "h") {
|
|
1069
|
-
if (this.currentView === "help") this.show(this.previousView);
|
|
1070
|
-
else {
|
|
1071
|
-
this.previousView = this.currentView;
|
|
1072
|
-
this.show("help");
|
|
1073
|
-
}
|
|
1074
|
-
return;
|
|
1075
|
-
}
|
|
1076
|
-
if (!["i", "t", "n", "l", "r", "u", "o", "c", "q"].includes(key.name ?? "")) return;
|
|
1077
|
-
if (key.name === "i" && !this.hasInstallationPage()) return;
|
|
1078
|
-
if (this.currentView === "help") this.show(this.previousView);
|
|
1079
|
-
this.actionRunning = true;
|
|
1080
|
-
try {
|
|
1081
|
-
switch (key.name) {
|
|
1082
|
-
case "t":
|
|
1083
|
-
this.show(this.currentView === "injections" ? "home" : "injections");
|
|
1084
|
-
break;
|
|
1085
|
-
case "n":
|
|
1086
|
-
this.selectedRuntime += 1;
|
|
1087
|
-
this.show("injections");
|
|
1088
|
-
break;
|
|
1089
|
-
case "l":
|
|
1090
|
-
this.show(this.currentView === "logs" ? "home" : "logs");
|
|
1091
|
-
break;
|
|
1092
|
-
case "r":
|
|
1093
|
-
await this.restart();
|
|
1094
|
-
break;
|
|
1095
|
-
case "u":
|
|
1096
|
-
this.show("home");
|
|
1097
|
-
break;
|
|
1098
|
-
case "o":
|
|
1099
|
-
this.server.openBrowser();
|
|
1100
|
-
break;
|
|
1101
|
-
case "i":
|
|
1102
|
-
this.openInstallationPage();
|
|
1103
|
-
break;
|
|
1104
|
-
case "c":
|
|
1105
|
-
this.show("logs");
|
|
1106
|
-
this.logger.clearScreen("error");
|
|
1107
|
-
break;
|
|
1108
|
-
case "q":
|
|
1109
|
-
await this.shutdown();
|
|
1110
|
-
break;
|
|
1111
|
-
}
|
|
1112
|
-
} catch (error) {
|
|
1113
|
-
this.logger.error(`[makoo] ${error instanceof Error ? error.message : String(error)}`);
|
|
1114
|
-
} finally {
|
|
1115
|
-
this.actionRunning = false;
|
|
1116
|
-
}
|
|
1117
|
-
};
|
|
1118
|
-
openInstallationPage() {
|
|
1119
|
-
const open = this.server.config.server.open;
|
|
1120
|
-
try {
|
|
1121
|
-
this.server.config.server.open = this.server.config.base;
|
|
1122
|
-
this.server.openBrowser();
|
|
1123
|
-
} finally {
|
|
1124
|
-
this.server.config.server.open = open;
|
|
1125
|
-
}
|
|
1126
|
-
}
|
|
1127
|
-
async restart() {
|
|
1128
|
-
this.restarting = true;
|
|
1129
|
-
this.show("home");
|
|
1130
|
-
try {
|
|
1131
|
-
await this.server.restart();
|
|
1132
|
-
} finally {
|
|
1133
|
-
this.restarting = false;
|
|
1134
|
-
this.refresh();
|
|
1135
|
-
}
|
|
1136
|
-
}
|
|
1137
|
-
shutdown = async () => {
|
|
1138
|
-
this.close();
|
|
1139
|
-
try {
|
|
1140
|
-
await this.server.close();
|
|
1141
|
-
} finally {
|
|
1142
|
-
process.exit(0);
|
|
1143
|
-
}
|
|
1144
|
-
};
|
|
1145
|
-
close = () => {
|
|
1146
|
-
if (this.closed) return;
|
|
1147
|
-
this.closed = true;
|
|
1148
|
-
this.unsubscribe?.();
|
|
1149
|
-
this.stopInput?.();
|
|
1150
|
-
process.off("exit", this.close);
|
|
1151
|
-
process.off("SIGINT", this.shutdown);
|
|
1152
|
-
if (this.currentView !== "logs") {
|
|
1153
|
-
this.screenOutput.clear();
|
|
1154
|
-
process.stdout.write(LEAVE_ALT_SCREEN);
|
|
1155
|
-
this.currentView = "logs";
|
|
1156
|
-
this.flushLogs();
|
|
1157
|
-
}
|
|
1158
|
-
this.logger.info = this.originalInfo;
|
|
1159
|
-
this.logger.warn = this.originalWarn;
|
|
1160
|
-
this.logger.warnOnce = this.originalWarnOnce;
|
|
1161
|
-
this.logger.error = this.originalError;
|
|
1162
|
-
this.logger.clearScreen = this.originalClearScreen;
|
|
1163
|
-
};
|
|
1164
|
-
writeLog(log) {
|
|
1165
|
-
if (this.currentView === "logs") {
|
|
1166
|
-
this.printLog(log);
|
|
1167
|
-
return;
|
|
1168
|
-
}
|
|
1169
|
-
if (log.type === "error") this.unreadErrors += 1;
|
|
1170
|
-
if (log.options) log.options = { ...log.options, clear: false };
|
|
1171
|
-
this.bufferedLogs.push(log);
|
|
1172
|
-
if (this.bufferedLogs.length > MAX_BUFFERED_LOGS) {
|
|
1173
|
-
this.bufferedLogs.shift();
|
|
1174
|
-
this.omittedLogs += 1;
|
|
1175
|
-
}
|
|
1176
|
-
this.refresh();
|
|
1177
|
-
}
|
|
1178
|
-
printLog(log) {
|
|
1179
|
-
switch (log.type) {
|
|
1180
|
-
case "info":
|
|
1181
|
-
this.originalInfo.call(this.logger, log.message, log.options);
|
|
1182
|
-
break;
|
|
1183
|
-
case "warn":
|
|
1184
|
-
this.originalWarn.call(this.logger, log.message, log.options);
|
|
1185
|
-
break;
|
|
1186
|
-
case "warnOnce":
|
|
1187
|
-
this.originalWarnOnce.call(this.logger, log.message, log.options);
|
|
1188
|
-
break;
|
|
1189
|
-
case "error":
|
|
1190
|
-
this.originalError.call(this.logger, log.message, log.options);
|
|
1191
|
-
break;
|
|
1192
|
-
}
|
|
1193
|
-
}
|
|
1194
|
-
flushLogs() {
|
|
1195
|
-
if (this.omittedLogs > 0)
|
|
1196
|
-
this.originalWarn.call(
|
|
1197
|
-
this.logger,
|
|
1198
|
-
`[makoo] ${this.omittedLogs} earlier dev logs omitted.`
|
|
1199
|
-
);
|
|
1200
|
-
for (const log of this.bufferedLogs) this.printLog(log);
|
|
1201
|
-
this.bufferedLogs = [];
|
|
1202
|
-
this.omittedLogs = 0;
|
|
1203
|
-
this.unreadErrors = 0;
|
|
1204
|
-
}
|
|
1205
|
-
};
|
|
1206
|
-
|
|
1207
|
-
// src/cli/commands/dev/dev.ts
|
|
1208
|
-
async function devCommand(config) {
|
|
1209
|
-
const server = await createServer(config);
|
|
1210
|
-
const cliVersion = await loadCliVersion(null);
|
|
1211
|
-
const terminal = new DevTerminal(server, cliVersion);
|
|
1212
|
-
await terminal.start();
|
|
1213
|
-
}
|
|
1214
|
-
|
|
1215
|
-
// src/cli/commands/preview.ts
|
|
1216
|
-
import { preview } from "vite";
|
|
1217
|
-
async function previewCommand(config) {
|
|
1218
|
-
const server = await preview(config);
|
|
1219
|
-
server.printUrls();
|
|
1220
|
-
server.bindCLIShortcuts({ print: true });
|
|
1221
|
-
}
|
|
1222
|
-
|
|
1223
|
-
// src/cli/bin.ts
|
|
672
|
+
// src/commands/bin.ts
|
|
1224
673
|
var cli = cac("makoo");
|
|
1225
674
|
function normalizeDuplicateOptions(options) {
|
|
1226
675
|
for (const [key, value] of Object.entries(options)) {
|
|
@@ -1289,9 +738,9 @@ cli.command("preview [root]", "Preview the built userscript").option("--host [ho
|
|
|
1289
738
|
}
|
|
1290
739
|
);
|
|
1291
740
|
cli.help();
|
|
1292
|
-
cli.version(await loadCliVersion(
|
|
741
|
+
cli.version(await loadCliVersion());
|
|
1293
742
|
process.on("unhandledRejection", (err) => {
|
|
1294
|
-
if (err
|
|
743
|
+
if (isMakooError(err)) {
|
|
1295
744
|
console.error(err);
|
|
1296
745
|
} else {
|
|
1297
746
|
console.error("[makoo]", err);
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { ComponentEachStatus, ComponentStatus, ListenerStatus } from '../../../../../core';
|
|
2
|
+
/** Transport endpoint handed to the page runtime; token travels in the ws query. */
|
|
3
|
+
export type DevEndpoint = {
|
|
4
|
+
host: string;
|
|
5
|
+
port: number;
|
|
6
|
+
token: string;
|
|
7
|
+
};
|
|
8
|
+
/** One node of a serialized error tree: an error, a cause link, or an aggregate child. */
|
|
9
|
+
export type SerializedErrorNode = {
|
|
10
|
+
code?: string;
|
|
11
|
+
category?: string;
|
|
12
|
+
message: string;
|
|
13
|
+
name?: string;
|
|
14
|
+
details?: unknown;
|
|
15
|
+
cause?: SerializedErrorNode;
|
|
16
|
+
errors?: SerializedErrorNode[];
|
|
17
|
+
};
|
|
18
|
+
export type SerializedMakooError = SerializedErrorNode & {
|
|
19
|
+
code: string;
|
|
20
|
+
};
|
|
21
|
+
export type AttachedListenerSnapshot = {
|
|
22
|
+
name: string;
|
|
23
|
+
status: ListenerStatus;
|
|
24
|
+
};
|
|
25
|
+
/** One anonymous Child Injection under an Each Injection, in document order. */
|
|
26
|
+
export type ChildSnapshot = {
|
|
27
|
+
status: ComponentStatus;
|
|
28
|
+
lastError?: SerializedMakooError;
|
|
29
|
+
};
|
|
30
|
+
export type InjectionSnapshot = {
|
|
31
|
+
name: string;
|
|
32
|
+
kind: 'component';
|
|
33
|
+
status: ComponentStatus;
|
|
34
|
+
lastError?: SerializedMakooError;
|
|
35
|
+
attachedListeners: AttachedListenerSnapshot[];
|
|
36
|
+
} | {
|
|
37
|
+
name: string;
|
|
38
|
+
kind: 'component-each';
|
|
39
|
+
status: ComponentEachStatus;
|
|
40
|
+
lastError?: SerializedMakooError;
|
|
41
|
+
children: ChildSnapshot[];
|
|
42
|
+
} | {
|
|
43
|
+
name: string;
|
|
44
|
+
kind: 'standalone-listener';
|
|
45
|
+
status: ListenerStatus;
|
|
46
|
+
lastError?: SerializedMakooError;
|
|
47
|
+
};
|
|
48
|
+
export type SerializedDiagnostic = {
|
|
49
|
+
type: 'diagnostic';
|
|
50
|
+
name?: string;
|
|
51
|
+
error: SerializedMakooError;
|
|
52
|
+
};
|
|
53
|
+
/** One Core instance's complete row inside a page submission. */
|
|
54
|
+
export type PageRuntimeRow = {
|
|
55
|
+
runtimeId: number;
|
|
56
|
+
injections: InjectionSnapshot[];
|
|
57
|
+
diagnostics: SerializedDiagnostic[];
|
|
58
|
+
};
|
|
59
|
+
export declare const SUBMIT_PAGE_RPC = "makoo:submit-page";
|
|
60
|
+
declare module 'devframe' {
|
|
61
|
+
interface DevframeRpcServerFunctions {
|
|
62
|
+
'makoo:submit-page': (rows: PageRuntimeRow[]) => Promise<void>;
|
|
63
|
+
}
|
|
64
|
+
}
|