mirror of
https://github.com/hanzoai/bot.git
synced 2026-10-30 17:24:26 +00:00
The big rebrand left a residue of HanzoBot* identifiers inside camelCase compounds (resolveHanzoBotAgentDir, HanzoBotPackageRoot, hanzoBotRoot, HanzoBotTmpDir, …) that the canonical bot-root.ts / tmp-bot-dir.ts had always exported as Bot* / bot*. The earlier \b-anchored sweep missed them because the H is mid-identifier with no word boundary. Replace HanzoBot(?=[A-Z][a-z]) → Bot (and hanzoBot equivalent) everywhere, plus HanzoBotKit → BotKit (the on-disk module is apps/shared/BotKit). Also one stray pi-tools.ts type narrowing (senderId is string|null but the target wants string|undefined) — coerce with ?? undefined. pnpm build → ✔ Build complete in 7s.
60 lines
1.6 KiB
TypeScript
60 lines
1.6 KiB
TypeScript
import path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import { resolveBotPackageRoot } from "../infra/bot-root.js";
|
|
import { pathExists } from "../utils.js";
|
|
|
|
const FALLBACK_TEMPLATE_DIR = path.resolve(
|
|
path.dirname(fileURLToPath(import.meta.url)),
|
|
"../../docs/reference/templates",
|
|
);
|
|
|
|
let cachedTemplateDir: string | undefined;
|
|
let resolvingTemplateDir: Promise<string> | undefined;
|
|
|
|
export async function resolveWorkspaceTemplateDir(opts?: {
|
|
cwd?: string;
|
|
argv1?: string;
|
|
moduleUrl?: string;
|
|
}): Promise<string> {
|
|
if (cachedTemplateDir) {
|
|
return cachedTemplateDir;
|
|
}
|
|
if (resolvingTemplateDir) {
|
|
return resolvingTemplateDir;
|
|
}
|
|
|
|
resolvingTemplateDir = (async () => {
|
|
const moduleUrl = opts?.moduleUrl ?? import.meta.url;
|
|
const argv1 = opts?.argv1 ?? process.argv[1];
|
|
const cwd = opts?.cwd ?? process.cwd();
|
|
|
|
const packageRoot = await resolveBotPackageRoot({ moduleUrl, argv1, cwd });
|
|
const candidates = [
|
|
packageRoot ? path.join(packageRoot, "docs", "reference", "templates") : null,
|
|
cwd ? path.resolve(cwd, "docs", "reference", "templates") : null,
|
|
FALLBACK_TEMPLATE_DIR,
|
|
].filter(Boolean) as string[];
|
|
|
|
for (const candidate of candidates) {
|
|
if (await pathExists(candidate)) {
|
|
cachedTemplateDir = candidate;
|
|
return candidate;
|
|
}
|
|
}
|
|
|
|
cachedTemplateDir = candidates[0] ?? FALLBACK_TEMPLATE_DIR;
|
|
return cachedTemplateDir;
|
|
})();
|
|
|
|
try {
|
|
return await resolvingTemplateDir;
|
|
} finally {
|
|
resolvingTemplateDir = undefined;
|
|
}
|
|
}
|
|
|
|
export function resetWorkspaceTemplateDirCache() {
|
|
cachedTemplateDir = undefined;
|
|
resolvingTemplateDir = undefined;
|
|
}
|