@newly/cli 0.1.105 → 0.1.106
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.runcloud.md +6 -0
- package/dist/commands/run-cloud.js +74 -0
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/README.runcloud.md
CHANGED
|
@@ -64,6 +64,8 @@ runcloud ios create --model iphone --install ./MyApp.app # boot a simulator an
|
|
|
64
64
|
runcloud ios list # list active sessions
|
|
65
65
|
runcloud ios get <id> # inspect a session (viewer URL, status)
|
|
66
66
|
runcloud ios open-url myapp://path --id <id> # open a URL or deep link
|
|
67
|
+
runcloud ios logs <id> --tail 200 # read logs from this lease
|
|
68
|
+
runcloud ios logs <id> --follow # follow new log entries
|
|
67
69
|
runcloud ios delete <id> # release the session
|
|
68
70
|
|
|
69
71
|
# Android works the same under `runcloud android …`
|
|
@@ -74,6 +76,10 @@ Useful `create` flags: `--region`, `--display-name`, `--inactivity-timeout 3m`,
|
|
|
74
76
|
`--hard-timeout 1h`, `--install-asset <name-or-id>`, `--rm` (release when the
|
|
75
77
|
command exits), `--json`.
|
|
76
78
|
|
|
79
|
+
The same `logs` commands work for Android. Snapshots are limited to the active
|
|
80
|
+
lease and accept 1 to 1,000 lines. In follow mode, `--json` emits one JSON object
|
|
81
|
+
per line.
|
|
82
|
+
|
|
77
83
|
### Tunnel a local dev server into a simulator
|
|
78
84
|
|
|
79
85
|
```bash
|
|
@@ -65,6 +65,40 @@ function formatRecord(value) {
|
|
|
65
65
|
.map(([k, v]) => `${k}: ${typeof v === 'object' ? JSON.stringify(v) : String(v)}`)
|
|
66
66
|
.join('\n');
|
|
67
67
|
}
|
|
68
|
+
export function consumeSimulatorLogSse(raw) {
|
|
69
|
+
const entries = [];
|
|
70
|
+
let offset = 0;
|
|
71
|
+
let separator = /\r?\n\r?\n/.exec(raw.slice(offset));
|
|
72
|
+
while (separator) {
|
|
73
|
+
const frameEnd = offset + separator.index;
|
|
74
|
+
const frame = raw.slice(offset, frameEnd);
|
|
75
|
+
offset = frameEnd + separator[0].length;
|
|
76
|
+
const data = frame
|
|
77
|
+
.split(/\r?\n/)
|
|
78
|
+
.filter((line) => line.startsWith('data:'))
|
|
79
|
+
.map((line) => line.slice('data:'.length).trimStart())
|
|
80
|
+
.join('\n');
|
|
81
|
+
if (data) {
|
|
82
|
+
let value;
|
|
83
|
+
try {
|
|
84
|
+
value = JSON.parse(data);
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
throw new Error('Simulator log stream returned invalid JSON');
|
|
88
|
+
}
|
|
89
|
+
const entry = value;
|
|
90
|
+
if (!entry || typeof entry.timestamp !== 'string' || typeof entry.message !== 'string') {
|
|
91
|
+
throw new Error('Simulator log stream returned an invalid entry');
|
|
92
|
+
}
|
|
93
|
+
entries.push({ timestamp: entry.timestamp, message: entry.message });
|
|
94
|
+
}
|
|
95
|
+
separator = /\r?\n\r?\n/.exec(raw.slice(offset));
|
|
96
|
+
}
|
|
97
|
+
return { entries, remainder: raw.slice(offset) };
|
|
98
|
+
}
|
|
99
|
+
function writeSimulatorLogEntry(entry, json) {
|
|
100
|
+
console.log(json ? JSON.stringify(entry) : entry.message);
|
|
101
|
+
}
|
|
68
102
|
function parseLabels(labels) {
|
|
69
103
|
const out = {};
|
|
70
104
|
for (const raw of labels ?? []) {
|
|
@@ -338,6 +372,46 @@ function registerSimulatorCommands(program, platform) {
|
|
|
338
372
|
.action((url, opts) => action(async () => {
|
|
339
373
|
print(await client().post(`/run-cloud/${platform}/${encodeURIComponent(opts.id)}/open-url`, { url }), opts);
|
|
340
374
|
}));
|
|
375
|
+
simulator
|
|
376
|
+
.command('logs')
|
|
377
|
+
.description(`Read or follow logs from ${article} active ${label} session`)
|
|
378
|
+
.argument('<id>')
|
|
379
|
+
.option('--tail <lines>', 'number of retained lines to return (1-1000)')
|
|
380
|
+
.option('-f, --follow', 'follow new log entries', false)
|
|
381
|
+
.option('--json', 'output JSON; follow mode emits one object per line', false)
|
|
382
|
+
.action((id, opts) => action(async () => {
|
|
383
|
+
if (opts.follow && opts.tail !== undefined) {
|
|
384
|
+
throw new Error('--tail cannot be combined with --follow');
|
|
385
|
+
}
|
|
386
|
+
const path = `/run-cloud/${platform}/${encodeURIComponent(id)}/logs`;
|
|
387
|
+
if (!opts.follow) {
|
|
388
|
+
const tail = opts.tail === undefined ? 200 : Number(opts.tail);
|
|
389
|
+
if (!Number.isInteger(tail) || tail < 1 || tail > 1_000) {
|
|
390
|
+
throw new Error('--tail must be an integer from 1 to 1000');
|
|
391
|
+
}
|
|
392
|
+
const snapshot = await client().get(`${path}?tail=${tail}`);
|
|
393
|
+
if (opts.json) {
|
|
394
|
+
print(snapshot, opts);
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
const entries = Array.isArray(snapshot.entries) ? snapshot.entries : [];
|
|
398
|
+
for (const entry of entries)
|
|
399
|
+
writeSimulatorLogEntry(entry, false);
|
|
400
|
+
if (entries.length === 0)
|
|
401
|
+
console.error('No simulator logs captured for this lease.');
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
let pending = '';
|
|
405
|
+
for await (const chunk of client().stream(`${path}?follow=1`)) {
|
|
406
|
+
const parsed = consumeSimulatorLogSse(`${pending}${chunk}`);
|
|
407
|
+
pending = parsed.remainder;
|
|
408
|
+
if (pending.length > 1024 * 1024) {
|
|
409
|
+
throw new Error('Simulator log stream returned an oversized incomplete event');
|
|
410
|
+
}
|
|
411
|
+
for (const entry of parsed.entries)
|
|
412
|
+
writeSimulatorLogEntry(entry, opts.json === true);
|
|
413
|
+
}
|
|
414
|
+
}));
|
|
341
415
|
return simulator;
|
|
342
416
|
}
|
|
343
417
|
async function action(fn) {
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const CLI_VERSION = '0.1.
|
|
1
|
+
export const CLI_VERSION = '0.1.106';
|