🎥 Make videos programmatically with React
working well
Jonny Burger639aa34da6cd
diff --git a/packages/cli/src/get-env.ts b/packages/cli/src/get-env.tsindex 93ca3ed2c9..e16906f338 100644--- a/packages/cli/src/get-env.ts+++ b/packages/cli/src/get-env.ts@@ -1,6 +1,7 @@import dotenv from 'dotenv';import fs from 'fs';import path from 'path';+import {Internals} from 'remotion';import {Log} from './log';import {parsedCli} from './parse-command-line';@@ -18,33 +19,57 @@ function getProcessEnv(): Record<string, string> {return env;}+const getEnvForEnvFile = async (+ processEnv: ReturnType<typeof getProcessEnv>,+ envFile: string+) => {+ try {+ const envFileData = await fs.promises.readFile(envFile);+ return {+ ...processEnv,+ ...dotenv.parse(envFileData),+ };+ } catch (err) {+ Log.error(`Your .env file at ${envFile} could not not be parsed.`);+ Log.error(err);+ process.exit(1);+ }+};+export const getEnvironmentVariables = async (): Promise<Record<string, string>> => {const processEnv = getProcessEnv();- 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);+ if (parsedCli['env-file']) {+ const envFile = path.resolve(process.cwd(), parsedCli['env-file']);+ if (!fs.existsSync(envFile)) {+ Log.error('You passed a --env-file but it could not be found.');+ Log.error('We looked for the file at:', envFile);+ Log.error('Check that your path is correct and try again.');+ process.exit(1);+ }+ return getEnvForEnvFile(processEnv, envFile);}+ const configFileSetting = Internals.getDotEnvLocation();+ if (configFileSetting) {+ const envFile = path.resolve(process.cwd(), configFileSetting);+ if (!fs.existsSync(envFile)) {+ Log.error(+ 'You specifed a custom .env file using `Config.Rendering.setDotEnvLocation()` in the config file but it could not be found'+ );+ Log.error('We looked for the file at:', envFile);+ Log.error('Check that your path is correct and try again.');+ process.exit(1);+ }+ return getEnvForEnvFile(processEnv, envFile);+ }++ const envFile = path.resolve(process.cwd(), '.env');if (!fs.existsSync(envFile)) {return processEnv;}- try {- const envFileData = await fs.promises.readFile(envFile);- return {- ...processEnv,- ...dotenv.parse(envFileData),- };- } catch (err) {- Log.error(`Your .env file at ${envFile} could not not be parsed.`);- process.exit(1);- }+ return getEnvForEnvFile(processEnv, envFile);};diff --git a/packages/core/src/config/env-file.ts b/packages/core/src/config/env-file.tsnew file mode 100644index 0000000000..0467e56332--- /dev/null+++ b/packages/core/src/config/env-file.ts@@ -0,0 +1,7 @@+let envFile: string | null = null;++export const setDotEnvLocation = (file: string) => {+ envFile = file;+};++export const getDotEnvLocation = (): string | null => envFile;diff --git a/packages/core/src/config/index.ts b/packages/core/src/config/index.tsindex 8213aa26e6..c54b38a1a4 100644--- a/packages/core/src/config/index.ts+++ b/packages/core/src/config/index.ts@@ -3,6 +3,7 @@ import {BrowserExecutable, setBrowserExecutable} from './browser-executable';import {Codec, setCodec, setOutputFormat} from './codec';import {Concurrency, setConcurrency} from './concurrency';import {setCrf} from './crf';+import {setDotEnvLocation} from './env-file';import {FrameRange, setFrameRange} from './frame-range';import {ImageFormat, setImageFormat} from './image-format';import {setImageSequence} from './image-sequence';@@ -49,6 +50,11 @@ export const Config = {setBrowserExecutable,},Rendering: {+ /**+ * Set a custom location for a .env file.+ * Default: `.env`+ */+ setDotEnvLocation,/*** Sets how many Puppeteer instances will work on rendering your video in parallel.* Default: `null`, meaning half of the threads available on your CPU.diff --git a/packages/core/src/internals.ts b/packages/core/src/internals.tsindex 4a1b418d59..a33fa6bbcf 100644--- a/packages/core/src/internals.ts+++ b/packages/core/src/internals.ts@@ -21,6 +21,7 @@ import {getDefaultCrfForCodec,validateSelectedCrfAndCodecCombination,} from './config/crf';+import {getDotEnvLocation} from './config/env-file';import {getRange,setFrameRangeFromCli,@@ -129,6 +130,7 @@ export const Internals = {setupEnvVariables,ENV_VARIABLES_ENV_NAME,ENV_VARIABLES_LOCAL_STORAGE_KEY,+ getDotEnvLocation,};export type {diff --git a/packages/docs/docs/cli.md b/packages/docs/docs/cli.mdindex 292d17fb34..bb5a66747e 100644--- a/packages/docs/docs/cli.md+++ b/packages/docs/docs/cli.md@@ -18,6 +18,7 @@ Besides choosing a video and output location with the command line arguments, th- `--pixel-format`: [Set a custom pixel format. See here for available values.](/docs/config#setpixelformat)- `--image-format`: [`jpeg` or `png` - JPEG is faster, but supports transparency.](/docs/config#setimageformat) The default image format is `jpeg` since v1.1. Flag available since v1.4.- `--config`: Specify a location for the Remotion config file. Available in v1.2 and later.+- `--env-file`: Specify a location for a dotenv file. Default `.env`. Available in v2.2 and later.- `--quality`: [Value between 0 and 100 for JPEG rendering quality](/docs/config#setquality). Doesn't work when PNG frames are rendered. Available since v1.4.- `--overwrite`: [Write to output even if file already exists.](/docs/config#setoverwriteoutput)- `--sequence`: [Pass this flag if you want an image sequence as the output instead of a video.](/docs/config#setimagesequence) Available since v1.4.