zcode-app-cli 3.3.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/LICENSE +24 -0
- package/README.md +642 -0
- package/bin/zcode.js +848 -0
- package/config.example.json +110 -0
- package/package.json +81 -0
- package/vendor/.node-bundle-meta.json +6 -0
- package/vendor/extraction.json +11 -0
- package/vendor/node_modules/@zcode/tui/dist/index.js +161875 -0
- package/vendor/node_modules/@zcode/tui/package.json +14 -0
- package/vendor/packages/android-emulator-plugin/.mcp.json +19 -0
- package/vendor/packages/android-emulator-plugin/.zcode-plugin/plugin.json +63 -0
- package/vendor/packages/android-emulator-plugin/README.md +134 -0
- package/vendor/packages/android-emulator-plugin/commands/android-dev.md +11 -0
- package/vendor/packages/android-emulator-plugin/dist/lib/path.d.ts +4 -0
- package/vendor/packages/android-emulator-plugin/dist/lib/path.js +17 -0
- package/vendor/packages/android-emulator-plugin/dist/lib/result.d.ts +5 -0
- package/vendor/packages/android-emulator-plugin/dist/lib/result.js +22 -0
- package/vendor/packages/android-emulator-plugin/dist/lib/run.d.ts +18 -0
- package/vendor/packages/android-emulator-plugin/dist/lib/run.js +99 -0
- package/vendor/packages/android-emulator-plugin/dist/mcp/server.d.ts +3 -0
- package/vendor/packages/android-emulator-plugin/dist/mcp/server.js +47607 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/app.d.ts +39 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/app.js +50 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/avd.d.ts +37 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/avd.js +185 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/build.d.ts +68 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/build.js +131 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/config.d.ts +7 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/config.js +29 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/device.d.ts +20 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/device.js +91 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/logs.d.ts +15 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/logs.js +31 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/preflight.d.ts +15 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/preflight.js +123 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/project-template.d.ts +13 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/project-template.js +211 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/project.d.ts +33 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/project.js +195 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/screenshot.d.ts +14 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/screenshot.js +73 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/sdk.d.ts +14 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/sdk.js +185 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/ui.d.ts +92 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/ui.js +146 -0
- package/vendor/packages/android-emulator-plugin/hooks/hooks.json +3 -0
- package/vendor/packages/android-emulator-plugin/package.json +35 -0
- package/vendor/packages/android-emulator-plugin/skills/android-dev/INSTALL_ENVIRONMENT.md +357 -0
- package/vendor/packages/android-emulator-plugin/skills/android-dev/SKILL.md +73 -0
- package/vendor/packages/android-emulator-plugin/templates/compose-app/README.md +5 -0
- package/vendor/packages/document-skills-plugin/.zcode-plugin/plugin.json +8 -0
- package/vendor/packages/document-skills-plugin/package.json +8 -0
- package/vendor/packages/document-skills-plugin/skills/docx/LICENSE.txt +13 -0
- package/vendor/packages/document-skills-plugin/skills/docx/SKILL.md +201 -0
- package/vendor/packages/document-skills-plugin/skills/docx/references/chart-templates.md +386 -0
- package/vendor/packages/document-skills-plugin/skills/docx/references/common-rules.md +419 -0
- package/vendor/packages/document-skills-plugin/skills/docx/references/decorations.md +537 -0
- package/vendor/packages/document-skills-plugin/skills/docx/references/design-system.md +1797 -0
- package/vendor/packages/document-skills-plugin/skills/docx/references/docx-js-advanced.md +257 -0
- package/vendor/packages/document-skills-plugin/skills/docx/references/docx-js-core.md +332 -0
- package/vendor/packages/document-skills-plugin/skills/docx/references/faq.md +323 -0
- package/vendor/packages/document-skills-plugin/skills/docx/references/math-formulas.md +276 -0
- package/vendor/packages/document-skills-plugin/skills/docx/references/ooxml.md +222 -0
- package/vendor/packages/document-skills-plugin/skills/docx/references/toc.md +264 -0
- package/vendor/packages/document-skills-plugin/skills/docx/routes/comment.md +88 -0
- package/vendor/packages/document-skills-plugin/skills/docx/routes/create.md +207 -0
- package/vendor/packages/document-skills-plugin/skills/docx/routes/edit.md +115 -0
- package/vendor/packages/document-skills-plugin/skills/docx/routes/format.md +120 -0
- package/vendor/packages/document-skills-plugin/skills/docx/routes/read.md +114 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scenes/academic.md +783 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scenes/contract.md +463 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scenes/copywriting.md +139 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scenes/exam.md +698 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scenes/official-doc.md +411 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scenes/report.md +340 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scenes/resume.md +534 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scripts/__init__.py +1 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scripts/add_toc_placeholders.py +749 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scripts/document.py +1333 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scripts/postcheck.py +807 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scripts/templates/comments.xml +3 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scripts/templates/commentsExtended.xml +3 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scripts/templates/commentsExtensible.xml +3 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scripts/templates/commentsIds.xml +3 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scripts/templates/people.xml +3 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scripts/utilities.py +374 -0
- package/vendor/packages/document-skills-plugin/skills/docx/setup.sh +177 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/LICENSE.txt +13 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/SKILL.md +919 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/briefs/academic.md +1058 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/briefs/creative.md +770 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/briefs/poster.md +702 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/briefs/process-advanced.md +284 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/briefs/process.md +319 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/briefs/report.md +1659 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/configs/components.md +153 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/configs/fonts.md +93 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/configs/visual_framework.md +263 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/references/resume-academic.tex +130 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/references/resume-altacv.tex +190 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/scripts/cover_validate.js +367 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/scripts/design_engine.py +2816 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/scripts/html2pdf-next.js +754 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/scripts/html2poster.js +256 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/scripts/pdf.py +2959 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/scripts/pdf_qa.py +901 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/scripts/poster_validate.py +1337 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/scripts/setup.sh +269 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/scripts/toc_validate.py +2075 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/charts.md +320 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/cover-backgrounds.md +384 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/cover.md +1442 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/fill-engine.md +527 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/geometry.md +142 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/overflow.md +630 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/pagination.md +367 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/palette.md +217 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/typography.md +20 -0
- package/vendor/packages/ios-simulator-plugin/.mcp.json +15 -0
- package/vendor/packages/ios-simulator-plugin/.zcode-plugin/plugin.json +34 -0
- package/vendor/packages/ios-simulator-plugin/README.md +111 -0
- package/vendor/packages/ios-simulator-plugin/commands/ios-dev.md +11 -0
- package/vendor/packages/ios-simulator-plugin/dist/lib/path.d.ts +4 -0
- package/vendor/packages/ios-simulator-plugin/dist/lib/path.js +18 -0
- package/vendor/packages/ios-simulator-plugin/dist/lib/result.d.ts +5 -0
- package/vendor/packages/ios-simulator-plugin/dist/lib/result.js +20 -0
- package/vendor/packages/ios-simulator-plugin/dist/lib/run.d.ts +17 -0
- package/vendor/packages/ios-simulator-plugin/dist/lib/run.js +83 -0
- package/vendor/packages/ios-simulator-plugin/dist/mcp/server.d.ts +3 -0
- package/vendor/packages/ios-simulator-plugin/dist/mcp/server.js +46833 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/build.d.ts +112 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/build.js +99 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/logs.d.ts +21 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/logs.js +26 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/preflight.d.ts +12 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/preflight.js +62 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/project.d.ts +35 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/project.js +288 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/screenshot.d.ts +22 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/screenshot.js +30 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/sim.d.ts +60 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/sim.js +116 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/ui.d.ts +57 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/ui.js +67 -0
- package/vendor/packages/ios-simulator-plugin/hooks/hooks.json +3 -0
- package/vendor/packages/ios-simulator-plugin/package.json +35 -0
- package/vendor/packages/ios-simulator-plugin/skills/ios-dev/SKILL.md +45 -0
- package/vendor/packages/ios-simulator-plugin/templates/swiftui-app/README.md +5 -0
- package/vendor/packages/restore-legacy-sessions-plugin/.zcode-plugin/plugin.json +9 -0
- package/vendor/packages/restore-legacy-sessions-plugin/README.md +35 -0
- package/vendor/packages/restore-legacy-sessions-plugin/commands/restore-legacy-sessions.md +11 -0
- package/vendor/packages/restore-legacy-sessions-plugin/package.json +8 -0
- package/vendor/packages/restore-legacy-sessions-plugin/skills/restore-legacy-sessions/SKILL.md +92 -0
- package/vendor/packages/restore-legacy-sessions-plugin/skills/restore-legacy-sessions/scripts/restore-conversation.mjs +648 -0
- package/vendor/packages/restore-legacy-sessions-plugin/skills/restore-legacy-sessions/scripts/scan-legacy-sessions.mjs +422 -0
- package/vendor/packages/skill-creator-plugin/.zcode-plugin/plugin.json +8 -0
- package/vendor/packages/skill-creator-plugin/package.json +8 -0
- package/vendor/packages/skill-creator-plugin/skills/skill-creator/SKILL.md +159 -0
- package/vendor/packages/zcode-guide-plugin/.zcode-plugin/plugin.json +8 -0
- package/vendor/packages/zcode-guide-plugin/README.md +22 -0
- package/vendor/packages/zcode-guide-plugin/package.json +8 -0
- package/vendor/packages/zcode-guide-plugin/skills/diagnosing-commands/SKILL.md +66 -0
- package/vendor/packages/zcode-guide-plugin/skills/diagnosing-hooks/SKILL.md +66 -0
- package/vendor/packages/zcode-guide-plugin/skills/diagnosing-mcp/SKILL.md +97 -0
- package/vendor/packages/zcode-guide-plugin/skills/diagnosing-plugins/SKILL.md +59 -0
- package/vendor/packages/zcode-guide-plugin/skills/diagnosing-skills/SKILL.md +61 -0
- package/vendor/packages/zcode-guide-plugin/skills/zcode-configuration-guide/SKILL.md +99 -0
- package/vendor/zcode.cjs +2926 -0
- package/zcode-runtime.lock.json +8 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
type Target = {
|
|
2
|
+
serial?: string;
|
|
3
|
+
avd?: string;
|
|
4
|
+
timeoutMs?: number;
|
|
5
|
+
};
|
|
6
|
+
export declare function install(input: Target & {
|
|
7
|
+
apkPath: string;
|
|
8
|
+
}): Promise<{
|
|
9
|
+
installed: boolean;
|
|
10
|
+
serial: string;
|
|
11
|
+
apkPath: string;
|
|
12
|
+
output: string;
|
|
13
|
+
}>;
|
|
14
|
+
export declare function launch(input: Target & {
|
|
15
|
+
applicationId: string;
|
|
16
|
+
activity?: string;
|
|
17
|
+
}): Promise<{
|
|
18
|
+
launched: boolean;
|
|
19
|
+
serial: string;
|
|
20
|
+
applicationId: string;
|
|
21
|
+
output: string;
|
|
22
|
+
}>;
|
|
23
|
+
export declare function terminate(input: Target & {
|
|
24
|
+
applicationId: string;
|
|
25
|
+
}): Promise<{
|
|
26
|
+
terminated: boolean;
|
|
27
|
+
serial: string;
|
|
28
|
+
applicationId: string;
|
|
29
|
+
}>;
|
|
30
|
+
export declare function openUrl(input: Target & {
|
|
31
|
+
url: string;
|
|
32
|
+
}): Promise<{
|
|
33
|
+
opened: boolean;
|
|
34
|
+
serial: string;
|
|
35
|
+
url: string;
|
|
36
|
+
}>;
|
|
37
|
+
export declare function packageName(value: string): string;
|
|
38
|
+
export {};
|
|
39
|
+
//# sourceMappingURL=app.d.ts.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { inside } from "../lib/path.js";
|
|
2
|
+
import { brief, ok, run } from "../lib/run.js";
|
|
3
|
+
import { ensureDevice } from "./avd.js";
|
|
4
|
+
import { adbShell } from "./device.js";
|
|
5
|
+
import { androidEnv, requireTool } from "./sdk.js";
|
|
6
|
+
const PACKAGE = /^[A-Za-z][A-Za-z0-9_]*(?:\.[A-Za-z][A-Za-z0-9_]*)+$/;
|
|
7
|
+
export async function install(input) {
|
|
8
|
+
const device = await ensureDevice(input);
|
|
9
|
+
const apk = inside(process.cwd(), input.apkPath);
|
|
10
|
+
const adb = await requireTool("adb");
|
|
11
|
+
const out = await run([adb, "-s", device.serial, "install", "-r", apk], {
|
|
12
|
+
timeout: input.timeoutMs ?? 120_000,
|
|
13
|
+
env: await androidEnv(),
|
|
14
|
+
});
|
|
15
|
+
if (!ok(out))
|
|
16
|
+
throw new Error(brief(out));
|
|
17
|
+
return { installed: true, serial: device.serial, apkPath: input.apkPath, output: brief(out) };
|
|
18
|
+
}
|
|
19
|
+
export async function launch(input) {
|
|
20
|
+
const device = await ensureDevice(input);
|
|
21
|
+
const app = packageName(input.applicationId);
|
|
22
|
+
const out = input.activity
|
|
23
|
+
? await adbShell(device.serial, ["am", "start", "-W", "-n", `${app}/${input.activity}`], input.timeoutMs ?? 60_000)
|
|
24
|
+
: await adbShell(device.serial, ["monkey", "-p", app, "-c", "android.intent.category.LAUNCHER", "1"], input.timeoutMs ?? 60_000);
|
|
25
|
+
return { launched: true, serial: device.serial, applicationId: app, output: brief(out) };
|
|
26
|
+
}
|
|
27
|
+
export async function terminate(input) {
|
|
28
|
+
const device = await ensureDevice(input);
|
|
29
|
+
const app = packageName(input.applicationId);
|
|
30
|
+
await adbShell(device.serial, ["am", "force-stop", app], input.timeoutMs ?? 30_000);
|
|
31
|
+
return { terminated: true, serial: device.serial, applicationId: app };
|
|
32
|
+
}
|
|
33
|
+
export async function openUrl(input) {
|
|
34
|
+
const device = await ensureDevice(input);
|
|
35
|
+
const value = url(input.url);
|
|
36
|
+
await adbShell(device.serial, ["am", "start", "-a", "android.intent.action.VIEW", "-d", value], input.timeoutMs ?? 30_000);
|
|
37
|
+
return { opened: true, serial: device.serial, url: value };
|
|
38
|
+
}
|
|
39
|
+
export function packageName(value) {
|
|
40
|
+
if (!PACKAGE.test(value))
|
|
41
|
+
throw new Error(`Invalid Android application id: ${value}`);
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
function url(value) {
|
|
45
|
+
if (value.length > 2048)
|
|
46
|
+
throw new Error("URL is too long.");
|
|
47
|
+
if (!/^[A-Za-z][A-Za-z0-9+.-]*:/.test(value))
|
|
48
|
+
throw new Error(`Invalid URL: ${value}`);
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type Device } from "./device.js";
|
|
2
|
+
type Avd = {
|
|
3
|
+
name: string;
|
|
4
|
+
};
|
|
5
|
+
type StartInput = {
|
|
6
|
+
serial?: string;
|
|
7
|
+
avd?: string;
|
|
8
|
+
timeoutMs?: number;
|
|
9
|
+
};
|
|
10
|
+
type StartResult = Device & {
|
|
11
|
+
reused: boolean;
|
|
12
|
+
started: boolean;
|
|
13
|
+
};
|
|
14
|
+
export declare function listAvds(): Promise<Avd[]>;
|
|
15
|
+
export declare function parseAvds(value: string): Avd[];
|
|
16
|
+
export declare function ensureDevice(input?: StartInput): Promise<Device>;
|
|
17
|
+
export declare function startEmulator(input?: StartInput): Promise<StartResult>;
|
|
18
|
+
export declare function stopEmulator(input: {
|
|
19
|
+
serial: string;
|
|
20
|
+
}): Promise<{
|
|
21
|
+
stopped: boolean;
|
|
22
|
+
serial: string;
|
|
23
|
+
}>;
|
|
24
|
+
export declare function createAvd(input?: {
|
|
25
|
+
name?: string;
|
|
26
|
+
packageId?: string;
|
|
27
|
+
device?: string;
|
|
28
|
+
force?: boolean;
|
|
29
|
+
}): Promise<{
|
|
30
|
+
created: boolean;
|
|
31
|
+
name: string;
|
|
32
|
+
packageId: string;
|
|
33
|
+
output: string;
|
|
34
|
+
}>;
|
|
35
|
+
export declare function startedEmulatorCandidates(devices: Device[], before: Set<string>): Device[];
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=avd.d.ts.map
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { spawn as spawnChild } from "node:child_process";
|
|
2
|
+
import { brief, ok, run } from "../lib/run.js";
|
|
3
|
+
import { androidSystemImagePackage } from "./config.js";
|
|
4
|
+
import { isBootComplete, listDevices, pickDevice, validSerial } from "./device.js";
|
|
5
|
+
import { androidEnv, requireTool } from "./sdk.js";
|
|
6
|
+
const AVD = /^[A-Za-z0-9_. -]+$/;
|
|
7
|
+
const EMULATOR_BOOT_POLL_MS = 2_000;
|
|
8
|
+
const AVD_NAME_TIMEOUT_MS = 5_000;
|
|
9
|
+
export async function listAvds() {
|
|
10
|
+
const emulator = await requireTool("emulator");
|
|
11
|
+
const out = await run([emulator, "-list-avds"], { timeout: 20_000, env: await androidEnv() });
|
|
12
|
+
if (!ok(out))
|
|
13
|
+
throw new Error(brief(out));
|
|
14
|
+
return parseAvds(out.stdout);
|
|
15
|
+
}
|
|
16
|
+
export function parseAvds(value) {
|
|
17
|
+
return value
|
|
18
|
+
.split(/\r?\n/)
|
|
19
|
+
.map((line) => line.trim())
|
|
20
|
+
.filter((line) => line.length > 0)
|
|
21
|
+
.map((name) => ({ name }));
|
|
22
|
+
}
|
|
23
|
+
export async function ensureDevice(input = {}) {
|
|
24
|
+
const timeoutMs = input.timeoutMs ?? 180_000;
|
|
25
|
+
if (input.serial)
|
|
26
|
+
return waitForReadyTarget(await pickDevice({ serial: input.serial }), timeoutMs);
|
|
27
|
+
const ready = await pickDevice().catch(() => undefined);
|
|
28
|
+
if (ready)
|
|
29
|
+
return waitForReadyTarget(ready, timeoutMs);
|
|
30
|
+
return startEmulator(input);
|
|
31
|
+
}
|
|
32
|
+
export async function startEmulator(input = {}) {
|
|
33
|
+
const timeoutMs = input.timeoutMs ?? 180_000;
|
|
34
|
+
if (input.serial) {
|
|
35
|
+
throw new Error("android_start_emulator always starts a new emulator. Reuse an existing target by passing serial to build, install, launch, screenshot, log, or UI tools.");
|
|
36
|
+
}
|
|
37
|
+
const avd = await pickAvd(input.avd);
|
|
38
|
+
const running = await runningAvd(avd.name);
|
|
39
|
+
if (running) {
|
|
40
|
+
throw new Error(`Android AVD "${avd.name}" is already running as ${running.serial}. Reuse it by passing serial "${running.serial}" to target tools, or choose another AVD.`);
|
|
41
|
+
}
|
|
42
|
+
const before = new Set((await listDevices().catch(() => [])).map((item) => item.serial));
|
|
43
|
+
const emulator = await requireTool("emulator");
|
|
44
|
+
const env = await androidEnv();
|
|
45
|
+
const child = spawnChild(emulator, ["-avd", avd.name], {
|
|
46
|
+
env: Object.fromEntries(Object.entries({ ...process.env, ...env }).filter((item) => typeof item[1] === "string")),
|
|
47
|
+
shell: false,
|
|
48
|
+
stdio: "ignore",
|
|
49
|
+
});
|
|
50
|
+
await waitForSpawn(child);
|
|
51
|
+
child.unref();
|
|
52
|
+
const device = await waitForStartedDevice(before, avd.name, timeoutMs);
|
|
53
|
+
return targetResult({ ...device, raw: `${device.raw} pid:${child.pid}` }, true);
|
|
54
|
+
}
|
|
55
|
+
export async function stopEmulator(input) {
|
|
56
|
+
if (!validSerial(input.serial))
|
|
57
|
+
throw new Error(`Invalid Android device serial: ${input.serial}`);
|
|
58
|
+
const adb = await requireTool("adb");
|
|
59
|
+
const out = await run([adb, "-s", input.serial, "emu", "kill"], {
|
|
60
|
+
timeout: 20_000,
|
|
61
|
+
env: await androidEnv(),
|
|
62
|
+
});
|
|
63
|
+
if (!ok(out))
|
|
64
|
+
throw new Error(brief(out));
|
|
65
|
+
return { stopped: true, serial: input.serial };
|
|
66
|
+
}
|
|
67
|
+
export async function createAvd(input = {}) {
|
|
68
|
+
const name = cleanAvd(input.name || process.env.ANDROID_PLUGIN_DEFAULT_AVD || "medium_phone");
|
|
69
|
+
const pkg = input.packageId || defaultSystemImage();
|
|
70
|
+
const avdmanager = await requireTool("avdmanager");
|
|
71
|
+
const args = ["create", "avd", "--name", name, "--package", pkg];
|
|
72
|
+
if (input.device)
|
|
73
|
+
args.push("--device", input.device);
|
|
74
|
+
if (input.force)
|
|
75
|
+
args.push("--force");
|
|
76
|
+
const out = await run([avdmanager, ...args], {
|
|
77
|
+
input: "no\n",
|
|
78
|
+
timeout: 120_000,
|
|
79
|
+
env: await androidEnv(),
|
|
80
|
+
});
|
|
81
|
+
if (!ok(out))
|
|
82
|
+
throw new Error(brief(out));
|
|
83
|
+
return {
|
|
84
|
+
created: true,
|
|
85
|
+
name,
|
|
86
|
+
packageId: pkg,
|
|
87
|
+
output: brief(out),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
async function pickAvd(name) {
|
|
91
|
+
if (name && !AVD.test(name))
|
|
92
|
+
throw new Error(`Invalid Android AVD name: ${name}`);
|
|
93
|
+
const avds = await listAvds();
|
|
94
|
+
const want = name || process.env.ANDROID_PLUGIN_DEFAULT_AVD;
|
|
95
|
+
if (want) {
|
|
96
|
+
const hit = avds.find((item) => item.name === want || item.name.toLowerCase().includes(want.toLowerCase()));
|
|
97
|
+
if (hit)
|
|
98
|
+
return hit;
|
|
99
|
+
}
|
|
100
|
+
const first = avds[0];
|
|
101
|
+
if (first)
|
|
102
|
+
return first;
|
|
103
|
+
throw new Error("No Android AVDs found. Create one in Android Studio or call android_create_avd after confirming setup.");
|
|
104
|
+
}
|
|
105
|
+
async function waitForStartedDevice(before, avdName, timeoutMs) {
|
|
106
|
+
const deadline = Date.now() + timeoutMs;
|
|
107
|
+
let last = [];
|
|
108
|
+
while (Date.now() < deadline) {
|
|
109
|
+
last = await listDevices().catch(() => []);
|
|
110
|
+
for (const fresh of startedEmulatorCandidates(last, before)) {
|
|
111
|
+
if (!(await isBootComplete(fresh.serial)))
|
|
112
|
+
continue;
|
|
113
|
+
const name = await avdNameFor(fresh.serial).catch(() => undefined);
|
|
114
|
+
if (name === avdName)
|
|
115
|
+
return fresh;
|
|
116
|
+
}
|
|
117
|
+
await sleep(EMULATOR_BOOT_POLL_MS);
|
|
118
|
+
}
|
|
119
|
+
const detail = last.length
|
|
120
|
+
? last.map((item) => `${item.serial}:${item.state}`).join(", ")
|
|
121
|
+
: "no adb devices";
|
|
122
|
+
throw new Error(`Timed out waiting for Android Emulator to boot (${detail}).`);
|
|
123
|
+
}
|
|
124
|
+
export function startedEmulatorCandidates(devices, before) {
|
|
125
|
+
return devices.filter((item) => {
|
|
126
|
+
return item.kind === "emulator" && item.state === "device" && !before.has(item.serial);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
async function waitForReadyTarget(device, timeoutMs) {
|
|
130
|
+
if (device.kind !== "emulator")
|
|
131
|
+
return device;
|
|
132
|
+
const deadline = Date.now() + timeoutMs;
|
|
133
|
+
while (Date.now() < deadline) {
|
|
134
|
+
if (await isBootComplete(device.serial))
|
|
135
|
+
return device;
|
|
136
|
+
await sleep(EMULATOR_BOOT_POLL_MS);
|
|
137
|
+
}
|
|
138
|
+
throw new Error(`Timed out waiting for Android Emulator to boot (${device.serial}).`);
|
|
139
|
+
}
|
|
140
|
+
async function runningAvd(name) {
|
|
141
|
+
const emulators = (await listDevices().catch(() => [])).filter((item) => item.kind === "emulator" && item.state === "device");
|
|
142
|
+
for (const device of emulators) {
|
|
143
|
+
const avdName = await avdNameFor(device.serial).catch(() => undefined);
|
|
144
|
+
if (avdName === name)
|
|
145
|
+
return device;
|
|
146
|
+
}
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
async function avdNameFor(serial) {
|
|
150
|
+
const adb = await requireTool("adb");
|
|
151
|
+
const out = await run([adb, "-s", serial, "emu", "avd", "name"], {
|
|
152
|
+
timeout: AVD_NAME_TIMEOUT_MS,
|
|
153
|
+
env: await androidEnv(),
|
|
154
|
+
});
|
|
155
|
+
if (!ok(out))
|
|
156
|
+
return undefined;
|
|
157
|
+
return out.stdout
|
|
158
|
+
.split(/\r?\n/)
|
|
159
|
+
.map((line) => line.trim())
|
|
160
|
+
.find((line) => line.length > 0 && line !== "OK");
|
|
161
|
+
}
|
|
162
|
+
function targetResult(device, started) {
|
|
163
|
+
return {
|
|
164
|
+
...device,
|
|
165
|
+
reused: !started,
|
|
166
|
+
started,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
function sleep(ms) {
|
|
170
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
171
|
+
}
|
|
172
|
+
function waitForSpawn(child) {
|
|
173
|
+
return new Promise((resolve, reject) => {
|
|
174
|
+
child.once("error", reject);
|
|
175
|
+
child.once("spawn", resolve);
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
function cleanAvd(value) {
|
|
179
|
+
if (!AVD.test(value))
|
|
180
|
+
throw new Error(`Invalid Android AVD name: ${value}`);
|
|
181
|
+
return value.trim();
|
|
182
|
+
}
|
|
183
|
+
function defaultSystemImage() {
|
|
184
|
+
return androidSystemImagePackage();
|
|
185
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
type Build = {
|
|
2
|
+
projectDir?: string;
|
|
3
|
+
module?: string;
|
|
4
|
+
variant?: string;
|
|
5
|
+
applicationId?: string;
|
|
6
|
+
serial?: string;
|
|
7
|
+
avd?: string;
|
|
8
|
+
timeoutMs?: number;
|
|
9
|
+
};
|
|
10
|
+
type RunApp = Build & {
|
|
11
|
+
launchActivity?: string;
|
|
12
|
+
};
|
|
13
|
+
export declare function buildApp(input?: Build): Promise<{
|
|
14
|
+
ok: boolean;
|
|
15
|
+
root: string;
|
|
16
|
+
module: string;
|
|
17
|
+
variant: string;
|
|
18
|
+
task: string;
|
|
19
|
+
apkPath: string | undefined;
|
|
20
|
+
applicationId: string;
|
|
21
|
+
logPath: string;
|
|
22
|
+
code: number;
|
|
23
|
+
timedOut: boolean;
|
|
24
|
+
output: string;
|
|
25
|
+
}>;
|
|
26
|
+
export declare function buildAndRun(input?: RunApp): Promise<{
|
|
27
|
+
installed: boolean;
|
|
28
|
+
launched: boolean;
|
|
29
|
+
ok: boolean;
|
|
30
|
+
root: string;
|
|
31
|
+
module: string;
|
|
32
|
+
variant: string;
|
|
33
|
+
task: string;
|
|
34
|
+
apkPath: string | undefined;
|
|
35
|
+
applicationId: string;
|
|
36
|
+
logPath: string;
|
|
37
|
+
code: number;
|
|
38
|
+
timedOut: boolean;
|
|
39
|
+
output: string;
|
|
40
|
+
} | {
|
|
41
|
+
device: import("./device.js").Device;
|
|
42
|
+
installed: {
|
|
43
|
+
installed: boolean;
|
|
44
|
+
serial: string;
|
|
45
|
+
apkPath: string;
|
|
46
|
+
output: string;
|
|
47
|
+
};
|
|
48
|
+
launched: {
|
|
49
|
+
launched: boolean;
|
|
50
|
+
serial: string;
|
|
51
|
+
applicationId: string;
|
|
52
|
+
output: string;
|
|
53
|
+
};
|
|
54
|
+
ok: boolean;
|
|
55
|
+
root: string;
|
|
56
|
+
module: string;
|
|
57
|
+
variant: string;
|
|
58
|
+
task: string;
|
|
59
|
+
apkPath: string | undefined;
|
|
60
|
+
applicationId: string;
|
|
61
|
+
logPath: string;
|
|
62
|
+
code: number;
|
|
63
|
+
timedOut: boolean;
|
|
64
|
+
output: string;
|
|
65
|
+
}>;
|
|
66
|
+
export declare function pickApk(hits: string[], variant: string): string | undefined;
|
|
67
|
+
export {};
|
|
68
|
+
//# sourceMappingURL=build.d.ts.map
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { access, mkdir, writeFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import { data, inside, rel } from "../lib/path.js";
|
|
5
|
+
import { brief, ok, run } from "../lib/run.js";
|
|
6
|
+
import { install, launch } from "./app.js";
|
|
7
|
+
import { ensureDevice } from "./avd.js";
|
|
8
|
+
import { discover, findApks } from "./project.js";
|
|
9
|
+
import { androidEnv, findTool } from "./sdk.js";
|
|
10
|
+
export async function buildApp(input = {}) {
|
|
11
|
+
const root = await projectRoot(input.projectDir);
|
|
12
|
+
const found = await discover(root);
|
|
13
|
+
const module = normalizeModule(input.module || found.modules[0] || "app");
|
|
14
|
+
const variant = input.variant || found.variants[0] || "debug";
|
|
15
|
+
const task = `:${module}:assemble${cap(variant)}`;
|
|
16
|
+
const gradle = await gradleCommand(root);
|
|
17
|
+
const out = await run([...gradle, task], {
|
|
18
|
+
cwd: root,
|
|
19
|
+
timeout: input.timeoutMs ?? 600_000,
|
|
20
|
+
env: await androidEnv(),
|
|
21
|
+
});
|
|
22
|
+
const log = await record("build", out);
|
|
23
|
+
const apk = ok(out) ? await findApk(root, module, variant) : undefined;
|
|
24
|
+
const applicationId = input.applicationId || found.applicationIds[0];
|
|
25
|
+
return {
|
|
26
|
+
ok: ok(out),
|
|
27
|
+
root: rel(root),
|
|
28
|
+
module,
|
|
29
|
+
variant,
|
|
30
|
+
task,
|
|
31
|
+
apkPath: apk ? rel(apk) : undefined,
|
|
32
|
+
applicationId,
|
|
33
|
+
logPath: log,
|
|
34
|
+
code: out.code,
|
|
35
|
+
timedOut: out.timed,
|
|
36
|
+
output: brief(out, 12_000),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export async function buildAndRun(input = {}) {
|
|
40
|
+
const built = await buildApp(input);
|
|
41
|
+
if (!built.ok)
|
|
42
|
+
return { ...built, installed: false, launched: false };
|
|
43
|
+
if (!built.apkPath)
|
|
44
|
+
throw new Error("Build succeeded, but no APK product was found.");
|
|
45
|
+
if (!built.applicationId)
|
|
46
|
+
throw new Error("Build succeeded, but applicationId could not be resolved.");
|
|
47
|
+
const device = await ensureDevice({
|
|
48
|
+
serial: input.serial,
|
|
49
|
+
avd: input.avd,
|
|
50
|
+
timeoutMs: input.timeoutMs,
|
|
51
|
+
});
|
|
52
|
+
const installed = await install({
|
|
53
|
+
serial: device.serial,
|
|
54
|
+
apkPath: built.apkPath,
|
|
55
|
+
timeoutMs: input.timeoutMs,
|
|
56
|
+
});
|
|
57
|
+
const launched = await launch({
|
|
58
|
+
serial: device.serial,
|
|
59
|
+
applicationId: built.applicationId,
|
|
60
|
+
activity: input.launchActivity,
|
|
61
|
+
timeoutMs: input.timeoutMs,
|
|
62
|
+
});
|
|
63
|
+
return { ...built, device, installed, launched };
|
|
64
|
+
}
|
|
65
|
+
async function projectRoot(raw) {
|
|
66
|
+
if (raw)
|
|
67
|
+
return inside(process.cwd(), raw);
|
|
68
|
+
const found = await discover();
|
|
69
|
+
if (found.root !== undefined)
|
|
70
|
+
return inside(process.cwd(), found.root || ".");
|
|
71
|
+
throw new Error("No Android Gradle project found. Use android_create_app first.");
|
|
72
|
+
}
|
|
73
|
+
async function findApk(root, module, variant) {
|
|
74
|
+
const hits = await findApks(root, [module]);
|
|
75
|
+
return pickApk(hits, variant);
|
|
76
|
+
}
|
|
77
|
+
export function pickApk(hits, variant) {
|
|
78
|
+
const want = `${path.sep}${variant.toLowerCase()}${path.sep}`;
|
|
79
|
+
return hits.find((item) => item.toLowerCase().includes(want)) || hits[0];
|
|
80
|
+
}
|
|
81
|
+
async function gradleCommand(root) {
|
|
82
|
+
const wrapper = path.join(root, process.platform === "win32" ? "gradlew.bat" : "gradlew");
|
|
83
|
+
if (await exists(wrapper))
|
|
84
|
+
return [wrapper];
|
|
85
|
+
const gradle = await findTool("gradle");
|
|
86
|
+
if (gradle) {
|
|
87
|
+
const generated = await run([gradle, "wrapper", "--gradle-version", "8.9"], {
|
|
88
|
+
cwd: root,
|
|
89
|
+
timeout: 120_000,
|
|
90
|
+
env: await androidEnv(),
|
|
91
|
+
});
|
|
92
|
+
if (ok(generated) && (await exists(wrapper)))
|
|
93
|
+
return [wrapper];
|
|
94
|
+
return [gradle];
|
|
95
|
+
}
|
|
96
|
+
throw new Error("No Gradle wrapper or gradle executable found. Generate a wrapper or install Gradle.");
|
|
97
|
+
}
|
|
98
|
+
async function record(name, out) {
|
|
99
|
+
const dir = await data("logs");
|
|
100
|
+
const file = path.join(dir, `${stamp()}-${name}-${key(process.cwd())}.log`);
|
|
101
|
+
await mkdir(dir, { recursive: true });
|
|
102
|
+
await writeFile(file, [
|
|
103
|
+
`$ ${out.cmd.join(" ")}`,
|
|
104
|
+
`exit=${out.code}`,
|
|
105
|
+
`timedOut=${out.timed}`,
|
|
106
|
+
"",
|
|
107
|
+
out.stdout,
|
|
108
|
+
out.stderr,
|
|
109
|
+
].join("\n"), "utf8");
|
|
110
|
+
return rel(file);
|
|
111
|
+
}
|
|
112
|
+
async function exists(file) {
|
|
113
|
+
return access(file)
|
|
114
|
+
.then(() => true)
|
|
115
|
+
.catch(() => false);
|
|
116
|
+
}
|
|
117
|
+
function normalizeModule(value) {
|
|
118
|
+
return value.replace(/^:+/, "") || "app";
|
|
119
|
+
}
|
|
120
|
+
function cap(value) {
|
|
121
|
+
return value
|
|
122
|
+
.split(/[-_]/g)
|
|
123
|
+
.map((item) => item.charAt(0).toUpperCase() + item.slice(1))
|
|
124
|
+
.join("");
|
|
125
|
+
}
|
|
126
|
+
function key(value) {
|
|
127
|
+
return createHash("sha1").update(value).digest("hex").slice(0, 8);
|
|
128
|
+
}
|
|
129
|
+
function stamp() {
|
|
130
|
+
return new Date().toISOString().replaceAll(/[:.]/g, "-");
|
|
131
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function androidApiLevel(): number;
|
|
2
|
+
export declare function androidBuildToolsVersion(): string;
|
|
3
|
+
export declare function androidSystemImageVariant(): string;
|
|
4
|
+
export declare function androidSystemImageAbi(): string;
|
|
5
|
+
export declare function androidSystemImagePackage(): string;
|
|
6
|
+
export declare function javaMajorVersion(): string;
|
|
7
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export function androidApiLevel() {
|
|
2
|
+
return intEnv("ANDROID_PLUGIN_API_LEVEL", 35);
|
|
3
|
+
}
|
|
4
|
+
export function androidBuildToolsVersion() {
|
|
5
|
+
return stringEnv("ANDROID_PLUGIN_BUILD_TOOLS_VERSION", "35.0.0");
|
|
6
|
+
}
|
|
7
|
+
export function androidSystemImageVariant() {
|
|
8
|
+
return stringEnv("ANDROID_PLUGIN_SYSTEM_IMAGE_VARIANT", "default");
|
|
9
|
+
}
|
|
10
|
+
export function androidSystemImageAbi() {
|
|
11
|
+
return stringEnv("ANDROID_PLUGIN_SYSTEM_IMAGE_ABI", process.arch === "arm64" ? "arm64-v8a" : "x86_64");
|
|
12
|
+
}
|
|
13
|
+
export function androidSystemImagePackage() {
|
|
14
|
+
return `system-images;android-${androidApiLevel()};${androidSystemImageVariant()};${androidSystemImageAbi()}`;
|
|
15
|
+
}
|
|
16
|
+
export function javaMajorVersion() {
|
|
17
|
+
return stringEnv("ANDROID_PLUGIN_JDK_MAJOR", "17");
|
|
18
|
+
}
|
|
19
|
+
function stringEnv(name, fallback) {
|
|
20
|
+
const value = process.env[name]?.trim();
|
|
21
|
+
return value || fallback;
|
|
22
|
+
}
|
|
23
|
+
function intEnv(name, fallback) {
|
|
24
|
+
const value = process.env[name]?.trim();
|
|
25
|
+
if (!value)
|
|
26
|
+
return fallback;
|
|
27
|
+
const parsed = Number(value);
|
|
28
|
+
return Number.isInteger(parsed) && parsed > 0 ? parsed : fallback;
|
|
29
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type Device = {
|
|
2
|
+
serial: string;
|
|
3
|
+
state: string;
|
|
4
|
+
kind: "emulator" | "device";
|
|
5
|
+
model?: string;
|
|
6
|
+
product?: string;
|
|
7
|
+
device?: string;
|
|
8
|
+
transportId?: string;
|
|
9
|
+
raw: string;
|
|
10
|
+
};
|
|
11
|
+
export declare function validSerial(serial: string): boolean;
|
|
12
|
+
export declare function listDevices(): Promise<Device[]>;
|
|
13
|
+
export declare function parseAdbDevices(value: string): Device[];
|
|
14
|
+
export declare function pickDevice(input?: {
|
|
15
|
+
serial?: string;
|
|
16
|
+
}): Promise<Device>;
|
|
17
|
+
export declare function adbShell(serial: string, args: string[], timeout?: number): Promise<import("../lib/run.js").Run>;
|
|
18
|
+
export declare function adbShellCommand(args: string[]): string;
|
|
19
|
+
export declare function isBootComplete(serial: string): Promise<boolean>;
|
|
20
|
+
//# sourceMappingURL=device.d.ts.map
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { brief, ok, run } from "../lib/run.js";
|
|
2
|
+
import { androidEnv, requireTool } from "./sdk.js";
|
|
3
|
+
const SERIAL = /^[A-Za-z0-9._:-]+$/;
|
|
4
|
+
const SAFE_DEVICE_SHELL_TOKEN = /^[A-Za-z0-9_@%+=:,./-]+$/;
|
|
5
|
+
export function validSerial(serial) {
|
|
6
|
+
return SERIAL.test(serial);
|
|
7
|
+
}
|
|
8
|
+
export async function listDevices() {
|
|
9
|
+
const adb = await requireTool("adb");
|
|
10
|
+
const out = await run([adb, "devices", "-l"], { timeout: 20_000, env: await androidEnv() });
|
|
11
|
+
if (!ok(out))
|
|
12
|
+
throw new Error(brief(out));
|
|
13
|
+
return parseAdbDevices(out.stdout);
|
|
14
|
+
}
|
|
15
|
+
export function parseAdbDevices(value) {
|
|
16
|
+
return value
|
|
17
|
+
.split(/\r?\n/)
|
|
18
|
+
.map((line) => line.trim())
|
|
19
|
+
.filter((line) => line && !line.startsWith("List of devices"))
|
|
20
|
+
.map((line) => {
|
|
21
|
+
const parts = line.split(/\s+/);
|
|
22
|
+
const serial = parts[0] ?? "";
|
|
23
|
+
const state = parts[1] ?? "unknown";
|
|
24
|
+
const attrs = new Map();
|
|
25
|
+
for (const part of parts.slice(2)) {
|
|
26
|
+
const split = part.indexOf(":");
|
|
27
|
+
if (split > 0)
|
|
28
|
+
attrs.set(part.slice(0, split), part.slice(split + 1));
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
serial,
|
|
32
|
+
state,
|
|
33
|
+
kind: serial.startsWith("emulator-") ? "emulator" : "device",
|
|
34
|
+
model: attrs.get("model"),
|
|
35
|
+
product: attrs.get("product"),
|
|
36
|
+
device: attrs.get("device"),
|
|
37
|
+
transportId: attrs.get("transport_id"),
|
|
38
|
+
raw: line,
|
|
39
|
+
};
|
|
40
|
+
})
|
|
41
|
+
.filter((item) => item.serial.length > 0);
|
|
42
|
+
}
|
|
43
|
+
export async function pickDevice(input = {}) {
|
|
44
|
+
const devices = await listDevices();
|
|
45
|
+
if (input.serial) {
|
|
46
|
+
if (!validSerial(input.serial))
|
|
47
|
+
throw new Error(`Invalid Android device serial: ${input.serial}`);
|
|
48
|
+
const hit = devices.find((item) => item.serial === input.serial);
|
|
49
|
+
if (!hit)
|
|
50
|
+
throw new Error(`Android device not found: ${input.serial}`);
|
|
51
|
+
if (hit.state !== "device")
|
|
52
|
+
throw new Error(`Android device is not ready: ${input.serial} (${hit.state})`);
|
|
53
|
+
return hit;
|
|
54
|
+
}
|
|
55
|
+
const online = devices.filter((item) => item.state === "device");
|
|
56
|
+
const emulator = online.find((item) => item.kind === "emulator");
|
|
57
|
+
if (emulator)
|
|
58
|
+
return emulator;
|
|
59
|
+
const first = online[0];
|
|
60
|
+
if (first)
|
|
61
|
+
return first;
|
|
62
|
+
throw new Error("No ready Android device or emulator found.");
|
|
63
|
+
}
|
|
64
|
+
export async function adbShell(serial, args, timeout = 30_000) {
|
|
65
|
+
if (!validSerial(serial))
|
|
66
|
+
throw new Error(`Invalid Android device serial: ${serial}`);
|
|
67
|
+
const adb = await requireTool("adb");
|
|
68
|
+
const out = await run([adb, "-s", serial, "shell", adbShellCommand(args)], {
|
|
69
|
+
timeout,
|
|
70
|
+
env: await androidEnv(),
|
|
71
|
+
});
|
|
72
|
+
if (!ok(out))
|
|
73
|
+
throw new Error(brief(out));
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
export function adbShellCommand(args) {
|
|
77
|
+
if (args.length === 0)
|
|
78
|
+
throw new Error("Missing adb shell command.");
|
|
79
|
+
return args.map(deviceShellQuote).join(" ");
|
|
80
|
+
}
|
|
81
|
+
export async function isBootComplete(serial) {
|
|
82
|
+
const out = await adbShell(serial, ["getprop", "sys.boot_completed"], 10_000).catch(() => undefined);
|
|
83
|
+
return out?.stdout.trim() === "1";
|
|
84
|
+
}
|
|
85
|
+
function deviceShellQuote(value) {
|
|
86
|
+
if (value.length === 0)
|
|
87
|
+
return "''";
|
|
88
|
+
if (SAFE_DEVICE_SHELL_TOKEN.test(value))
|
|
89
|
+
return value;
|
|
90
|
+
return `'${value.replaceAll("'", "'\\''")}'`;
|
|
91
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
type Logs = {
|
|
2
|
+
serial?: string;
|
|
3
|
+
avd?: string;
|
|
4
|
+
applicationId?: string;
|
|
5
|
+
lines?: number;
|
|
6
|
+
limit?: number;
|
|
7
|
+
};
|
|
8
|
+
export declare function logs(input?: Logs): Promise<{
|
|
9
|
+
device: import("./device.js").Device;
|
|
10
|
+
applicationId: string | undefined;
|
|
11
|
+
lines: number;
|
|
12
|
+
output: string;
|
|
13
|
+
}>;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=logs.d.ts.map
|