mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-03 03:03:24 -04:00
refactor: reuse runtime requires evaluation
This commit is contained in:
@@ -41,6 +41,68 @@ export function isConfigPathTruthyWithDefaults(
|
||||
return isTruthy(value);
|
||||
}
|
||||
|
||||
export type RuntimeRequires = {
|
||||
bins?: string[];
|
||||
anyBins?: string[];
|
||||
env?: string[];
|
||||
config?: string[];
|
||||
};
|
||||
|
||||
export function evaluateRuntimeRequires(params: {
|
||||
requires?: RuntimeRequires;
|
||||
hasBin: (bin: string) => boolean;
|
||||
hasAnyRemoteBin?: (bins: string[]) => boolean;
|
||||
hasRemoteBin?: (bin: string) => boolean;
|
||||
hasEnv: (envName: string) => boolean;
|
||||
isConfigPathTruthy: (pathStr: string) => boolean;
|
||||
}): boolean {
|
||||
const requires = params.requires;
|
||||
if (!requires) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const requiredBins = requires.bins ?? [];
|
||||
if (requiredBins.length > 0) {
|
||||
for (const bin of requiredBins) {
|
||||
if (params.hasBin(bin)) {
|
||||
continue;
|
||||
}
|
||||
if (params.hasRemoteBin?.(bin)) {
|
||||
continue;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const requiredAnyBins = requires.anyBins ?? [];
|
||||
if (requiredAnyBins.length > 0) {
|
||||
const anyFound = requiredAnyBins.some((bin) => params.hasBin(bin));
|
||||
if (!anyFound && !params.hasAnyRemoteBin?.(requiredAnyBins)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const requiredEnv = requires.env ?? [];
|
||||
if (requiredEnv.length > 0) {
|
||||
for (const envName of requiredEnv) {
|
||||
if (!params.hasEnv(envName)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const requiredConfig = requires.config ?? [];
|
||||
if (requiredConfig.length > 0) {
|
||||
for (const configPath of requiredConfig) {
|
||||
if (!params.isConfigPathTruthy(configPath)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
export function resolveRuntimePlatform(): string {
|
||||
return process.platform;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user