Publish the hub as pi-mobile-hub with CLI flags and LAN pairing auth, add mobile deep-link pairing and EAS build config, and expand gitignore for Expo/EAS artifacts. Co-authored-by: Cursor <cursoragent@cursor.com>
95 lines
2.0 KiB
TypeScript
95 lines
2.0 KiB
TypeScript
import { readFileSync } from "node:fs";
|
|
import { dirname, join } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
export type CliOptions = {
|
|
port: number;
|
|
noAuth: boolean;
|
|
help: boolean;
|
|
version: boolean;
|
|
};
|
|
|
|
const DEFAULT_PORT = 8787;
|
|
|
|
function getPackageVersion(): string {
|
|
try {
|
|
const dir = dirname(fileURLToPath(import.meta.url));
|
|
const packageJsonPath = join(dir, "..", "package.json");
|
|
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8")) as { version?: string };
|
|
return packageJson.version ?? "0.0.0";
|
|
} catch {
|
|
return "0.0.0";
|
|
}
|
|
}
|
|
|
|
export function parseCliArgs(argv: string[]): CliOptions {
|
|
let port = Number(process.env.PORT);
|
|
if (Number.isNaN(port)) {
|
|
port = DEFAULT_PORT;
|
|
}
|
|
|
|
let noAuth = false;
|
|
let help = false;
|
|
let version = false;
|
|
|
|
for (let index = 0; index < argv.length; index += 1) {
|
|
const arg = argv[index];
|
|
|
|
if (arg === "--help" || arg === "-h") {
|
|
help = true;
|
|
continue;
|
|
}
|
|
|
|
if (arg === "--version" || arg === "-v") {
|
|
version = true;
|
|
continue;
|
|
}
|
|
|
|
if (arg === "--no-auth") {
|
|
noAuth = true;
|
|
continue;
|
|
}
|
|
|
|
if (arg === "--port" || arg === "-p") {
|
|
const value = Number(argv[index + 1]);
|
|
if (!Number.isNaN(value)) {
|
|
port = value;
|
|
index += 1;
|
|
}
|
|
continue;
|
|
}
|
|
|
|
if (arg.startsWith("--port=")) {
|
|
const value = Number(arg.slice("--port=".length));
|
|
if (!Number.isNaN(value)) {
|
|
port = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
return { port, noAuth, help, version };
|
|
}
|
|
|
|
export function printHelp(): void {
|
|
console.log(`pi-mobile-hub — Pi Mobile API hub
|
|
|
|
Usage:
|
|
pi-mobile-hub [options]
|
|
|
|
Options:
|
|
-p, --port <number> Port to listen on (default: 8787)
|
|
--no-auth Disable pairing token requirement
|
|
-h, --help Show this help message
|
|
-v, --version Show version number
|
|
|
|
Examples:
|
|
npx pi-mobile-hub
|
|
npx pi-mobile-hub --port 9000
|
|
npx pi-mobile-hub --no-auth
|
|
`);
|
|
}
|
|
|
|
export function printVersion(): void {
|
|
console.log(getPackageVersion());
|
|
}
|