🎥 Make videos programmatically with React
tweak
Jonny Burgeraaa4c8c49d69
diff --git a/packages/cli/src/get-cli-options.ts b/packages/cli/src/get-cli-options.tsindex 92045b84fb..922f4eb3e1 100644--- a/packages/cli/src/get-cli-options.ts+++ b/packages/cli/src/get-cli-options.ts@@ -2,12 +2,12 @@ import {RenderInternals} from '@remotion/renderer';import fs from 'fs';import path from 'path';import {Codec, FrameRange, Internals, PixelFormat} from 'remotion';+import {getEnvironmentVariables} from './get-env';import {getOutputFilename} from './get-filename';import {getInputProps} from './get-input-props';import {getImageFormat} from './image-formats';import {Log} from './log';import {getUserPassedFileExtension} from './user-passed-output-location';-import {getEnv} from "./get-env";const getAndValidateFrameRange = () => {const frameRange = Internals.getRange();@@ -175,7 +175,7 @@ export const getCliOptions = async () => {codec,overwrite: Internals.getShouldOverwrite(),inputProps: getInputProps(),- env: getEnv(),+ env: await getEnvironmentVariables(),quality: Internals.getQuality(),browser: await getAndValidateBrowser(),absoluteOutputFile: getAndValidateAbsoluteOutputFile(outputFile, overwrite),diff --git a/packages/cli/src/get-env.ts b/packages/cli/src/get-env.tsindex 9d56a289f4..93ca3ed2c9 100644--- a/packages/cli/src/get-env.ts+++ b/packages/cli/src/get-env.ts@@ -18,31 +18,33 @@ function getProcessEnv(): Record<string, string> {return env;}-export const getEnv = (): Record<string, string> => {+export const getEnvironmentVariables = async (): Promise<+ Record<string, string>+> => {const processEnv = getProcessEnv();- if (!parsedCli['env-file']) {- return processEnv;+ const envFile = path.resolve(process.cwd(), parsedCli['env-file'] ?? '.env');+ if (parsedCli['env-file'] && !fs.existsSync(envFile)) {+ Log.error(+ 'You passed --env-file but it was not a file path to a valid environment file.'+ );+ Log.info('We looked for the file at:', envFile);+ Log.error('Check that your path is correct and try again.');+ process.exit(1);}- const envFile = path.resolve(process.cwd(), parsedCli['env-file']);+ if (!fs.existsSync(envFile)) {+ return processEnv;+ }try {- if (fs.existsSync(envFile)) {- const envFileData = fs.readFileSync(envFile);- return {- ...processEnv,- ...dotenv.parse(envFileData),- };- }+ const envFileData = await fs.promises.readFile(envFile);+ return {+ ...processEnv,+ ...dotenv.parse(envFileData),+ };} catch (err) {- // fall through+ Log.error(`Your .env file at ${envFile} could not not be parsed.`);+ process.exit(1);}-- Log.error(- 'You passed --env-file but it was not a file path to a valid environment file.'- );- Log.info('Got the following value:', parsedCli['env-file']);- Log.error('Check that your input is parseable using `dotenv` and try again.');- process.exit(1);};diff --git a/packages/cli/src/parse-command-line.ts b/packages/cli/src/parse-command-line.tsindex 22ccbebc4e..1ef51edea8 100644--- a/packages/cli/src/parse-command-line.ts+++ b/packages/cli/src/parse-command-line.ts@@ -15,6 +15,7 @@ export type CommandLineOptions = {['pixel-format']: PixelFormat;['image-format']: ImageFormat;['bundle-cache']: string;+ ['env-file']: string;codec: Codec;concurrency: number;config: string;diff --git a/packages/cli/src/preview.ts b/packages/cli/src/preview.tsindex bf5706bc63..bcd0d811e8 100644--- a/packages/cli/src/preview.ts+++ b/packages/cli/src/preview.ts@@ -5,10 +5,10 @@ import betterOpn from 'better-opn';import path from 'path';import xns from 'xns';import {getConfigFileName} from './get-config-file-name';+import {getEnvironmentVariables} from './get-env';import {getInputProps} from './get-input-props';import {loadConfigFile} from './load-config';import {parsedCli} from './parse-command-line';-import {getEnv} from "./get-env";const noop = () => undefined;@@ -19,7 +19,7 @@ export const previewCommand = xns(async () => {loadConfigFile(getConfigFileName());const inputProps = getInputProps();- const env = getEnv();+ const env = getEnvironmentVariables();const port = await BundlerInternals.startServer(path.resolve(__dirname, 'previewEntry.js'),