diff --git a/packages/cli/src/commands/init.ts b/packages/cli/src/commands/init.ts index 89002311da..1b02f4086d 100644 --- a/packages/cli/src/commands/init.ts +++ b/packages/cli/src/commands/init.ts @@ -156,6 +156,10 @@ function resolveAssetDir(devSegments: string[], builtSegments: string[]): string return existsSync(devPath) ? devPath : builtPath; } +// Resolves bundled templates shipped inside the CLI package +// (packages/cli/src/templates/ in dev, dist/templates/ when packed). +// Not to be confused with the repo-root registry/examples/ directory, which +// is fetched remotely via fetchRemoteTemplate. function getStaticTemplateDir(templateId: string): string { return resolveAssetDir(["..", "templates", templateId], ["templates", templateId]); } diff --git a/packages/cli/src/templates/remote.test.ts b/packages/cli/src/templates/remote.test.ts new file mode 100644 index 0000000000..9eed1d50bb --- /dev/null +++ b/packages/cli/src/templates/remote.test.ts @@ -0,0 +1,15 @@ +import { describe, expect, it } from "vitest"; +import { MANIFEST_FILENAME, TEMPLATES_DIR } from "./remote.js"; + +// These constants construct the GitHub URL that installed CLIs use to fetch +// remote examples. Accidentally reverting either value silently breaks init +// for every user. Pin them explicitly. +describe("remote template path constants", () => { + it("TEMPLATES_DIR points to registry/examples", () => { + expect(TEMPLATES_DIR).toBe("registry/examples"); + }); + + it("MANIFEST_FILENAME is templates.json (renamed to registry.json in PR 3)", () => { + expect(MANIFEST_FILENAME).toBe("templates.json"); + }); +}); diff --git a/packages/cli/src/templates/remote.ts b/packages/cli/src/templates/remote.ts index d1d7ac0b83..278383899a 100644 --- a/packages/cli/src/templates/remote.ts +++ b/packages/cli/src/templates/remote.ts @@ -10,8 +10,9 @@ import { join } from "node:path"; import { homedir } from "node:os"; const REPO = "heygen-com/hyperframes"; -const TEMPLATES_DIR = "registry/examples"; -const MANIFEST_FILENAME = "templates.json"; +// Exported for regression testing — see remote.test.ts. +export const TEMPLATES_DIR = "registry/examples"; +export const MANIFEST_FILENAME = "templates.json"; /** Cache directory for remote template metadata. */ const CACHE_DIR = join(homedir(), ".hyperframes", "cache"); @@ -71,7 +72,7 @@ export async function listRemoteTemplates(): Promise { /** * Download a template from GitHub into destDir using giget. - * Fetches from `examples/` in the hyperframes repo. + * Fetches from `registry/examples/` in the hyperframes repo. */ export async function fetchRemoteTemplate( templateId: string,