MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / scaffoldProject

Function scaffoldProject

packages/cli/src/commands/init.ts:518–577  ·  view source on GitHub ↗
(
  destDir: string,
  name: string,
  templateId: string,
  localVideoName: string | undefined,
  durationSeconds?: number,
  tailwind = false,
  resolution?: CanvasResolution,
)

Source from the content-addressed store, hash-verified

516// ---------------------------------------------------------------------------
517
518async function scaffoldProject(
519 destDir: string,
520 name: string,
521 templateId: string,
522 localVideoName: string | undefined,
523 durationSeconds?: number,
524 tailwind = false,
525 resolution?: CanvasResolution,
526): Promise<void> {
527 mkdirSync(destDir, { recursive: true });
528
529 // Use bundled template if available, otherwise fetch from GitHub.
530 // Check for index.html inside the dir — an empty directory left by the
531 // build toolchain should not prevent the remote fetch fallback.
532 const templateDir = getStaticTemplateDir(templateId);
533 if (existsSync(join(templateDir, "index.html"))) {
534 cpSync(templateDir, destDir, { recursive: true });
535 } else {
536 await fetchRemoteTemplate(templateId, destDir);
537 }
538 patchVideoSrc(destDir, localVideoName, durationSeconds);
539 if (tailwind) writeTailwindSupport(destDir);
540 if (resolution) applyResolutionPreset(destDir, resolution);
541
542 writeFileSync(
543 resolve(destDir, "meta.json"),
544 JSON.stringify(
545 {
546 id: name,
547 name,
548 createdAt: new Date().toISOString(),
549 },
550 null,
551 2,
552 ),
553 "utf-8",
554 );
555
556 // Write hyperframes.json so `hyperframes add` knows which registry to use
557 // and where to drop block/component files. Overwritten only if absent.
558 if (!existsSync(resolve(destDir, "hyperframes.json"))) {
559 const { writeProjectConfig, DEFAULT_PROJECT_CONFIG } =
560 await import("../utils/projectConfig.js");
561 writeProjectConfig(destDir, DEFAULT_PROJECT_CONFIG);
562 }
563
564 writeDefaultPackageJson(destDir, name);
565
566 // Copy shared files (CLAUDE.md, AGENTS.md) for AI agent context
567 const sharedDir = getSharedTemplateDir();
568 if (existsSync(sharedDir)) {
569 for (const entry of readdirSync(sharedDir, { withFileTypes: true })) {
570 const src = join(sharedDir, entry.name);
571 const dest = resolve(destDir, entry.name);
572 if (entry.isFile() || entry.isSymbolicLink()) {
573 copyFileSync(src, dest);
574 }
575 }

Callers 1

runFunction · 0.85

Calls 9

getStaticTemplateDirFunction · 0.85
fetchRemoteTemplateFunction · 0.85
patchVideoSrcFunction · 0.85
writeTailwindSupportFunction · 0.85
applyResolutionPresetFunction · 0.85
resolveFunction · 0.85
writeProjectConfigFunction · 0.85
writeDefaultPackageJsonFunction · 0.85
getSharedTemplateDirFunction · 0.85

Tested by

no test coverage detected