openclaw/scripts/lib/mobile-version.ts
Peter Steinberger 9491d5a5a3
refactor(scripts): deslop scripts/lib (#159362)
* refactor(scripts): deslop scripts/lib

Consolidate script lifecycle, scenario, planner, report, release and
packaging helpers while retaining CLI and publication contracts.

Keep config-boundary source caches within one scan so repeated in-process
checks observe edits. Carry extracted helpers through selective fixtures
and iOS scope routing. Leave PR tooling and its library import closure intact.

* fix(scripts): retain sanitizer fast path after helper cleanup

* fix(scripts): model watchdog shell consumer in dead-code checks
2026-09-27 17:13:58 -07:00

28 lines
1 KiB
TypeScript

import { readFileSync } from "node:fs";
import path from "node:path";
import { parseReleaseVersion } from "./release-version.mjs";
export function normalizeGatewayVersionToPinnedMobileVersion(rawVersion: string): string {
const trimmed = rawVersion.trim().replace(/^v/u, "");
if (!trimmed) {
throw new Error("Missing root package.json version.");
}
const parsed = parseReleaseVersion(trimmed);
if (!parsed) {
throw new Error(
`Invalid gateway version '${rawVersion}'. Expected YYYY.M.PATCH, YYYY.M.PATCH-alpha.N, YYYY.M.PATCH-beta.N, or YYYY.M.PATCH-N.`,
);
}
return parsed.baseVersion;
}
export function readRootPackageVersion(rootDir: string): string {
const packageJsonPath = path.join(rootDir, "package.json");
const parsed = JSON.parse(readFileSync(packageJsonPath, "utf8")) as { version?: unknown };
const version = typeof parsed.version === "string" ? parsed.version.trim() : "";
if (!version) {
throw new Error(`Missing package.json version in ${packageJsonPath}.`);
}
return version;
}