@glassly/cli 2.0.11 → 2.0.12-beta.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 +17 -0
- package/package.json +2 -2
- package/src/index.ts +269 -0
package/README.md
CHANGED
|
@@ -27,6 +27,23 @@ Or run without installing:
|
|
|
27
27
|
bunx @glassly/cli --help
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
+
## Run without hardware
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
glassly sim # desktop simulator: glasses display, input controls, phone page
|
|
34
|
+
glassly sim --detach # start it in the background and return once ready
|
|
35
|
+
glassly sim screen # what is on the glasses, one element per line
|
|
36
|
+
glassly sim screenshot a.png # the display as a PNG
|
|
37
|
+
glassly sim tap # also double-tap, hold, swipe-up, swipe-down, look-up, button
|
|
38
|
+
glassly sim say "hello" # speech, delivered as a transcription
|
|
39
|
+
glassly sim logs # console output from both layers
|
|
40
|
+
glassly sim stop
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The subcommands talk to the simulator running for the current project, so a
|
|
44
|
+
script or a coding agent can drive a miniapp end to end. `glassly sim --help`
|
|
45
|
+
lists all of them.
|
|
46
|
+
|
|
30
47
|
## Develop and test on a phone
|
|
31
48
|
|
|
32
49
|
```bash
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glassly/cli",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.12-beta.0",
|
|
4
4
|
"description": "The glassly command: develop, pack, release, and publish Glassly miniapps. Bun-only.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"typecheck": "tsc --noEmit"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@glassly/miniapp-cli": "0.1.
|
|
25
|
+
"@glassly/miniapp-cli": "0.1.11-beta.0",
|
|
26
26
|
"commander": "^15.1.0",
|
|
27
27
|
"qrcode": "^1.5.4"
|
|
28
28
|
},
|
package/src/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
addPermissionCmd,
|
|
7
7
|
buildProduction as buildMiniappProduction,
|
|
8
8
|
dev as devMiniapp,
|
|
9
|
+
findSim,
|
|
9
10
|
listHardwareCmd,
|
|
10
11
|
listPermissionsCmd,
|
|
11
12
|
pack as packMiniapp,
|
|
@@ -15,7 +16,16 @@ import {
|
|
|
15
16
|
removePermissionCmd,
|
|
16
17
|
runManifestWizard,
|
|
17
18
|
schemaPrint,
|
|
19
|
+
sim as simMiniapp,
|
|
20
|
+
simDetached,
|
|
21
|
+
simGet,
|
|
22
|
+
simLogs,
|
|
23
|
+
simPost,
|
|
24
|
+
simScreenshot,
|
|
25
|
+
simText,
|
|
18
26
|
type QRSize,
|
|
27
|
+
type SimLogLine,
|
|
28
|
+
type SimTarget,
|
|
19
29
|
} from "@glassly/miniapp-cli";
|
|
20
30
|
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
21
31
|
import { basename, extname, join, resolve } from "node:path";
|
|
@@ -667,6 +677,265 @@ program
|
|
|
667
677
|
}
|
|
668
678
|
});
|
|
669
679
|
|
|
680
|
+
const simulator = program
|
|
681
|
+
.command("sim")
|
|
682
|
+
.description("Run the miniapp in the desktop simulator: glasses display, input, and phone page, no hardware needed")
|
|
683
|
+
.option("--cwd <path>", "miniapp project directory", process.cwd())
|
|
684
|
+
.option("--port <port>", "simulator port (to start on, or of the running simulator to control)")
|
|
685
|
+
.option("--device <id>", "glasses to simulate", "simulated")
|
|
686
|
+
.option("--no-open", "do not open the simulator window in a browser")
|
|
687
|
+
.option("--detach", "start it in the background and return once it is ready (for scripts and coding agents)")
|
|
688
|
+
.action(async (options: { cwd: string; port?: string; device: string; open: boolean; detach?: boolean }) => {
|
|
689
|
+
try {
|
|
690
|
+
if (options.detach) {
|
|
691
|
+
const command = [process.execPath, process.argv[1], "sim", "--no-open", "--cwd", resolve(options.cwd), "--device", options.device];
|
|
692
|
+
if (options.port) command.push("--port", options.port);
|
|
693
|
+
const started = await simDetached({ cwd: resolve(options.cwd), command });
|
|
694
|
+
console.log(`${started.alreadyRunning ? "Simulator already running" : "Simulator running"} at ${started.url} (pid ${started.pid})`);
|
|
695
|
+
console.log(`Output: ${started.logPath}`);
|
|
696
|
+
console.log("Stop it with `glassly sim stop`.");
|
|
697
|
+
process.exit(0);
|
|
698
|
+
}
|
|
699
|
+
await simMiniapp({
|
|
700
|
+
cwd: resolve(options.cwd),
|
|
701
|
+
port: options.port ? Number(options.port) : undefined,
|
|
702
|
+
device: options.device,
|
|
703
|
+
open: options.open,
|
|
704
|
+
openBrowser,
|
|
705
|
+
});
|
|
706
|
+
} catch (error) {
|
|
707
|
+
fail(error);
|
|
708
|
+
}
|
|
709
|
+
});
|
|
710
|
+
|
|
711
|
+
function simTarget(command: Command): SimTarget {
|
|
712
|
+
const options = command.optsWithGlobals() as { cwd?: string; port?: string };
|
|
713
|
+
return { cwd: options.cwd ? resolve(options.cwd) : undefined, port: options.port ? Number(options.port) : undefined };
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
function simCommand<Args extends unknown[]>(run: (target: SimTarget, ...args: Args) => Promise<void>) {
|
|
717
|
+
return async (...args: unknown[]) => {
|
|
718
|
+
const command = args[args.length - 1] as Command;
|
|
719
|
+
try {
|
|
720
|
+
await run(simTarget(command), ...(args.slice(0, -1) as Args));
|
|
721
|
+
} catch (error) {
|
|
722
|
+
fail(error);
|
|
723
|
+
}
|
|
724
|
+
};
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
function jsonArgument(raw: string | undefined, name: string): unknown {
|
|
728
|
+
if (raw === undefined) return undefined;
|
|
729
|
+
try {
|
|
730
|
+
return JSON.parse(raw);
|
|
731
|
+
} catch {
|
|
732
|
+
throw new Error(`${name} must be JSON, e.g. '{"at": 1}' (got ${raw})`);
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
function formatSimLog(entry: SimLogLine): string {
|
|
737
|
+
const time = new Date(entry.timestamp).toTimeString().slice(0, 8);
|
|
738
|
+
return `${time} ${entry.source.padEnd(10)} ${entry.level.padEnd(5)} ${entry.message}`;
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
simulator
|
|
742
|
+
.command("status")
|
|
743
|
+
.description("Show the running simulator: miniapp state, subscriptions, sensors")
|
|
744
|
+
.option("--json", "print the full status as JSON")
|
|
745
|
+
.action(simCommand(async (target, options: { json?: boolean }) => {
|
|
746
|
+
const status = await simGet<Record<string, any>>(target, "status");
|
|
747
|
+
if (options.json) {
|
|
748
|
+
console.log(JSON.stringify(status, null, 2));
|
|
749
|
+
return;
|
|
750
|
+
}
|
|
751
|
+
console.log(`${status.name} (${status.packageName}) at ${findSim(target)}`);
|
|
752
|
+
console.log(`background: ${status.background}${status.connected ? ", connected" : ""}${status.paused ? ", paused" : ""}`);
|
|
753
|
+
console.log(`display: ${status.display.elements} elements, view ${status.display.view}, ${status.display.frames} frames rendered`);
|
|
754
|
+
console.log(`subscriptions: ${status.subscriptions.join(", ") || "none"}`);
|
|
755
|
+
console.log(`phone page: ${status.ui.open ? "open" : "closed"}`);
|
|
756
|
+
if (status.unsimulated.length) console.log(`not simulated: ${status.unsimulated.join(", ")}`);
|
|
757
|
+
}));
|
|
758
|
+
|
|
759
|
+
simulator
|
|
760
|
+
.command("screen")
|
|
761
|
+
.description("Print what is on the glasses display, one element per line")
|
|
762
|
+
.option("--json", "print the display snapshot as JSON")
|
|
763
|
+
.action(simCommand(async (target, options: { json?: boolean }) => {
|
|
764
|
+
process.stdout.write(await simText(target, options.json ? "screen?format=json" : "screen"));
|
|
765
|
+
if (options.json) process.stdout.write("\n");
|
|
766
|
+
}));
|
|
767
|
+
|
|
768
|
+
simulator
|
|
769
|
+
.command("screenshot [path]")
|
|
770
|
+
.description("Save the glasses display as a PNG (default ./glassly-sim.png)")
|
|
771
|
+
.option("--scale <n>", "pixels per display pixel, 1-4", "2")
|
|
772
|
+
.option("--no-wait", "capture now instead of after running transitions finish")
|
|
773
|
+
.action(simCommand(async (target, path: string | undefined, options: { scale: string; wait: boolean }) => {
|
|
774
|
+
console.log(await simScreenshot(target, path ?? "glassly-sim.png", { scale: Number(options.scale), wait: options.wait }));
|
|
775
|
+
}));
|
|
776
|
+
|
|
777
|
+
const SIM_GESTURES: Record<string, [string, string]> = {
|
|
778
|
+
tap: ["single_tap", "Tap the touch bar"],
|
|
779
|
+
"double-tap": ["double_tap", "Double tap the touch bar"],
|
|
780
|
+
"triple-tap": ["triple_tap", "Triple tap the touch bar"],
|
|
781
|
+
hold: ["long_press", "Press and hold the touch bar"],
|
|
782
|
+
"swipe-up": ["swipe_up", "Swipe up on the touch bar"],
|
|
783
|
+
"swipe-down": ["swipe_down", "Swipe down on the touch bar"],
|
|
784
|
+
"look-up": ["head_up", "Raise the head past the head-up angle"],
|
|
785
|
+
"look-down": ["head_down", "Lower the head again"],
|
|
786
|
+
};
|
|
787
|
+
|
|
788
|
+
for (const [name, [gesture, description]] of Object.entries(SIM_GESTURES)) {
|
|
789
|
+
simulator
|
|
790
|
+
.command(name)
|
|
791
|
+
.description(description)
|
|
792
|
+
.action(simCommand(async (target) => {
|
|
793
|
+
await simPost(target, "touch", { gesture });
|
|
794
|
+
}));
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
simulator
|
|
798
|
+
.command("touch <gesture>")
|
|
799
|
+
.description("Send any touch gesture by its wire name (single_tap, swipe_left, dial_up, ...)")
|
|
800
|
+
.action(simCommand(async (target, gesture: string) => {
|
|
801
|
+
await simPost(target, "touch", { gesture });
|
|
802
|
+
}));
|
|
803
|
+
|
|
804
|
+
simulator
|
|
805
|
+
.command("button [press]")
|
|
806
|
+
.description("Press the glasses button: short (default) or long")
|
|
807
|
+
.action(simCommand(async (target, press: string | undefined) => {
|
|
808
|
+
await simPost(target, "button", { pressType: press === "long" ? "long" : "short" });
|
|
809
|
+
}));
|
|
810
|
+
|
|
811
|
+
simulator
|
|
812
|
+
.command("say <text...>")
|
|
813
|
+
.description("Speech the glasses hear, delivered as a transcription")
|
|
814
|
+
.option("--interim", "send as a not-yet-final result")
|
|
815
|
+
.option("--language <code>", "spoken language", "en-US")
|
|
816
|
+
.action(simCommand(async (target, text: string[], options: { interim?: boolean; language: string }) => {
|
|
817
|
+
await simPost(target, "say", { text: text.join(" "), isFinal: !options.interim, language: options.language });
|
|
818
|
+
}));
|
|
819
|
+
|
|
820
|
+
simulator
|
|
821
|
+
.command("translate <text...>")
|
|
822
|
+
.description("A translation result for miniapps that subscribe to translations")
|
|
823
|
+
.option("--from <code>", "source language", "en-US")
|
|
824
|
+
.option("--to <code>", "target language", "es-ES")
|
|
825
|
+
.option("--interim", "send as a not-yet-final result")
|
|
826
|
+
.action(simCommand(async (target, text: string[], options: { from: string; to: string; interim?: boolean }) => {
|
|
827
|
+
await simPost(target, "translate", { text: text.join(" "), source: options.from, target: options.to, isFinal: !options.interim });
|
|
828
|
+
}));
|
|
829
|
+
|
|
830
|
+
simulator
|
|
831
|
+
.command("location <lat> <lng>")
|
|
832
|
+
.description("Move the phone to a coordinate")
|
|
833
|
+
.action(simCommand(async (target, lat: string, lng: string) => {
|
|
834
|
+
await simPost(target, "location", { lat: Number(lat), lng: Number(lng) });
|
|
835
|
+
}));
|
|
836
|
+
|
|
837
|
+
simulator
|
|
838
|
+
.command("heading <degrees>")
|
|
839
|
+
.description("Turn the phone compass (0 = north, 90 = east)")
|
|
840
|
+
.action(simCommand(async (target, degrees: string) => {
|
|
841
|
+
await simPost(target, "heading", { degrees: Number(degrees) });
|
|
842
|
+
}));
|
|
843
|
+
|
|
844
|
+
simulator
|
|
845
|
+
.command("battery <level>")
|
|
846
|
+
.description("Set the glasses battery percentage")
|
|
847
|
+
.option("--phone", "set the phone battery instead")
|
|
848
|
+
.option("--charging", "report it as charging")
|
|
849
|
+
.action(simCommand(async (target, level: string, options: { phone?: boolean; charging?: boolean }) => {
|
|
850
|
+
await simPost(target, "battery", { target: options.phone ? "phone" : "glasses", level: Number(level), charging: options.charging === true });
|
|
851
|
+
}));
|
|
852
|
+
|
|
853
|
+
simulator
|
|
854
|
+
.command("disconnect")
|
|
855
|
+
.description("Disconnect the glasses (the host pauses the miniapp)")
|
|
856
|
+
.action(simCommand(async (target) => {
|
|
857
|
+
await simPost(target, "connection", { connected: false });
|
|
858
|
+
}));
|
|
859
|
+
|
|
860
|
+
simulator
|
|
861
|
+
.command("connect")
|
|
862
|
+
.description("Reconnect the glasses")
|
|
863
|
+
.action(simCommand(async (target) => {
|
|
864
|
+
await simPost(target, "connection", { connected: true });
|
|
865
|
+
}));
|
|
866
|
+
|
|
867
|
+
simulator
|
|
868
|
+
.command("notify")
|
|
869
|
+
.description("Deliver a phone notification")
|
|
870
|
+
.option("--title <text>", "notification title", "")
|
|
871
|
+
.option("--content <text>", "notification body", "")
|
|
872
|
+
.option("--app <name>", "app that posted it", "Messages")
|
|
873
|
+
.action(simCommand(async (target, options: { title: string; content: string; app: string }) => {
|
|
874
|
+
await simPost(target, "notify", options);
|
|
875
|
+
}));
|
|
876
|
+
|
|
877
|
+
simulator
|
|
878
|
+
.command("event <stream> [json]")
|
|
879
|
+
.description("Deliver an event on any stream by its wire name, with a JSON payload")
|
|
880
|
+
.action(simCommand(async (target, stream: string, raw: string | undefined) => {
|
|
881
|
+
await simPost(target, "event", { stream, data: jsonArgument(raw, "The event payload") ?? {} });
|
|
882
|
+
}));
|
|
883
|
+
|
|
884
|
+
const simulatorUi = simulator.command("ui").description("Act as the miniapp's phone page");
|
|
885
|
+
|
|
886
|
+
simulatorUi
|
|
887
|
+
.command("send <channel> [json]")
|
|
888
|
+
.description("Broadcast on a channel, as the page does with glassly.send")
|
|
889
|
+
.action(simCommand(async (target, channel: string, raw: string | undefined) => {
|
|
890
|
+
await simPost(target, "ui/send", { channel, payload: jsonArgument(raw, "The channel payload") });
|
|
891
|
+
}));
|
|
892
|
+
|
|
893
|
+
simulatorUi
|
|
894
|
+
.command("request <channel> [json]")
|
|
895
|
+
.description("Call an RPC channel, as the page does with glassly.request, and print the result")
|
|
896
|
+
.option("--timeout <ms>", "give up after this long", "10000")
|
|
897
|
+
.action(simCommand(async (target, channel: string, raw: string | undefined, options: { timeout: string }) => {
|
|
898
|
+
const { result } = await simPost<{ result: unknown }>(target, "ui/request", {
|
|
899
|
+
channel,
|
|
900
|
+
payload: jsonArgument(raw, "The request payload"),
|
|
901
|
+
timeoutMs: Number(options.timeout),
|
|
902
|
+
});
|
|
903
|
+
console.log(JSON.stringify(result, null, 2));
|
|
904
|
+
}));
|
|
905
|
+
|
|
906
|
+
simulator
|
|
907
|
+
.command("logs")
|
|
908
|
+
.description("Print the miniapp's console output and the simulator's own notes")
|
|
909
|
+
.option("--since <seq>", "only entries after this sequence number", "0")
|
|
910
|
+
.option("-f, --follow", "keep printing new entries")
|
|
911
|
+
.option("--source <list>", "background,ui,host,bridge (bridge = channel traffic; off by default)")
|
|
912
|
+
.option("--json", "print entries as JSON lines with their sequence numbers")
|
|
913
|
+
.action(simCommand(async (target, options: { since: string; follow?: boolean; source?: string; json?: boolean }) => {
|
|
914
|
+
let since = Number(options.since) || 0;
|
|
915
|
+
const sources = options.source?.split(",").map((source) => source.trim()).filter(Boolean);
|
|
916
|
+
for (;;) {
|
|
917
|
+
const { entries, seq } = await simLogs(target, { since, sources });
|
|
918
|
+
for (const entry of entries) console.log(options.json ? JSON.stringify(entry) : formatSimLog(entry));
|
|
919
|
+
since = seq;
|
|
920
|
+
if (!options.follow) return;
|
|
921
|
+
await new Promise((done) => setTimeout(done, 400));
|
|
922
|
+
}
|
|
923
|
+
}));
|
|
924
|
+
|
|
925
|
+
simulator
|
|
926
|
+
.command("restart")
|
|
927
|
+
.description("Restart the miniapp's background script")
|
|
928
|
+
.action(simCommand(async (target) => {
|
|
929
|
+
await simPost(target, "restart");
|
|
930
|
+
}));
|
|
931
|
+
|
|
932
|
+
simulator
|
|
933
|
+
.command("stop")
|
|
934
|
+
.description("Stop the running simulator")
|
|
935
|
+
.action(simCommand(async (target) => {
|
|
936
|
+
await simPost(target, "stop");
|
|
937
|
+
}));
|
|
938
|
+
|
|
670
939
|
program
|
|
671
940
|
.command("build")
|
|
672
941
|
.description("Build the current miniapp")
|