🎥 Make videos programmatically with React
Migrate CLI flags to proper RemotionOption definitions
Jonny Burger95229f3caa52
diff --git a/packages/cli/src/bundle.ts b/packages/cli/src/bundle.tsindex 71b99ea3a4..6c85fefca7 100644--- a/packages/cli/src/bundle.ts+++ b/packages/cli/src/bundle.ts@@ -21,6 +21,7 @@ const {askAIOption,experimentalClientSideRenderingOption,keyboardShortcutsOption,+ outDirOption,} = BrowserSafeApis.options;export const bundleCommand = async (@@ -90,8 +91,9 @@ export const bundleCommand = async (commandLine: parsedCli,}).value;- const outputPath = parsedCli['out-dir']- ? path.resolve(process.cwd(), parsedCli['out-dir'])+ const outDir = outDirOption.getValue({commandLine: parsedCli}).value;+ const outputPath = outDir+ ? path.resolve(process.cwd(), outDir): path.join(remotionRoot, 'build');const gitignoreFolder = BundlerInternals.findClosestFolderWithItem(diff --git a/packages/cli/src/config/index.ts b/packages/cli/src/config/index.tsindex 2256a33a51..e0ab20d8d3 100644--- a/packages/cli/src/config/index.ts+++ b/packages/cli/src/config/index.ts@@ -119,6 +119,7 @@ const {overrideWidthOption,overrideFpsOption,overrideDurationOption,+ outDirOption,} = BrowserSafeApis.options;declare global {@@ -587,6 +588,11 @@ type FlatConfig = RemotionConfigObject &* Default: false*/setIPv4: (ipv4: boolean) => void;+ /**+ * Define the output directory for `npx remotion bundle`.+ * Default: `build` in the Remotion root.+ */+ setOutDir: (outDir: string | null) => void;/*** Choose between using Chrome Headless Shell or Chrome for Testing*/@@ -738,6 +744,7 @@ export const Config: FlatConfig = {setPublicLicenseKey: publicLicenseKeyOption.setConfig,setForceNewStudioEnabled: forceNewStudioOption.setConfig,setIPv4: ipv4Option.setConfig,+ setOutDir: outDirOption.setConfig,};export const ConfigInternals = {diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.tsindex 3ed5e42cd8..7b01902904 100644--- a/packages/cli/src/index.ts+++ b/packages/cli/src/index.ts@@ -1,4 +1,5 @@import {RenderInternals} from '@remotion/renderer';+import {BrowserSafeApis} from '@remotion/renderer/client';import {StudioServerInternals} from '@remotion/studio-server';import minimist from 'minimist';import {addCommand} from './add';@@ -49,9 +50,15 @@ import {versionsCommand,} from './versions';+const {packageManagerOption} = BrowserSafeApis.options;+export const cli = async () => {const [command, ...args] = parsedCli._;+ const packageManager = packageManagerOption.getValue({+ commandLine: parsedCli,+ }).value;+const remotionRoot = RenderInternals.findRemotionRoot();if (command !== VERSIONS_COMMAND && !parsedCli.help) {await validateVersionsBeforeCommand(remotionRoot, 'info');@@ -111,7 +118,7 @@ export const cli = async () => {} else if (command === 'upgrade') {await upgradeCommand({remotionRoot,- packageManager: parsedCli['package-manager'],+ packageManager: packageManager ?? undefined,version: parsedCli.version,logLevel,args,@@ -130,7 +137,7 @@ export const cli = async () => {await addCommand({remotionRoot,- packageManager: parsedCli['package-manager'],+ packageManager: packageManager ?? undefined,packageNames,logLevel,args: additionalArgs,diff --git a/packages/cli/src/parse-command-line.ts b/packages/cli/src/parse-command-line.tsindex a47faa45ce..4cecca6fd3 100644--- a/packages/cli/src/parse-command-line.ts+++ b/packages/cli/src/parse-command-line.ts@@ -46,6 +46,8 @@ const {overrideWidthOption,overrideFpsOption,overrideDurationOption,+ outDirOption,+ packageManagerOption,} = BrowserSafeApis.options;export type CommandLineOptions = {@@ -121,13 +123,13 @@ export type CommandLineOptions = {concurrencies: string;[enforceAudioOption.cliFlag]: TypeOfOption<typeof enforceAudioOption>;gl: OpenGlRenderer;- ['package-manager']: string;+ [packageManagerOption.cliFlag]: TypeOfOption<typeof packageManagerOption>;['webpack-poll']: number;['no-open']: boolean;['browser']: string;['browser-args']: string;[userAgentOption.cliFlag]: TypeOfOption<typeof userAgentOption>;- ['out-dir']: string;+ [outDirOption.cliFlag]: TypeOfOption<typeof outDirOption>;[audioLatencyHintOption.cliFlag]: AudioContextLatencyCategory;[ipv4Option.cliFlag]: TypeOfOption<typeof ipv4Option>;[deleteAfterOption.cliFlag]: TypeOfOption<typeof deleteAfterOption>;diff --git a/packages/docs/docs/cli/add.mdx b/packages/docs/docs/cli/add.mdxindex dd9948b215..e89a50f571 100644--- a/packages/docs/docs/cli/add.mdx+++ b/packages/docs/docs/cli/add.mdx@@ -38,9 +38,7 @@ This command will:### `--package-manager`<AvailableFrom v="4.0.367"/>-Forces a specific package manager to be used. By default, Remotion will auto-detect the package manager based on your lockfile.--Acceptable values are `npm`, `yarn` and `pnpm`+<Options id="package-manager" />## Package manager supportdiff --git a/packages/docs/docs/cli/bundle.mdx b/packages/docs/docs/cli/bundle.mdxindex 98b5de3c55..9693cf2d54 100644--- a/packages/docs/docs/cli/bundle.mdx+++ b/packages/docs/docs/cli/bundle.mdx@@ -32,7 +32,7 @@ Specify a location for the Remotion config file.### `--out-dir`-Define the location of the resulting bundle. By default it is a folder called `./build`, adjacent to the [Remotion Root](/docs/terminology/remotion-root).+<Options id="out-dir" />### `--public-path`<AvailableFrom v="4.0.127"/>diff --git a/packages/docs/docs/cli/upgrade.mdx b/packages/docs/docs/cli/upgrade.mdxindex 4e821bdc50..6cf8a9d5f8 100644--- a/packages/docs/docs/cli/upgrade.mdx+++ b/packages/docs/docs/cli/upgrade.mdx@@ -17,9 +17,7 @@ npx remotion upgrade### `--package-manager`<AvailableFrom v="3.2.33"/>-Forces a specific package manager to be used. This is useful if you are using Remotion in a monorepo and you want to upgrade all packages at once. By default, Remotion will auto-detect the package manager.--Acceptable values are `npm`, `yarn` and `pnpm`+<Options id="package-manager" />### `--version`<AvailableFrom v="4.0.15"/>diff --git a/packages/docs/docs/config.mdx b/packages/docs/docs/config.mdxindex 5782e44683..155c5f7c61 100644--- a/packages/docs/docs/config.mdx+++ b/packages/docs/docs/config.mdx@@ -87,6 +87,18 @@ Config.setPublicDir('./custom-public-dir');The [command line flag](/docs/cli/render#--public-dir) `--public-dir` will take precedence over this option.+## `setOutDir()`<AvailableFrom v="4.0.426" />++<Options id="out-dir" />++```ts twoslash title="remotion.config.ts"+import {Config} from '@remotion/cli/config';+// ---cut---+Config.setOutDir('./custom-build-dir');+```++The [command line flag](/docs/cli/bundle#--out-dir) `--out-dir` will take precedence over this option.+## `setEntryPoint()`<AvailableFrom v="3.2.40" />Sets the Remotion [entry point](/docs/terminology/entry-point), you don't have to specify it for CLI commands.diff --git a/packages/lambda/src/cli/commands/render/render.ts b/packages/lambda/src/cli/commands/render/render.tsindex 2ee5686bd6..a714d952d6 100644--- a/packages/lambda/src/cli/commands/render/render.ts+++ b/packages/lambda/src/cli/commands/render/render.ts@@ -63,6 +63,8 @@ const {userAgentOption,disableWebSecurityOption,ignoreCertificateErrorsOption,+ audioCodecOption,+ videoCodecOption,} = BrowserSafeApis.options;export const renderCommand = async ({@@ -206,6 +208,9 @@ export const renderCommand = async ({const darkMode = darkModeOption.getValue({commandLine: CliInternals.parsedCli,}).value;+ const audioCodec = audioCodecOption.getValue({+ commandLine: CliInternals.parsedCli,+ }).value;const chromiumOptions: Required<ChromiumOptions> = {disableWebSecurity,@@ -289,19 +294,18 @@ export const renderCommand = async ({const outName = parsedLambdaCli['out-name'];const downloadName = args[2] ?? null;- const {value: codec, source: reason} =- BrowserSafeApis.options.videoCodecOption.getValue(- {- commandLine: CliInternals.parsedCli,- },- {- downloadName,- outName: outName ?? null,- configFile: ConfigInternals.getOutputCodecOrUndefined() ?? null,- uiCodec: null,- compositionCodec: null,- },- );+ const {value: codec, source: reason} = videoCodecOption.getValue(+ {+ commandLine: CliInternals.parsedCli,+ },+ {+ downloadName,+ outName: outName ?? null,+ configFile: ConfigInternals.getOutputCodecOrUndefined() ?? null,+ uiCodec: null,+ compositionCodec: null,+ },+ );const imageFormat = CliInternals.getVideoImageFormat({codec,@@ -366,8 +370,7 @@ export const renderCommand = async ({: null,rendererFunctionName: parsedLambdaCli['renderer-function-name'] ?? null,forceBucketName: parsedLambdaCli['force-bucket-name'] ?? null,- audioCodec:- CliInternals.parsedCli[BrowserSafeApis.options.audioCodecOption.cliFlag],+ audioCodec,deleteAfter: deleteAfter ?? null,colorSpace,downloadBehavior: {type: 'play-in-browser'},diff --git a/packages/renderer/src/options/index.tsx b/packages/renderer/src/options/index.tsxindex a669ff7611..9495f5a6c1 100644--- a/packages/renderer/src/options/index.tsx+++ b/packages/renderer/src/options/index.tsx@@ -42,6 +42,8 @@ import {mutedOption} from './mute';import {numberOfGifLoopsOption} from './number-of-gif-loops';import {numberOfSharedAudioTagsOption} from './number-of-shared-audio-tags';import {offthreadVideoCacheSizeInBytesOption} from './offthreadvideo-cache-size';+import {outDirOption} from './out-dir';+import {packageManagerOption} from './package-manager';import {offthreadVideoThreadsOption} from './offthreadvideo-threads';import {onBrowserDownloadOption} from './on-browser-download';import type {AnyRemotionOption} from './option';@@ -141,6 +143,8 @@ export const allOptions = {overrideWidthOption,overrideFpsOption,overrideDurationOption,+ outDirOption,+ packageManagerOption,};export type AvailableOptions = keyof typeof allOptions;diff --git a/packages/renderer/src/options/out-dir.tsx b/packages/renderer/src/options/out-dir.tsxnew file mode 100644index 0000000000..b7bbd65c48--- /dev/null+++ b/packages/renderer/src/options/out-dir.tsx@@ -0,0 +1,46 @@+import type {AnyRemotionOption} from './option';++const cliFlag = 'out-dir' as const;++let currentOutDir: string | null = null;++export const outDirOption = {+ name: 'Output Directory',+ cliFlag,+ description: () => {+ return (+ <>+ Define the location of the resulting bundle. By default it is a folder+ called <code>build</code>, adjacent to the{' '}+ <a href="/docs/terminology/remotion-root">Remotion Root</a>.+ </>+ );+ },+ ssrName: 'outDir' as const,+ docLink: 'https://www.remotion.dev/docs/cli/bundle#--out-dir',+ getValue: ({commandLine}) => {+ if (commandLine[cliFlag] !== undefined) {+ return {+ source: 'cli',+ value: commandLine[cliFlag] as string,+ };+ }++ if (currentOutDir !== null) {+ return {+ source: 'config',+ value: currentOutDir,+ };+ }++ return {+ source: 'default',+ value: null,+ };+ },+ setConfig: (value: string | null) => {+ currentOutDir = value;+ },+ type: '' as string | null,+ id: cliFlag,+} satisfies AnyRemotionOption<string | null>;diff --git a/packages/renderer/src/options/package-manager.tsx b/packages/renderer/src/options/package-manager.tsxnew file mode 100644index 0000000000..c727d783c7--- /dev/null+++ b/packages/renderer/src/options/package-manager.tsx@@ -0,0 +1,48 @@+import type {AnyRemotionOption} from './option';++const cliFlag = 'package-manager' as const;++let currentPackageManager: string | null = null;++export const packageManagerOption = {+ name: 'Package Manager',+ cliFlag,+ description: () => {+ return (+ <>+ Forces a specific package manager to be used. By default, Remotion will+ auto-detect the package manager based on your lockfile.+ <br />+ Acceptable values are <code>npm</code>, <code>yarn</code>,{' '}+ <code>pnpm</code> and <code>bun</code>.+ </>+ );+ },+ ssrName: 'packageManager' as const,+ docLink: 'https://www.remotion.dev/docs/cli/upgrade#--package-manager',+ getValue: ({commandLine}) => {+ if (commandLine[cliFlag] !== undefined) {+ return {+ source: 'cli',+ value: commandLine[cliFlag] as string,+ };+ }++ if (currentPackageManager !== null) {+ return {+ source: 'config',+ value: currentPackageManager,+ };+ }++ return {+ source: 'default',+ value: null,+ };+ },+ setConfig: (value: string | null) => {+ currentPackageManager = value;+ },+ type: '' as string | null,+ id: cliFlag,+} satisfies AnyRemotionOption<string | null>;