🎥 Make videos programmatically with React
added shared logic for validating image format
Apoorv Kansalb1d75f89ae18
diff --git a/packages/cli/src/index.tsx b/packages/cli/src/index.tsxindex b3512ddd78..4408fb1ad2 100644--- a/packages/cli/src/index.tsx+++ b/packages/cli/src/index.tsx@@ -26,6 +26,7 @@ import {createOverwriteableCliOutput} from './progress-bar';import {render} from './render';import {still} from './still';import {upgrade} from './upgrade';+import {validateImageFormat} from './validate-image-format';import {validateVersionsBeforeCommand,versionsCommand,@@ -96,6 +97,7 @@ export const CliInternals = {getCliOptions,parseCommandLine,loadConfig,+ validateImageFormat,initializeRenderCli,BooleanFlags,quietFlagProvided,diff --git a/packages/cli/src/still.ts b/packages/cli/src/still.tsindex 6c08505ea9..ddd984992d 100644--- a/packages/cli/src/still.ts+++ b/packages/cli/src/still.ts@@ -29,6 +29,7 @@ import {getOutputLocation,getUserPassedOutputLocation,} from './user-passed-output-location';+import {validateImageFormat} from './validate-image-format';export const still = async (remotionRoot: string) => {const startTime = Date.now();@@ -105,21 +106,7 @@ export const still = async (remotionRoot: string) => {process.exit(1);}- if (imageFormat === 'png' && !absoluteOutputLocation.endsWith('.png')) {- Log.warn(- `Rendering a PNG, expected a .png extension but got ${absoluteOutputLocation}`- );- }-- if (- imageFormat === 'jpeg' &&- !absoluteOutputLocation.endsWith('.jpg') &&- !absoluteOutputLocation.endsWith('.jpeg')- ) {- Log.warn(- `Rendering a JPEG, expected a .jpg or .jpeg extension but got ${absoluteOutputLocation}`- );- }+ validateImageFormat(imageFormat, absoluteOutputLocation);const browserInstance = openBrowser(browser, {browserExecutable,diff --git a/packages/cli/src/validate-image-format.ts b/packages/cli/src/validate-image-format.tsnew file mode 100644index 0000000000..04f4d64dc0--- /dev/null+++ b/packages/cli/src/validate-image-format.ts@@ -0,0 +1,21 @@+import type {ImageFormat} from '@remotion/renderer';+import {Log} from './log';++export const validateImageFormat = (+ imageFormat: ImageFormat,+ outName: string | null+) => {+ if (imageFormat === 'png' && outName?.endsWith('.png')) {+ Log.warn(`Rendering a PNG, expected a .png extension but got ${outName}`);+ }++ if (+ imageFormat === 'jpeg' &&+ !outName?.endsWith('.jpg') &&+ !outName?.endsWith('.jpeg')+ ) {+ Log.warn(+ `Rendering a JPEG, expected a .jpg or .jpeg extension but got ${outName}`+ );+ }+};diff --git a/packages/lambda/src/cli/commands/still.ts b/packages/lambda/src/cli/commands/still.tsindex 409936427c..88a22717a4 100644--- a/packages/lambda/src/cli/commands/still.ts+++ b/packages/lambda/src/cli/commands/still.ts@@ -88,19 +88,7 @@ export const stillCommand = async (args: string[]) => {}}- if (imageFormat === 'png' && outName.endsWith('.png')) {- Log.warn(`Rendering a PNG, expected a .png extension but got ${outName}`);- }-- if (- imageFormat === 'jpeg' &&- !outName.endsWith('.jpg') &&- !outName.endsWith('.jpeg')- ) {- Log.warn(- `Rendering a JPEG, expected a .jpg or .jpeg extension but got ${outName}`- );- }+ CliInternals.validateImageFormat(imageFormat, outName);}try {