@nickname4th/pura-cli 0.1.1 → 0.1.2
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/package.json +1 -1
- package/server/dist/adb.js +16 -1
- package/server/dist/cli.js +24 -0
package/package.json
CHANGED
package/server/dist/adb.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { execFile } from "node:child_process";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
2
5
|
import { promisify } from "node:util";
|
|
3
6
|
const execFileAsync = promisify(execFile);
|
|
4
|
-
const ADB =
|
|
7
|
+
const ADB = resolveAdbCommand();
|
|
5
8
|
const INCLUDE_TCP_DEVICES = process.env.INCLUDE_TCP_DEVICES === "true";
|
|
6
9
|
export function adbCommand(args) {
|
|
7
10
|
return {
|
|
@@ -151,6 +154,18 @@ export async function getDisplaySize(serial) {
|
|
|
151
154
|
function clamp(value, min, max) {
|
|
152
155
|
return Math.max(min, Math.min(max, value));
|
|
153
156
|
}
|
|
157
|
+
function resolveAdbCommand() {
|
|
158
|
+
if (process.env.ADB_PATH)
|
|
159
|
+
return process.env.ADB_PATH;
|
|
160
|
+
const sdkRoot = process.env.ANDROID_HOME ?? process.env.ANDROID_SDK_ROOT;
|
|
161
|
+
const candidates = [
|
|
162
|
+
sdkRoot ? path.join(sdkRoot, "platform-tools", "adb") : "",
|
|
163
|
+
path.join(os.homedir(), "Library", "Android", "sdk", "platform-tools", "adb"),
|
|
164
|
+
"/opt/homebrew/bin/adb",
|
|
165
|
+
"/usr/local/bin/adb"
|
|
166
|
+
].filter(Boolean);
|
|
167
|
+
return candidates.find((candidate) => fs.existsSync(candidate)) ?? "adb";
|
|
168
|
+
}
|
|
154
169
|
const keyEvents = {
|
|
155
170
|
back: "KEYCODE_BACK",
|
|
156
171
|
home: "KEYCODE_HOME",
|
package/server/dist/cli.js
CHANGED
|
@@ -204,6 +204,16 @@ function printLaunchAgentStatus() {
|
|
|
204
204
|
}
|
|
205
205
|
}
|
|
206
206
|
function makeLaunchAgentPlist(nodePath, cliPath) {
|
|
207
|
+
const environment = {
|
|
208
|
+
PATH: process.env.PATH,
|
|
209
|
+
ANDROID_HOME: process.env.ANDROID_HOME,
|
|
210
|
+
ANDROID_SDK_ROOT: process.env.ANDROID_SDK_ROOT,
|
|
211
|
+
ADB_PATH: findExecutable("adb")
|
|
212
|
+
};
|
|
213
|
+
const environmentEntries = Object.entries(environment)
|
|
214
|
+
.filter((entry) => Boolean(entry[1]))
|
|
215
|
+
.map(([key, value]) => ` <key>${escapeXml(key)}</key>\n <string>${escapeXml(value)}</string>`)
|
|
216
|
+
.join("\n");
|
|
207
217
|
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
208
218
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
209
219
|
<plist version="1.0">
|
|
@@ -220,6 +230,10 @@ function makeLaunchAgentPlist(nodePath, cliPath) {
|
|
|
220
230
|
<true/>
|
|
221
231
|
<key>KeepAlive</key>
|
|
222
232
|
<true/>
|
|
233
|
+
<key>EnvironmentVariables</key>
|
|
234
|
+
<dict>
|
|
235
|
+
${environmentEntries}
|
|
236
|
+
</dict>
|
|
223
237
|
<key>StandardOutPath</key>
|
|
224
238
|
<string>${escapeXml(path.join(os.homedir(), "Library", "Logs", "pura-agent.log"))}</string>
|
|
225
239
|
<key>StandardErrorPath</key>
|
|
@@ -256,6 +270,16 @@ function resolveAgentDataDir(value) {
|
|
|
256
270
|
return path.join(os.homedir(), ".pura", "agent-data");
|
|
257
271
|
return path.isAbsolute(value) ? value : path.resolve(value);
|
|
258
272
|
}
|
|
273
|
+
function findExecutable(name) {
|
|
274
|
+
for (const directory of (process.env.PATH ?? "").split(path.delimiter)) {
|
|
275
|
+
if (!directory)
|
|
276
|
+
continue;
|
|
277
|
+
const candidate = path.join(directory, name);
|
|
278
|
+
if (fs.existsSync(candidate))
|
|
279
|
+
return candidate;
|
|
280
|
+
}
|
|
281
|
+
return undefined;
|
|
282
|
+
}
|
|
259
283
|
function startServer(env) {
|
|
260
284
|
const child = spawn(process.execPath, [new URL("./index.js", import.meta.url).pathname], {
|
|
261
285
|
stdio: "inherit",
|