Skip to content

🎥 Make videos programmatically with React

fix some formatting

Jonny Burgerc5cb936d53bd
diff --git a/packages/cloudrun/src/api/upload-dir.ts b/packages/cloudrun/src/api/upload-dir.ts
index c71f3c0aba..8f48ceb2d5 100644
--- a/packages/cloudrun/src/api/upload-dir.ts
+++ b/packages/cloudrun/src/api/upload-dir.ts
@@ -40,12 +40,6 @@ export const uploadDir = async ({
onProgress: (progress: UploadDirProgress) => void;
toUpload: string[];
}) => {
- const files = await getFiles(localDir, localDir, toUpload);
- const progresses: {[key: string]: number} = {};
- for (const file of files) {
- progresses[file.name] = 0;
- }
-
async function getFiles(
directory: string,
originalDirectory: string,
@@ -85,6 +79,12 @@ export const uploadDir = async ({
return _files.flat(1);
}
+ const files = await getFiles(localDir, localDir, toUpload);
+ const progresses: {[key: string]: number} = {};
+ for (const file of files) {
+ progresses[file.name] = 0;
+ }
+
const cloudStorageClient = getCloudStorageClient();
const uploads = files.map((file) => {
diff --git a/packages/create-video/src/degit.ts b/packages/create-video/src/degit.ts
index 6b5de968dc..910efedf88 100644
--- a/packages/create-video/src/degit.ts
+++ b/packages/create-video/src/degit.ts
@@ -31,6 +31,17 @@ export function fetch(url: string, dest: string) {
});
}
+function untar(file: string, dest: string) {
+ return tar.extract(
+ {
+ file,
+ strip: 1,
+ C: dest,
+ },
+ [],
+ );
+}
+
export const degit = async ({
repoOrg,
repoName,
@@ -52,14 +63,3 @@ export const degit = async ({
await untar(file, dest);
fs.unlinkSync(file);
};
-
-function untar(file: string, dest: string) {
- return tar.extract(
- {
- file,
- strip: 1,
- C: dest,
- },
- [],
- );
-}
diff --git a/packages/create-video/src/pkg-managers.ts b/packages/create-video/src/pkg-managers.ts
index 991c23a6ea..9580633336 100644
--- a/packages/create-video/src/pkg-managers.ts
+++ b/packages/create-video/src/pkg-managers.ts
@@ -73,29 +73,6 @@ export const getInstallCommand = (manager: PackageManager) => {
}
};
-export const getDevCommand = (manager: PackageManager, template: Template) => {
- if (template.cliId === 'remix' || template.cliId === 'next') {
- return `${getRunCommand(manager)} dev`;
- }
-
- return getStartCommand(manager);
-};
-
-export const getRenderCommandForTemplate = (
- manager: PackageManager,
- template: Template,
-) => {
- if (template.cliId === 'remix') {
- return `${getRunCommand(manager)} remotion:render`;
- }
-
- if (template.cliId === 'still') {
- return `${getRunCommand(manager)} render`;
- }
-
- return getRenderCommand(manager);
-};
-
const getStartCommand = (manager: PackageManager) => {
if (manager === 'npm') {
return `npm start`;
@@ -152,6 +129,29 @@ export const getRunCommand = (manager: PackageManager) => {
throw new TypeError('unknown package manager');
};
+export const getDevCommand = (manager: PackageManager, template: Template) => {
+ if (template.cliId === 'remix' || template.cliId === 'next') {
+ return `${getRunCommand(manager)} dev`;
+ }
+
+ return getStartCommand(manager);
+};
+
+export const getRenderCommandForTemplate = (
+ manager: PackageManager,
+ template: Template,
+) => {
+ if (template.cliId === 'remix') {
+ return `${getRunCommand(manager)} remotion:render`;
+ }
+
+ if (template.cliId === 'still') {
+ return `${getRunCommand(manager)} render`;
+ }
+
+ return getRenderCommand(manager);
+};
+
export const getPackageManagerVersion = (
manager: PackageManager,
): Promise<string> => {
diff --git a/packages/create-video/src/test/validate-templates.test.ts b/packages/create-video/src/test/validate-templates.test.ts
index d4ef4a8069..57c5d4725a 100644
--- a/packages/create-video/src/test/validate-templates.test.ts
+++ b/packages/create-video/src/test/validate-templates.test.ts
@@ -7,6 +7,23 @@ const getFileForTemplate = (template: Template, file: string) => {
return `https://github.com/${template.org}/${template.repoName}/raw/${template.defaultBranch}/${file}`;
};
+const findFile = async (options: string[]) => {
+ let entryPoint: string | null = null;
+ let contents: string | null = null;
+ for (const point of options) {
+ const res = await got(point, {
+ throwHttpErrors: false,
+ });
+ if (res.statusCode === 200) {
+ entryPoint = point;
+ contents = res.body;
+ break;
+ }
+ }
+
+ return {entryPoint, contents};
+};
+
describe('Templates should be valid', () => {
for (const template of FEATURED_TEMPLATES) {
it(
@@ -183,20 +200,3 @@ describe('Templates should be valid', () => {
);
}
});
-
-const findFile = async (options: string[]) => {
- let entryPoint: string | null = null;
- let contents: string | null = null;
- for (const point of options) {
- const res = await got(point, {
- throwHttpErrors: false,
- });
- if (res.statusCode === 200) {
- entryPoint = point;
- contents = res.body;
- break;
- }
- }
-
- return {entryPoint, contents};
-};
diff --git a/packages/docs/components/Bounties.tsx b/packages/docs/components/Bounties.tsx
index 17be773ab7..334791e0fb 100644
--- a/packages/docs/components/Bounties.tsx
+++ b/packages/docs/components/Bounties.tsx
@@ -15,6 +15,33 @@ type RemoteData<T> =
type Bounty = AlgoraOutput["bounty"]["list"]["items"][number];
+const BountyCard = (props: { bounty: Bounty }) => (
+ <a
+ href={props.bounty.task.url}
+ target="_blank"
+ rel="noopener"
+ className="bounty-card"
+ >
+ <div className="bounty-content">
+ <div className="bounty-reward">{props.bounty.reward_formatted}</div>
+ <div className="bounty-issue">
+ {props.bounty.task.repo_name}#{props.bounty.task.number}
+ </div>
+ <div className="bounty-title">{props.bounty.task.title}</div>
+ </div>
+ </a>
+);
+
+const BountyCardSkeleton = () => (
+ <div className="bounty-skeleton">
+ <div className="bounty-content">
+ <div className="bounty-reward" />
+ <div className="bounty-issue" />
+ <div className="bounty-title" />
+ </div>
+ </div>
+);
+
export const Bounties = () => {
const { isDarkTheme } = useColorMode();
@@ -50,30 +77,3 @@ export const Bounties = () => {
</div>
);
};
-
-const BountyCard = (props: { bounty: Bounty }) => (
- <a
- href={props.bounty.task.url}
- target="_blank"
- rel="noopener"
- className="bounty-card"
- >
- <div className="bounty-content">
- <div className="bounty-reward">{props.bounty.reward_formatted}</div>
- <div className="bounty-issue">
- {props.bounty.task.repo_name}#{props.bounty.task.number}
- </div>
- <div className="bounty-title">{props.bounty.task.title}</div>
- </div>
- </a>
-);
-
-const BountyCardSkeleton = () => (
- <div className="bounty-skeleton">
- <div className="bounty-content">
- <div className="bounty-reward" />
- <div className="bounty-issue" />
- <div className="bounty-title" />
- </div>
- </div>
-);
diff --git a/packages/docs/components/demos/index.tsx b/packages/docs/components/demos/index.tsx
index 4c621b9a5f..6ce229c488 100644
--- a/packages/docs/components/demos/index.tsx
+++ b/packages/docs/components/demos/index.tsx
@@ -58,7 +58,7 @@ export const Demo: React.FC<{
[
o.name,
o.optional === "default-disabled" ? null : o.default,
- ] as const
+ ] as const,
)
.reduce((a, b) => {
a[b[0]] = b[1];
@@ -66,6 +66,8 @@ export const Demo: React.FC<{
}, {});
}, [demo.options]);
+ const [state, setState] = useState(() => initialState);
+
const restart = useCallback(() => {
setState(initialState);
setKey((k) => k + 1);
@@ -75,8 +77,6 @@ export const Demo: React.FC<{
throw new Error("Demo not found");
}
- const [state, setState] = useState(() => initialState);
-
return (
<div style={container}>
<Player
diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json
index eb27ad6a6a..9b524a984b 100644
--- a/packages/eslint-plugin/package.json
+++ b/packages/eslint-plugin/package.json
@@ -14,7 +14,7 @@
"author": "Jonny Burger <[email protected]>",
"license": "ISC",
"dependencies": {
- "@typescript-eslint/utils": "6.7.4"
+ "@typescript-eslint/utils": "5.19.0"
},
"keywords": [
"eslint",
diff --git a/packages/media-utils/src/audio-buffer/audio-buffer-to-wav.ts b/packages/media-utils/src/audio-buffer/audio-buffer-to-wav.ts
index 6ca99a2053..77c86801fc 100644
--- a/packages/media-utils/src/audio-buffer/audio-buffer-to-wav.ts
+++ b/packages/media-utils/src/audio-buffer/audio-buffer-to-wav.ts
@@ -2,31 +2,43 @@
* Inlined from https://github.com/Jam3/audiobuffer-to-wav/commit/2272eb09bd46a05e50a6d684d908aa6f13c58f63#diff-e727e4bdf3657fd1d798edcd6b099d6e092f8573cba266154583a746bba0f346
*/
-export function audioBufferToWav(
- buffer: AudioBuffer,
- opt: {
- float32: boolean;
- },
-) {
- const numChannels = buffer.numberOfChannels;
- const {sampleRate} = buffer;
- const format = opt.float32 ? 3 : 1;
- const bitDepth = format === 3 ? 32 : 16;
+function interleave(inputL: Float32Array, inputR: Float32Array) {
+ const length = inputL.length + inputR.length;
+ const result = new Float32Array(length);
- let result;
- if (numChannels === 2) {
- result = interleave(buffer.getChannelData(0), buffer.getChannelData(1));
- } else {
- result = buffer.getChannelData(0);
+ let index = 0;
+ let inputIndex = 0;
+
+ while (index < length) {
+ result[index++] = inputL[inputIndex];
+ result[index++] = inputR[inputIndex];
+ inputIndex++;
}
- return encodeWAV({
- samples: result,
- format,
- sampleRate,
- numChannels,
- bitDepth,
- });
+ return result;
+}
+
+function writeFloat32(output: DataView, offset: number, input: Float32Array) {
+ for (let i = 0; i < input.length; i++, offset += 4) {
+ output.setFloat32(offset, input[i], true);
+ }
+}
+
+function floatTo16BitPCM(
+ output: DataView,
+ offset: number,
+ input: Float32Array,
+) {
+ for (let i = 0; i < input.length; i++, offset += 2) {
+ const s = Math.max(-1, Math.min(1, input[i]));
+ output.setInt16(offset, s < 0 ? s * 0x8000 : s * 0x7fff, true);
+ }
+}
+
+function writeString(view: DataView, offset: number, string: string) {
+ for (let i = 0; i < string.length; i++) {
+ view.setUint8(offset + i, string.charCodeAt(i));
+ }
}
function encodeWAV({
@@ -84,41 +96,29 @@ function encodeWAV({
return buffer;
}
-function interleave(inputL: Float32Array, inputR: Float32Array) {
- const length = inputL.length + inputR.length;
- const result = new Float32Array(length);
-
- let index = 0;
- let inputIndex = 0;
-
- while (index < length) {
- result[index++] = inputL[inputIndex];
- result[index++] = inputR[inputIndex];
- inputIndex++;
- }
-
- return result;
-}
-
-function writeFloat32(output: DataView, offset: number, input: Float32Array) {
- for (let i = 0; i < input.length; i++, offset += 4) {
- output.setFloat32(offset, input[i], true);
- }
-}
-
-function floatTo16BitPCM(
- output: DataView,
- offset: number,
- input: Float32Array,
+export function audioBufferToWav(
+ buffer: AudioBuffer,
+ opt: {
+ float32: boolean;
+ },
) {
- for (let i = 0; i < input.length; i++, offset += 2) {
- const s = Math.max(-1, Math.min(1, input[i]));
- output.setInt16(offset, s < 0 ? s * 0x8000 : s * 0x7fff, true);
- }
-}
+ const numChannels = buffer.numberOfChannels;
+ const {sampleRate} = buffer;
+ const format = opt.float32 ? 3 : 1;
+ const bitDepth = format === 3 ? 32 : 16;
-function writeString(view: DataView, offset: number, string: string) {
- for (let i = 0; i < string.length; i++) {
- view.setUint8(offset + i, string.charCodeAt(i));
+ let result;
+ if (numChannels === 2) {
+ result = interleave(buffer.getChannelData(0), buffer.getChannelData(1));
+ } else {
+ result = buffer.getChannelData(0);
}
+
+ return encodeWAV({
+ samples: result,
+ format,
+ sampleRate,
+ numChannels,
+ bitDepth,
+ });
}
diff --git a/packages/media-utils/src/get-video-metadata.ts b/packages/media-utils/src/get-video-metadata.ts
index d94a0eea76..0c78ee9bd5 100644
--- a/packages/media-utils/src/get-video-metadata.ts
+++ b/packages/media-utils/src/get-video-metadata.ts
@@ -1,3 +1,4 @@
+/* eslint-disable @typescript-eslint/no-use-before-define */
import {isRemoteAsset} from './is-remote-asset';
import {pLimit} from './p-limit';
import type {VideoMetadata} from './types';
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 8c18c7fffa..c29695891a 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -744,8 +744,8 @@ importers:
packages/eslint-plugin:
dependencies:
'@typescript-eslint/utils':
- specifier: 6.7.4
+ specifier: 5.19.0
devDependencies:
eslint:
specifier: 8.42.0
@@ -9534,6 +9534,14 @@ packages:
transitivePeerDependencies:
- supports-color
+ /@typescript-eslint/[email protected]:
+ resolution: {integrity: sha512-Fz+VrjLmwq5fbQn5W7cIJZ066HxLMKvDEmf4eu1tZ8O956aoX45jAuBB76miAECMTODyUxH61AQM7q4/GOMQ5g==}
+ engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
+ dependencies:
+ '@typescript-eslint/types': 5.19.0
+ '@typescript-eslint/visitor-keys': 5.19.0
+ dev: false
+
/@typescript-eslint/[email protected]:
resolution: {integrity: sha512-7wWBq9d/GbPiIM6SqPK9tfynNxVbfpihoY5cSFMer19OYUA3l4powA2uv0AV2eAZV6KoAh6lkzxv4PoxOLh1oA==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
@@ -9596,6 +9604,11 @@ packages:
transitivePeerDependencies:
- supports-color
+ /@typescript-eslint/[email protected]:
+ resolution: {integrity: sha512-zR1ithF4Iyq1wLwkDcT+qFnhs8L5VUtjgac212ftiOP/ZZUOCuuF2DeGiZZGQXGoHA50OreZqLH5NjDcDqn34w==}
+ engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
+ dev: false
+
/@typescript-eslint/[email protected]:
resolution: {integrity: sha512-wHWgQHFB+qh6bu0IAPAJCdeCdI0wwzZnnWThlmHNY01XJ9Z97oKqKOzWYpR2I83QmshhQJl6LDM9TqMiMwJBTw==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
@@ -9610,6 +9623,27 @@ packages:
resolution: {integrity: sha512-o9XWK2FLW6eSS/0r/tgjAGsYasLAnOWg7hvZ/dGYSSNjCh+49k5ocPN8OmG5aZcSJ8pclSOyVKP2x03Sj+RrCA==}
engines: {node: ^16.0.0 || >=18.0.0}
+ /@typescript-eslint/[email protected]([email protected]):
+ resolution: {integrity: sha512-dRPuD4ocXdaE1BM/dNR21elSEUPKaWgowCA0bqJ6YbYkvtrPVEvZ+zqcX5a8ECYn3q5iBSSUcBBD42ubaOp0Hw==}
+ engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
+ peerDependencies:
+ typescript: '*'
+ peerDependenciesMeta:
+ typescript:
+ optional: true
+ dependencies:
+ '@typescript-eslint/types': 5.19.0
+ '@typescript-eslint/visitor-keys': 5.19.0
+ debug: 4.3.4([email protected])
+ globby: 11.1.0
+ is-glob: 4.0.3
+ semver: 7.5.3
+ tsutils: 3.21.0([email protected])
+ typescript: 4.9.5
+ transitivePeerDependencies:
+ - supports-color
+ dev: false
+
/@typescript-eslint/[email protected]([email protected]):
resolution: {integrity: sha512-kDLNn/tQP+Yp8Ro2dUpyyVV0Ksn2rmpPpB0/3MO874RNmXtypMwSeazjEN/Q6CTp8D7ExXAAekPEcCEB/vtJkw==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
@@ -9672,6 +9706,24 @@ packages:
transitivePeerDependencies:
- supports-color
+ resolution: {integrity: sha512-ZuEckdupXpXamKvFz/Ql8YnePh2ZWcwz7APICzJL985Rp5C2AYcHO62oJzIqNhAMtMK6XvrlBTZeNG8n7gS3lQ==}
+ engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
+ peerDependencies:
+ eslint: ^6.0.0 || ^7.0.0 || ^8.0.0
+ dependencies:
+ '@types/json-schema': 7.0.13
+ '@typescript-eslint/scope-manager': 5.19.0
+ '@typescript-eslint/types': 5.19.0
+ '@typescript-eslint/typescript-estree': 5.19.0([email protected])
+ eslint: 8.42.0
+ eslint-scope: 5.1.1
+ eslint-utils: 3.0.0([email protected])
+ transitivePeerDependencies:
+ - supports-color
+ - typescript
+ dev: false
+
resolution: {integrity: sha512-4O+Ps1CRDw+D+R40JYh5GlKLQERXRKW5yIQoNDpmXPJ+C7kaPF9R7GWl+PxGgXjB3PQCqsaaZUpZ9dG4U6DO7g==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
@@ -9710,6 +9762,14 @@ packages:
- supports-color
- typescript
+ /@typescript-eslint/[email protected]:
+ resolution: {integrity: sha512-Ym7zZoMDZcAKWsULi2s7UMLREdVQdScPQ/fKWMYefarCztWlHPFVJo8racf8R0Gc8FAEJ2eD4of8As1oFtnQlQ==}
+ engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
+ dependencies:
+ '@typescript-eslint/types': 5.19.0
+ eslint-visitor-keys: 3.4.1
+ dev: false
+
/@typescript-eslint/[email protected]:
resolution: {integrity: sha512-E13gBoIXmaNhwjipuvQg1ByqSAu/GbEpP/qzFihugJ+MomtoJtFAJG/+2DRPByf57B863m0/q7Zt16V9ohhANw==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
@@ -12819,12 +12879,10 @@ packages:
dependencies:
eslint: 8.42.0
eslint-visitor-keys: 2.1.0
- dev: true
resolution: {integrity: sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==}
engines: {node: '>=10'}
- dev: true
resolution: {integrity: sha512-pZnmmLwYzf+kWaM/Qgrvpen51upAktaaiI01nsJD/Yr3lMOdNtq0cxkrrg16w64VtisN6okbs7Q8AfGqj4c9fA==}
@@ -20659,7 +20717,6 @@ packages:
dependencies:
tslib: 1.14.1
typescript: 4.9.5
- dev: true
resolution: {integrity: sha512-McnNiV1l8RYeY8tBgEpuodCC1mLUdbSN+CYBL7kJsJNInOP8UjDDEwdk6Mw60vdLLrr5NHKZhMAOSrR2NZuQ+w==}