Skip to content

🎥 Make videos programmatically with React

disambuigate findEntryPoint and getEntryPoint

Jonny Burgerf7936e5e3810
diff --git a/packages/cli/src/benchmark.ts b/packages/cli/src/benchmark.ts
index 275863db78..2a89afda45 100644
--- a/packages/cli/src/benchmark.ts
+++ b/packages/cli/src/benchmark.ts
@@ -8,7 +8,7 @@ import {
import path from 'path';
import {chalk} from './chalk';
import {ConfigInternals} from './config';
-import { getEntryPoint } from './entry-point';
+import {findEntryPoint} from './entry-point';
import {getCliOptions, getFinalCodec} from './get-cli-options';
import {getRenderMediaOptions} from './get-render-media-options';
import {Log} from './log';
@@ -134,13 +134,11 @@ const makeBenchmarkProgressBar = ({
].join(' ');
};
-export const benchmarkCommand = async (
- remotionRoot: string,
-) => {
+export const benchmarkCommand = async (remotionRoot: string) => {
const runs: number = parsedCli.runs ?? DEFAULT_RUNS;
const args = parsedCli._.slice(1);
- const filePath = getEntryPoint();
+ const filePath = findEntryPoint();
if (!filePath) {
Log.error('No entry file passed.');
diff --git a/packages/cli/src/entry-point.ts b/packages/cli/src/entry-point.ts
index 3a2582bf19..ba2395d2ff 100644
--- a/packages/cli/src/entry-point.ts
+++ b/packages/cli/src/entry-point.ts
@@ -1,24 +1,37 @@
-import { existsSync } from "fs";
-import { parsedCli } from "./parse-command-line";
-import { ConfigInternals } from "./config";
-import { Log } from "./log";
+import {existsSync} from 'fs';
+import {ConfigInternals} from './config';
+import {Log} from './log';
+import {parsedCli} from './parse-command-line';
-export const getEntryPoint = () => {
+const candidates = [
+ './src/index.tsx',
+ './src/index.ts',
+ './src/index.js',
+ './remotion/index.tsx',
+ './remotion/index.ts',
+ './remotion/index.js',
+];
+
+const findCommonPath = () => {
+ return candidates.find((candidate) => existsSync(candidate));
+};
+
+export const findEntryPoint = () => {
+ // 1st priority: Explicitly passed entry point
let file: string | null = parsedCli._[1];
- if (file) return file;
+ if (file) return file;
- file = ConfigInternals.getEntryPoint();
- if (file) return file;
+ // 2nd priority: Config 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";
+ // 3rd priority: Common paths
+ const found = findCommonPath();
- if (file) {
- Log.verbose(`No entry point specified. Using ${file} as fallback`);
- return file;
- }
+ if (found) {
+ Log.verbose(`No entry point specified. Using ${found} as fallback`);
+ return found;
+ }
- return null;
-}
\ No newline at end of file
+ return null;
+};
diff --git a/packages/cli/src/preview.ts b/packages/cli/src/preview.ts
index 10515ef706..882fffa0b9 100644
--- a/packages/cli/src/preview.ts
+++ b/packages/cli/src/preview.ts
@@ -2,7 +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 {findEntryPoint} from './entry-point';
import {getEnvironmentVariables} from './get-env';
import {getInputProps} from './get-input-props';
import {getNetworkAddress} from './get-network-address';
@@ -35,7 +35,7 @@ const waitForLiveEventsListener = (): Promise<LiveEventsServer> => {
};
export const previewCommand = async (remotionRoot: string) => {
- const file = getEntryPoint();
+ const file = findEntryPoint();
if (!file) {
Log.error(
diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsx
index 61111a702a..d716bb3b6e 100644
--- a/packages/cli/src/render.tsx
+++ b/packages/cli/src/render.tsx
@@ -13,7 +13,7 @@ import path from 'path';
import {Internals} from 'remotion';
import {chalk} from './chalk';
import {ConfigInternals} from './config';
-import { getEntryPoint } from './entry-point';
+import {findEntryPoint} from './entry-point';
import {
getAndValidateAbsoluteOutputFile,
getCliOptions,
@@ -36,7 +36,7 @@ import {getUserPassedOutputLocation} from './user-passed-output-location';
export const render = async (remotionRoot: string) => {
const startTime = Date.now();
- const file = getEntryPoint();
+ const file = findEntryPoint();
if (!file) {
Log.error('No entry point specified. Pass more arguments:');