@newly/cli 0.1.105 → 0.1.107
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/commands/sandbox.js +55 -5
- 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/commands/sandbox.js
CHANGED
|
@@ -263,6 +263,33 @@ function secretSelector(opts) {
|
|
|
263
263
|
function collectRepeatable(value, previous) {
|
|
264
264
|
return [...previous, value];
|
|
265
265
|
}
|
|
266
|
+
export function parseTagPairs(values) {
|
|
267
|
+
return values.map((raw) => {
|
|
268
|
+
const at = raw.indexOf('=');
|
|
269
|
+
if (at <= 0) {
|
|
270
|
+
throw new Error(`--tag must be key=value (got ${JSON.stringify(raw)})`);
|
|
271
|
+
}
|
|
272
|
+
return [raw.slice(0, at), raw.slice(at + 1)];
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
export async function resolveSandboxByTag(api, tags) {
|
|
276
|
+
if (tags.length === 0) {
|
|
277
|
+
throw new Error('Provide a sandbox id, or --tag key=value to find one.');
|
|
278
|
+
}
|
|
279
|
+
const query = new URLSearchParams();
|
|
280
|
+
for (const [key, value] of parseTagPairs(tags))
|
|
281
|
+
query.append('tag', `${key}:${value}`);
|
|
282
|
+
const data = await api.get(`/run-cloud/sandboxes?${query}`);
|
|
283
|
+
const items = data?.items ?? [];
|
|
284
|
+
if (items.length === 0) {
|
|
285
|
+
throw new Error(`No sandbox matches ${tags.join(' ')}.`);
|
|
286
|
+
}
|
|
287
|
+
if (items.length > 1) {
|
|
288
|
+
const listed = items.map((s) => ` ${s.id}${s.name ? ` ${s.name}` : ''}`).join('\n');
|
|
289
|
+
throw new Error(`${items.length} sandboxes match ${tags.join(' ')} — narrow it, or pass an id:\n${listed}`);
|
|
290
|
+
}
|
|
291
|
+
return items[0].id;
|
|
292
|
+
}
|
|
266
293
|
export function registerSandbox(program) {
|
|
267
294
|
const sandbox = program.command('sandbox').description('Spawn and control microVM sandboxes');
|
|
268
295
|
const defaultHelp = new Help();
|
|
@@ -362,12 +389,16 @@ export function registerSandbox(program) {
|
|
|
362
389
|
.command('list')
|
|
363
390
|
.description('List sandboxes')
|
|
364
391
|
.option('--state <state>', 'filter by state')
|
|
365
|
-
.option('--name <name>', 'filter by name (exact)')
|
|
392
|
+
.option('--name <name>', 'filter by name (exact)')
|
|
393
|
+
.option('--tag <key=value>', 'filter by tag; repeatable, and a sandbox must carry every one', collectRepeatable, [])).action((opts) => run(async () => {
|
|
366
394
|
const query = new URLSearchParams();
|
|
367
395
|
if (opts.state)
|
|
368
396
|
query.set('state', opts.state);
|
|
369
397
|
if (opts.name)
|
|
370
398
|
query.set('name', opts.name);
|
|
399
|
+
for (const [key, value] of parseTagPairs(opts.tag ?? [])) {
|
|
400
|
+
query.append('tag', `${key}:${value}`);
|
|
401
|
+
}
|
|
371
402
|
const qs = query.size ? `?${query}` : '';
|
|
372
403
|
const api = runCloudApi();
|
|
373
404
|
const [data, boxes] = await Promise.all([
|
|
@@ -384,6 +415,23 @@ export function registerSandbox(program) {
|
|
|
384
415
|
else
|
|
385
416
|
console.log(renderSandboxList(items));
|
|
386
417
|
}));
|
|
418
|
+
withOutput(sandbox
|
|
419
|
+
.command('tag')
|
|
420
|
+
.description('Set or remove tags on a sandbox')
|
|
421
|
+
.argument('<id>', 'sandbox id')
|
|
422
|
+
.argument('<pairs...>', 'key=value to set, or key= to remove')).action((id, pairs, opts) => run(async () => {
|
|
423
|
+
const tags = Object.fromEntries(parseTagPairs(pairs).map(([key, value]) => [key, value === '' ? null : value]));
|
|
424
|
+
const updated = await runCloudApi().patch(`/run-cloud/sandboxes/${encodeURIComponent(id)}/tags`, { tags });
|
|
425
|
+
if (opts.json)
|
|
426
|
+
printJson(updated);
|
|
427
|
+
else {
|
|
428
|
+
const applied = (updated?.tags ?? {});
|
|
429
|
+
const entries = Object.entries(applied);
|
|
430
|
+
console.log(entries.length === 0
|
|
431
|
+
? `${id} now has no tags`
|
|
432
|
+
: `${id}\n${entries.map(([k, v]) => ` ${k}=${v}`).join('\n')}`);
|
|
433
|
+
}
|
|
434
|
+
}));
|
|
387
435
|
withOutput(sandbox
|
|
388
436
|
.command('get')
|
|
389
437
|
.description('Inspect a sandbox, including its public hostname when exposed')
|
|
@@ -497,15 +545,17 @@ export function registerSandbox(program) {
|
|
|
497
545
|
sandbox
|
|
498
546
|
.command('shell')
|
|
499
547
|
.description('Open an interactive shell (resumes paused sandboxes)')
|
|
500
|
-
.argument('
|
|
501
|
-
.
|
|
548
|
+
.argument('[id]', 'sandbox id; omit when using --tag')
|
|
549
|
+
.option('--tag <key=value>', 'find the sandbox by tag instead of id; repeatable, must match exactly one', collectRepeatable, [])
|
|
550
|
+
.action((id, opts) => run(async () => {
|
|
502
551
|
const credentials = requireCredentials();
|
|
503
552
|
const api = new ApiClient(credentials.apiUrl, credentials.token);
|
|
504
|
-
await
|
|
553
|
+
const sandboxId = id ?? (await resolveSandboxByTag(api, opts.tag ?? []));
|
|
554
|
+
await prepareSandboxShell(api, sandboxId);
|
|
505
555
|
process.exitCode = await runSandboxShell({
|
|
506
556
|
apiUrl: credentials.apiUrl,
|
|
507
557
|
token: credentials.token,
|
|
508
|
-
sandboxId
|
|
558
|
+
sandboxId,
|
|
509
559
|
});
|
|
510
560
|
}));
|
|
511
561
|
for (const lifecycle of [
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const CLI_VERSION = '0.1.
|
|
1
|
+
export const CLI_VERSION = '0.1.107';
|