🎥 Make videos programmatically with React
i think it's fire! :fire:
Jonny Burger5f21aeeff580
diff --git a/packages/lambda/.gitignore b/packages/lambda/.gitignorenew file mode 100644index 0000000000..b65d843069--- /dev/null+++ b/packages/lambda/.gitignore@@ -0,0 +1,3 @@+build+node_modules+function.zipdiff --git a/packages/lambda/package-lock.json b/packages/lambda/package-lock.jsonindex e89536085f..2e8eaac75a 100644--- a/packages/lambda/package-lock.json+++ b/packages/lambda/package-lock.json@@ -2804,9 +2804,9 @@}},"esbuild": {- "version": "0.10.2",- "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.10.2.tgz",- "integrity": "sha512-/5vsZD7wTJJHC3yNXLUjXNvUDwqwNoIMvFvLd9tcDQ9el5l13pspYm3yufavjIeYvNtAbo+6N/6uoWx9dGA6ug=="+ "version": "0.11.12",+ "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.11.12.tgz",+ "integrity": "sha512-c8cso/1RwVj+fbDvLtUgSG4ZJQ0y9Zdrl6Ot/GAjyy4pdMCHaFnDMts5gqFnWRPLajWtEnI+3hlET4R9fVoZng=="},"esbuild-loader": {"version": "2.12.0",@@ -2826,6 +2826,11 @@"resolved": "https://registry.npmjs.org/emojis-list/-/emojis-list-3.0.0.tgz","integrity": "sha512-/kyM18EfinwXZbno9FyUGeFh87KC8HRQBQGildHZbEuRyWFOmv1U10o9BBp8XVZDVNNuQKyIGIu5ZYAAXJ0V2Q=="},+ "esbuild": {+ "version": "0.10.2",+ "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.10.2.tgz",+ "integrity": "sha512-/5vsZD7wTJJHC3yNXLUjXNvUDwqwNoIMvFvLd9tcDQ9el5l13pspYm3yufavjIeYvNtAbo+6N/6uoWx9dGA6ug=="+ },"json5": {"version": "2.2.0","resolved": "https://registry.npmjs.org/json5/-/json5-2.2.0.tgz",diff --git a/packages/lambda/package.json b/packages/lambda/package.jsonindex 04641e2ea5..21730e034e 100644--- a/packages/lambda/package.json+++ b/packages/lambda/package.json@@ -19,8 +19,10 @@"@aws-sdk/client-s3": "^3.13.0","@remotion/bundler": "^2.0.2","@remotion/renderer": "^2.0.2",+ "esbuild": "^0.11.12","remotion": "^2.0.2","ts-node": "^9.1.1",+ "xns": "^2.0.7","zip-lib": "^0.7.2"},"peerDependencies": {diff --git a/packages/lambda/remotion-project/index.ts b/packages/lambda/remotion-project/index.tsindex e69de29bb2..d831f7b0f1 100644--- a/packages/lambda/remotion-project/index.ts+++ b/packages/lambda/remotion-project/index.ts@@ -0,0 +1,4 @@+import {registerRoot} from 'remotion';+import {RemotionRoot} from './Root';++registerRoot(RemotionRoot);diff --git a/packages/lambda/src/bundle-lambda.ts b/packages/lambda/src/bundle-lambda.tsindex 2d162c6ad5..59273e77d2 100644--- a/packages/lambda/src/bundle-lambda.ts+++ b/packages/lambda/src/bundle-lambda.ts@@ -1,9 +1,22 @@+import fs from 'fs';import path from 'path';+import esbuild = require('esbuild');import zl = require('zip-lib');-export const bundleLambda = () => {- return zl.archiveFolder(- path.join(__dirname, '..', 'template'),- 'function.zip'- );+export const bundleLambda = async () => {+ const outdir = path.join(__dirname, '..', 'build');+ fs.mkdirSync(outdir, {+ recursive: true,+ });+ const outfile = path.join(outdir, 'index.js');+ const template = path.join(__dirname, '..', 'template', 'render.ts');++ await esbuild.build({+ platform: 'node',+ bundle: true,+ outfile,+ entryPoints: [template],+ });++ return zl.archiveFolder(outdir, 'function.zip');};diff --git a/packages/lambda/src/bundle-remotion.ts b/packages/lambda/src/bundle-remotion.tsnew file mode 100644index 0000000000..79d35f1c02--- /dev/null+++ b/packages/lambda/src/bundle-remotion.ts@@ -0,0 +1,6 @@+import {bundle} from '@remotion/bundler';+import path from 'path';++export const bundleRemotion = () => {+ return bundle(path.join(__dirname, '..', 'remotion-project', 'index.ts'));+};diff --git a/packages/lambda/src/create-lambda.ts b/packages/lambda/src/create-lambda.tsindex 619ff7353f..4a07751e17 100644--- a/packages/lambda/src/create-lambda.ts+++ b/packages/lambda/src/create-lambda.ts@@ -1,5 +1,7 @@import {CreateFunctionCommand, LambdaClient} from '@aws-sdk/client-lambda';+import xns from 'xns';import {bundleLambda} from './bundle-lambda';+import {bundleRemotion} from './bundle-remotion';const client = new LambdaClient({region: 'eu-central-1',@@ -19,7 +21,8 @@ const params = {Description: 'Renders a Remotion video.',};-const run = async () => {+xns(async () => {+ await bundleRemotion();await bundleLambda();try {const data = await client.send(new CreateFunctionCommand(params));@@ -27,6 +30,4 @@ const run = async () => {} catch (err) {console.log('Error', err); // an error occurred}-};--run();+});diff --git a/packages/lambda/template/render.ts b/packages/lambda/template/render.tsnew file mode 100644index 0000000000..c2bc95f88b--- /dev/null+++ b/packages/lambda/template/render.ts@@ -0,0 +1,5 @@+import {isHomebrewInstalled} from '@remotion/renderer';++export const handler = async (event, context, callback) => {+ console.log('Remotion is running', await isHomebrewInstalled());+};