File size: 1,354 Bytes
901eb55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Android Version script supports OpenClaw repository automation.
import { resolveAndroidVersion } from "./lib/android-version.ts";
import { parseVersionQueryArgs } from "./lib/version-script-args.ts";

function printUsage(): void {
  process.stdout.write(
    "Usage: node --import tsx scripts/android-version.ts [--json|--shell] [--field name] [--root dir]\n\n",
  );
}

function main(argv = process.argv.slice(2)): number {
  const options = parseVersionQueryArgs(argv);
  if (options.help) {
    printUsage();
    return 0;
  }

  const version = resolveAndroidVersion(options.rootDir);

  if (options.field) {
    const value = version[options.field as keyof typeof version];
    if (value === undefined) {
      throw new Error(`Unknown Android version field '${options.field}'.`);
    }
    process.stdout.write(`${value}\n`);
    return 0;
  }

  if (options.format === "shell") {
    process.stdout.write(
      [
        `OPENCLAW_ANDROID_VERSION_NAME=${version.canonicalVersion}`,
        `OPENCLAW_ANDROID_VERSION_CODE=${version.versionCode}`,
      ].join("\n") + "\n",
    );
  } else {
    process.stdout.write(`${JSON.stringify(version, null, 2)}\n`);
  }
  return 0;
}

try {
  process.exitCode = main();
} catch (error) {
  process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
  process.exitCode = 1;
}