mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-03 13:22:14 +00:00
25 lines
735 B
TypeScript
25 lines
735 B
TypeScript
import fs from "node:fs/promises";
|
|
import path from "node:path";
|
|
|
|
export async function readPackageVersion(root: string): Promise<string | null> {
|
|
try {
|
|
const raw = await fs.readFile(path.join(root, "package.json"), "utf-8");
|
|
const parsed = JSON.parse(raw) as { version?: string };
|
|
const version = parsed?.version?.trim();
|
|
return version ? version : null;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export async function readPackageName(root: string): Promise<string | null> {
|
|
try {
|
|
const raw = await fs.readFile(path.join(root, "package.json"), "utf-8");
|
|
const parsed = JSON.parse(raw) as { name?: string };
|
|
const name = parsed?.name?.trim();
|
|
return name ? name : null;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|