mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 19:40:43 +00:00
76 lines
2.0 KiB
TypeScript
76 lines
2.0 KiB
TypeScript
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { resolveOpenClawPackageRoot } from "../infra/openclaw-root.js";
|
|
|
|
export const OPENCLAW_DOCS_URL = "https://docs.openclaw.ai";
|
|
export const OPENCLAW_SOURCE_URL = "https://github.com/openclaw/openclaw";
|
|
|
|
type ResolveOpenClawReferencePathParams = {
|
|
workspaceDir?: string;
|
|
argv1?: string;
|
|
cwd?: string;
|
|
moduleUrl?: string;
|
|
};
|
|
|
|
function isUsableDocsDir(docsDir: string): boolean {
|
|
return fs.existsSync(path.join(docsDir, "docs.json"));
|
|
}
|
|
|
|
function isGitCheckout(rootDir: string): boolean {
|
|
return fs.existsSync(path.join(rootDir, ".git"));
|
|
}
|
|
|
|
export async function resolveOpenClawDocsPath(params: {
|
|
workspaceDir?: string;
|
|
argv1?: string;
|
|
cwd?: string;
|
|
moduleUrl?: string;
|
|
}): Promise<string | null> {
|
|
const workspaceDir = params.workspaceDir?.trim();
|
|
if (workspaceDir) {
|
|
const workspaceDocs = path.join(workspaceDir, "docs");
|
|
if (isUsableDocsDir(workspaceDocs)) {
|
|
return workspaceDocs;
|
|
}
|
|
}
|
|
|
|
const packageRoot = await resolveOpenClawPackageRoot({
|
|
cwd: params.cwd,
|
|
argv1: params.argv1,
|
|
moduleUrl: params.moduleUrl,
|
|
});
|
|
if (!packageRoot) {
|
|
return null;
|
|
}
|
|
|
|
const packageDocs = path.join(packageRoot, "docs");
|
|
return isUsableDocsDir(packageDocs) ? packageDocs : null;
|
|
}
|
|
|
|
export async function resolveOpenClawSourcePath(
|
|
params: ResolveOpenClawReferencePathParams,
|
|
): Promise<string | null> {
|
|
const packageRoot = await resolveOpenClawPackageRoot({
|
|
cwd: params.cwd,
|
|
argv1: params.argv1,
|
|
moduleUrl: params.moduleUrl,
|
|
});
|
|
if (!packageRoot || !isGitCheckout(packageRoot)) {
|
|
return null;
|
|
}
|
|
return packageRoot;
|
|
}
|
|
|
|
export async function resolveOpenClawReferencePaths(
|
|
params: ResolveOpenClawReferencePathParams,
|
|
): Promise<{
|
|
docsPath: string | null;
|
|
sourcePath: string | null;
|
|
}> {
|
|
const [docsPath, sourcePath] = await Promise.all([
|
|
resolveOpenClawDocsPath(params),
|
|
resolveOpenClawSourcePath(params),
|
|
]);
|
|
return { docsPath, sourcePath };
|
|
}
|