mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-15 22:08:03 +00:00
refactor: address review feedback on template path rename
- Fix stale docstring in `fetchRemoteTemplate`: said "examples/<id>" after the rename, actual path is "registry/examples/<id>" - Add regression test pinning TEMPLATES_DIR and MANIFEST_FILENAME so accidentally reverting either constant fails a test instead of silently breaking init for every installed CLI - Export the two constants from remote.ts for test visibility (no public API change — internal module only) - Add a clarifying comment on getStaticTemplateDir / getSharedTemplateDir in init.ts noting these resolve to the CLI's bundled templates dir, not the newly-relocated registry/examples/ dir fetched remotely. Prevents future-reader confusion now that root templates/ is gone No behavior change. 2 new tests, 57 CLI tests passing (was 55, +2). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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/<id> in dev, dist/templates/<id> 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]);
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
});
|
||||
});
|
||||
@@ -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<RemoteTemplateInfo[]> {
|
||||
|
||||
/**
|
||||
* Download a template from GitHub into destDir using giget.
|
||||
* Fetches from `examples/<templateId>` in the hyperframes repo.
|
||||
* Fetches from `registry/examples/<templateId>` in the hyperframes repo.
|
||||
*/
|
||||
export async function fetchRemoteTemplate(
|
||||
templateId: string,
|
||||
|
||||
Reference in New Issue
Block a user