mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-24 16:06:34 +00:00
fix(producer): resolve runtime manifest in bundled builds + wrap sub-compositions
- Add dist-sibling path to manifest resolver (fixes "Missing manifest" when running from bundled public-server.js) - Add wrapSubCompositionAsStandalone: when entryFile is a <template>-based sub-composition, creates a standalone HTML document with GSAP + runtime so it can render independently - Extract TARGET_DURATION from composition scripts for data-duration Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
fea504a41f
commit
55beb9a56d
@@ -10,6 +10,10 @@ const MODULE_RELATIVE_MANIFEST_PATH = resolve(
|
||||
"../../../core/dist/hyperframe.manifest.json",
|
||||
);
|
||||
const CWD_RELATIVE_MANIFEST_PATHS = [
|
||||
// When bundled to a single file (dist/public-server.js), the manifest
|
||||
// is copied as a sibling by build.mjs
|
||||
resolve(PRODUCER_DIR, "hyperframe.manifest.json"),
|
||||
resolve(process.cwd(), "packages/core/dist/hyperframe.manifest.json"),
|
||||
resolve(process.cwd(), "../core/dist/hyperframe.manifest.json"),
|
||||
resolve(process.cwd(), "core/dist/hyperframe.manifest.json"),
|
||||
];
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* full context, and failures produce a diagnostic summary.
|
||||
*/
|
||||
|
||||
import { existsSync, mkdirSync, rmSync, writeFileSync, copyFileSync, appendFileSync } from "fs";
|
||||
import { existsSync, mkdirSync, rmSync, readFileSync, writeFileSync, copyFileSync, appendFileSync } from "fs";
|
||||
import {
|
||||
type EngineConfig,
|
||||
resolveConfig,
|
||||
@@ -277,6 +277,54 @@ export function createRenderJob(config: RenderConfig): RenderJob {
|
||||
/**
|
||||
* Main render pipeline
|
||||
*/
|
||||
/**
|
||||
* Wraps a <template>-based sub-composition into a standalone HTML document
|
||||
* that can be rendered independently by the producer.
|
||||
*/
|
||||
function wrapSubCompositionAsStandalone(templateHtml: string, compositionId: string, _srcPath: string): string {
|
||||
// Extract the inner content from the <template> wrapper
|
||||
const templateMatch = templateHtml.match(/<template[^>]*>([\s\S]*)<\/template>/i);
|
||||
const inner = templateMatch?.[1]?.trim() ?? templateHtml;
|
||||
|
||||
// Extract <script> blocks from the inner content
|
||||
const scripts: string[] = [];
|
||||
const withoutScripts = inner.replace(/<script\b[^>]*>([\s\S]*?)<\/script>/gi, (match) => {
|
||||
scripts.push(match);
|
||||
return "";
|
||||
});
|
||||
|
||||
// Find data-width and data-height from the composition root
|
||||
const widthMatch = inner.match(/data-width="(\d+)"/);
|
||||
const heightMatch = inner.match(/data-height="(\d+)"/);
|
||||
const width = widthMatch ? widthMatch[1] : "1920";
|
||||
const height = heightMatch ? heightMatch[1] : "1080";
|
||||
|
||||
// Try to extract TARGET_DURATION from the script for accurate duration
|
||||
const durationMatch = inner.match(/TARGET_DURATION\s*=\s*(\d+(?:\.\d+)?)/);
|
||||
const dataDuration = durationMatch ? ` data-duration="${durationMatch[1]}"` : "";
|
||||
|
||||
return `<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
body { background: #000; overflow: hidden; width: ${width}px; height: ${height}px; }
|
||||
</style>
|
||||
<script src="https://cdn.jsdelivr.net/npm/gsap@3.12.7/dist/gsap.min.js"><\/script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="main-comp" data-composition-id="${compositionId}" data-start="0"${dataDuration} data-width="${width}" data-height="${height}" style="position:relative;width:${width}px;height:${height}px;overflow:hidden;">
|
||||
${withoutScripts}
|
||||
<script>
|
||||
window.__timelines = window.__timelines || {};
|
||||
${scripts.map((s) => s.replace(/<\/?script[^>]*>/gi, "")).join("\n")}
|
||||
<\/script>
|
||||
</div>
|
||||
</body>
|
||||
</html>`;
|
||||
}
|
||||
|
||||
export async function executeRenderJob(
|
||||
job: RenderJob,
|
||||
projectDir: string,
|
||||
@@ -322,12 +370,24 @@ export async function executeRenderJob(
|
||||
}
|
||||
|
||||
const entryFile = job.config.entryFile || "index.html";
|
||||
const htmlPath = join(projectDir, entryFile);
|
||||
let htmlPath = join(projectDir, entryFile);
|
||||
if (!existsSync(htmlPath)) {
|
||||
throw new Error(`Entry file not found: ${htmlPath}`);
|
||||
}
|
||||
assertNotAborted();
|
||||
|
||||
// If entryFile is a sub-composition (<template> wrapper), create a
|
||||
// standalone index.html that embeds it so it can render independently.
|
||||
const rawEntry = readFileSync(htmlPath, "utf-8");
|
||||
if (entryFile !== "index.html" && rawEntry.trimStart().startsWith("<template")) {
|
||||
const wrapperPath = join(workDir, "standalone-entry.html");
|
||||
const compositionId = entryFile.replace(/^compositions\//, "").replace(/\.html$/, "");
|
||||
const standaloneHtml = wrapSubCompositionAsStandalone(rawEntry, compositionId, entryFile);
|
||||
writeFileSync(wrapperPath, standaloneHtml, "utf-8");
|
||||
htmlPath = wrapperPath;
|
||||
log.info("Wrapped sub-composition as standalone document", { entryFile, compositionId });
|
||||
}
|
||||
|
||||
// ── Stage 1: Compile ─────────────────────────────────────────────────
|
||||
const stage1Start = Date.now();
|
||||
updateJobStatus(job, "preprocessing", "Compiling composition", 5, onProgress);
|
||||
|
||||
Reference in New Issue
Block a user