Skip to content

🎥 Make videos programmatically with React

If entry point isn't specified, try to automatically detect it

Ravi Jain05ff155711c6
diff --git a/packages/cli/src/benchmark.ts b/packages/cli/src/benchmark.ts
index 95a8a2aaa4..275863db78 100644
--- a/packages/cli/src/benchmark.ts
+++ b/packages/cli/src/benchmark.ts
@@ -8,6 +8,7 @@ import {
import path from 'path';
import {chalk} from './chalk';
import {ConfigInternals} from './config';
+import { getEntryPoint } from './entry-point';
import {getCliOptions, getFinalCodec} from './get-cli-options';
import {getRenderMediaOptions} from './get-render-media-options';
import {Log} from './log';
@@ -135,11 +136,11 @@ const makeBenchmarkProgressBar = ({
export const benchmarkCommand = async (
remotionRoot: string,
- args: string[]
) => {
const runs: number = parsedCli.runs ?? DEFAULT_RUNS;
+ const args = parsedCli._.slice(1);
- const filePath = args[0];
+ const filePath = getEntryPoint();
if (!filePath) {
Log.error('No entry file passed.');
diff --git a/packages/cli/src/config/entry-point.ts b/packages/cli/src/config/entry-point.ts
new file mode 100644
index 0000000000..371b098cc6
--- /dev/null
+++ b/packages/cli/src/config/entry-point.ts
@@ -0,0 +1,9 @@
+let entryPoint: string | null = null;
+
+export const setEntryPoint = (ep: string) => {
+ entryPoint = ep;
+};
+
+export const getEntryPoint = () => {
+ return entryPoint;
+};
diff --git a/packages/cli/src/config/index.ts b/packages/cli/src/config/index.ts
index 882b5f6107..84d3624225 100644
--- a/packages/cli/src/config/index.ts
+++ b/packages/cli/src/config/index.ts
@@ -91,11 +91,13 @@ import {setQuality} from './quality';
import {setScale} from './scale';
import {setPuppeteerTimeout} from './timeout';
import {setWebpackCaching} from './webpack-caching';
+import { getEntryPoint, setEntryPoint } from './entry-point';
export const Config: ConfigType = {
Preview: {
setMaxTimelineTracks,
setKeyboardShortcutsEnabled,
+ setEntryPoint,
},
Bundling: {
overrideWebpackConfig,
@@ -190,6 +192,7 @@ export const ConfigInternals = {
getAudioBitrate,
getVideoBitrate,
getCrfOrUndefined,
+ getEntryPoint,
};
export const overrideRemotion = () => {
diff --git a/packages/cli/src/entry-point.ts b/packages/cli/src/entry-point.ts
new file mode 100644
index 0000000000..3a2582bf19
--- /dev/null
+++ b/packages/cli/src/entry-point.ts
@@ -0,0 +1,24 @@
+import { existsSync } from "fs";
+import { parsedCli } from "./parse-command-line";
+import { ConfigInternals } from "./config";
+import { Log } from "./log";
+
+export const getEntryPoint = () => {
+ let file: string | null = parsedCli._[1];
+ if (file) return file;
+
+ file = ConfigInternals.getEntryPoint();
+ if (file) return file;
+
+ if (existsSync("./src/index.tsx")) file = "src/index.tsx";
+ else if (existsSync("./src/index.ts")) file = "src/index.ts";
+ else if (existsSync("./src/index.js")) file = "src/index.js";
+ else if (existsSync("./remotion/index.js")) file = "remotion/index.js";
+
+ if (file) {
+ Log.verbose(`No entry point specified. Using ${file} as fallback`);
+ return file;
+ }
+
+ return null;
+}
\ No newline at end of file
diff --git a/packages/cli/src/index.tsx b/packages/cli/src/index.tsx
index 05dc11c147..31f3d3d5ea 100644
--- a/packages/cli/src/index.tsx
+++ b/packages/cli/src/index.tsx
@@ -71,7 +71,7 @@ export const cli = async () => {
} else if (command === VERSIONS_COMMAND) {
await versionsCommand(remotionRoot);
} else if (command === 'benchmark') {
- await benchmarkCommand(remotionRoot, parsedCli._.slice(1));
+ await benchmarkCommand(remotionRoot);
} else if (command === 'help') {
printHelp();
process.exit(0);
diff --git a/packages/cli/src/preview.ts b/packages/cli/src/preview.ts
index cf22f59432..10515ef706 100644
--- a/packages/cli/src/preview.ts
+++ b/packages/cli/src/preview.ts
@@ -2,6 +2,7 @@ import betterOpn from 'better-opn';
import path from 'path';
import {chalk} from './chalk';
import {ConfigInternals} from './config';
+import { getEntryPoint } from './entry-point';
import {getEnvironmentVariables} from './get-env';
import {getInputProps} from './get-input-props';
import {getNetworkAddress} from './get-network-address';
@@ -34,7 +35,7 @@ const waitForLiveEventsListener = (): Promise<LiveEventsServer> => {
};
export const previewCommand = async (remotionRoot: string) => {
- const file = parsedCli._[1];
+ const file = getEntryPoint();
if (!file) {
Log.error(
diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsx
index 3cf29b8e52..61111a702a 100644
--- a/packages/cli/src/render.tsx
+++ b/packages/cli/src/render.tsx
@@ -13,6 +13,7 @@ import path from 'path';
import {Internals} from 'remotion';
import {chalk} from './chalk';
import {ConfigInternals} from './config';
+import { getEntryPoint } from './entry-point';
import {
getAndValidateAbsoluteOutputFile,
getCliOptions,
@@ -35,7 +36,8 @@ import {getUserPassedOutputLocation} from './user-passed-output-location';
export const render = async (remotionRoot: string) => {
const startTime = Date.now();
- const file = parsedCli._[1];
+ const file = getEntryPoint();
+
if (!file) {
Log.error('No entry point specified. Pass more arguments:');
Log.error(
diff --git a/packages/docs/docs/cli/compositions.md b/packages/docs/docs/cli/compositions.md
index 86df9f4f80..6b746b20aa 100644
--- a/packages/docs/docs/cli/compositions.md
+++ b/packages/docs/docs/cli/compositions.md
@@ -11,6 +11,11 @@ Print list of composition IDs based on a path of an entry point.
npx remotion compositions <entry-file>
```
+If `entry-file` is not passed, Remotion will try to detect the entry file with the following priority order:
+1. Get the path from the Config (Can be set using `Config.Preview.setEntryPoint("<entry-point>")`).
+2. Look for some common paths i.e. `src/index.tsx`, `src/index.ts`, `src/index.js`, `remotion/index.js`.
+3. Fail as entry point could not be determined.
+
## Flags
### `--props`
diff --git a/packages/docs/docs/cli/preview.md b/packages/docs/docs/cli/preview.md
index ab1a0ba2d9..44e89e6732 100644
--- a/packages/docs/docs/cli/preview.md
+++ b/packages/docs/docs/cli/preview.md
@@ -6,9 +6,14 @@ sidebar_label: preview
Start the server which allows you to preview the Remotion video. The only argument to pass is the entry file:
```bash
-npx remotion preview src/index.tsx
+npx remotion preview <entry-file>
```
+If `entry-file` is not passed, Remotion will try to detect the entry file with the following priority order:
+1. Get the path from the Config (Can be set using `Config.Preview.setEntryPoint("<entry-point>")`).
+2. Look for some common paths i.e. `src/index.tsx`, `src/index.ts`, `src/index.js`, `remotion/index.js`.
+3. Fail as entry point could not be determined.
+
## Flags
### `--props`
diff --git a/packages/docs/docs/cli/render.md b/packages/docs/docs/cli/render.md
index fa4daef05a..28bd6c6310 100644
--- a/packages/docs/docs/cli/render.md
+++ b/packages/docs/docs/cli/render.md
@@ -11,6 +11,11 @@ Render a video or audio based on the entry point, the composition ID and save it
npx remotion render <entry-file> [<composition-id>] [<output-location>]
```
+If `entry-file` is not passed, Remotion will try to detect the entry file with the following priority order:
+1. Get the path from the Config (Can be set using `Config.Preview.setEntryPoint("<entry-point>")`).
+2. Look for some common paths i.e. `src/index.tsx`, `src/index.ts`, `src/index.js`, `remotion/index.js`.
+3. Fail as entry point could not be determined.
+
If `output-location` is not passed, the media will be rendered into the `out` folder.
If `composition-id` is also not passed, Remotion will let you select a composition.