🎥 Make videos programmatically with React
further abstractions
Jonny Burger57ca2466b85e
diff --git a/packages/template-vercel/src/app/api/render/add-bundle-to-sandbox.ts b/packages/template-vercel/src/app/api/render/add-bundle-to-sandbox.tsnew file mode 100644index 0000000000..15dd56e700--- /dev/null+++ b/packages/template-vercel/src/app/api/render/add-bundle-to-sandbox.ts@@ -0,0 +1,30 @@+import path from "path";+import { ensureLocalBundle, getRemotionBundleFiles } from "./helpers";+import { BUILD_DIR } from "../../../../build-dir.mjs";+import { Sandbox } from "@vercel/sandbox";++export const addBundleToSandbox = async (+ sandbox: Sandbox & AsyncDisposable,+) => {+ await ensureLocalBundle();+ const bundleFiles = await getRemotionBundleFiles();++ const dirs = new Set<string>();+ for (const file of bundleFiles) {+ const dir = path.dirname(file.path);+ if (dir && dir !== ".") {+ dirs.add(dir);+ }+ }++ for (const dir of Array.from(dirs).sort()) {+ await sandbox.mkDir(BUILD_DIR + "/" + dir);+ }++ await sandbox.writeFiles(+ bundleFiles.map((file) => ({+ path: BUILD_DIR + "/" + file.path,+ content: file.content,+ })),+ );+};diff --git a/packages/template-vercel/src/app/api/render/create-sandbox.ts b/packages/template-vercel/src/app/api/render/create-sandbox.tsindex d54e0cce46..a1c5751a38 100644--- a/packages/template-vercel/src/app/api/render/create-sandbox.ts+++ b/packages/template-vercel/src/app/api/render/create-sandbox.ts@@ -1,14 +1,11 @@import { Sandbox } from "@vercel/sandbox";-import path from "path";import { VERSION } from "remotion/version";import {createDisposableSandbox,- ensureLocalBundle,getEnsureBrowserScript,- getRemotionBundleFiles,OnProgressFn,} from "./helpers";-import { BUILD_DIR } from "../../../../build-dir.mjs";+import { addBundleToSandbox } from "./add-bundle-to-sandbox";export async function createSandbox({onProgress,@@ -88,32 +85,14 @@ export async function createSandbox({);}- await onProgress({ type: "phase", phase: "Bundling video...", progress: 0 });- await ensureLocalBundle();-- // Stage 2: Copy Remotion bundle (20%)- const bundleFiles = await getRemotionBundleFiles();-- // Create the directories first- const dirs = new Set<string>();- for (const file of bundleFiles) {- const dir = path.dirname(file.path);- if (dir && dir !== ".") {- dirs.add(dir);- }- }-- for (const dir of Array.from(dirs).sort()) {- await sandbox.mkDir(BUILD_DIR + "/" + dir);- }+ await onProgress({+ type: "phase",+ phase: "Adding Remotion video to Sandbox...",+ progress: 0,+ subtitle: preparingSubtitle,+ });- // Write all files to the sandbox- await sandbox.writeFiles(- bundleFiles.map((file) => ({- path: BUILD_DIR + "/" + file.path,- content: file.content,- })),- );+ await addBundleToSandbox(sandbox);await onProgress({type: "phase",