UNPKG

@remotion/cli

Version:

Control Remotion features using the `npx remotion` command

135 lines (134 loc) 7.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.studioCommand = void 0; const client_1 = require("@remotion/renderer/client"); const studio_server_1 = require("@remotion/studio-server"); const config_1 = require("./config"); const convert_entry_point_to_serve_url_1 = require("./convert-entry-point-to-serve-url"); const entry_point_1 = require("./entry-point"); const get_env_1 = require("./get-env"); const get_github_repository_1 = require("./get-github-repository"); const get_input_props_1 = require("./get-input-props"); const get_render_defaults_1 = require("./get-render-defaults"); const log_1 = require("./log"); const parsed_cli_1 = require("./parsed-cli"); const queue_1 = require("./render-queue/queue"); const { binariesDirectoryOption, publicDirOption, disableGitSourceOption, enableCrossSiteIsolationOption, askAIOption, interactivityOption, experimentalClientSideRenderingOption, keyboardShortcutsOption, forceNewStudioOption, numberOfSharedAudioTagsOption, audioLatencyHintOption, ipv4Option, rspackOption, webpackPollOption, noOpenOption, portOption, browserOption, previewSampleRateOption, } = client_1.BrowserSafeApis.options; const studioCommand = async (remotionRoot, args, logLevel) => { var _a, _b, _c; const { file, reason } = (0, entry_point_1.findEntryPoint)({ args, remotionRoot, logLevel, allowDirectory: false, }); log_1.Log.verbose({ indent: false, logLevel }, 'Entry point:', file, 'reason:', reason); if (!file) { log_1.Log.error({ indent: false, logLevel }, 'No Remotion entrypoint was found. Specify an additional argument manually:'); log_1.Log.error({ indent: false, logLevel }, ' npx remotion studio src/index.ts'); log_1.Log.error({ indent: false, logLevel }, 'See https://www.remotion.dev/docs/register-root for more information.'); process.exit(1); } const desiredPort = (_b = (_a = portOption.getValue({ commandLine: parsed_cli_1.parsedCli }).value) !== null && _a !== void 0 ? _a : config_1.ConfigInternals.getStudioPort()) !== null && _b !== void 0 ? _b : null; const fullEntryPath = (0, convert_entry_point_to_serve_url_1.convertEntryPointToServeUrl)(file); studio_server_1.StudioServerInternals.setFileWatcherRegistry(studio_server_1.StudioServerInternals.createFileWatcherRegistry()); let inputProps = (0, get_input_props_1.getInputProps)((newProps) => { studio_server_1.StudioServerInternals.waitForLiveEventsListener().then((listener) => { inputProps = newProps; listener.sendEventToClient({ type: 'new-input-props', newProps, }); }); }, logLevel); let envVariables = (0, get_env_1.getEnvironmentVariables)((newEnvVariables) => { studio_server_1.StudioServerInternals.waitForLiveEventsListener().then((listener) => { envVariables = newEnvVariables; listener.sendEventToClient({ type: 'new-env-variables', newEnvVariables, }); }); }, logLevel, false); const keyboardShortcutsEnabled = keyboardShortcutsOption.getValue({ commandLine: parsed_cli_1.parsedCli, }).value; const experimentalClientSideRenderingEnabled = experimentalClientSideRenderingOption.getValue({ commandLine: parsed_cli_1.parsedCli, }).value; if (experimentalClientSideRenderingEnabled) { log_1.Log.warn({ indent: false, logLevel }, 'Enabling WIP client-side rendering. Please see caveats on https://www.remotion.dev/docs/client-side-rendering/.'); } const binariesDirectory = binariesDirectoryOption.getValue({ commandLine: parsed_cli_1.parsedCli, }).value; const disableGitSource = disableGitSourceOption.getValue({ commandLine: parsed_cli_1.parsedCli, }).value; const relativePublicDir = publicDirOption.getValue({ commandLine: parsed_cli_1.parsedCli, }).value; const enableCrossSiteIsolation = enableCrossSiteIsolationOption.getValue({ commandLine: parsed_cli_1.parsedCli, }).value; const askAIEnabled = askAIOption.getValue({ commandLine: parsed_cli_1.parsedCli, }).value; const interactivityEnabled = interactivityOption.getValue({ commandLine: parsed_cli_1.parsedCli, }).value; const gitSource = (0, get_github_repository_1.getGitSource)({ remotionRoot, disableGitSource, logLevel }); const useRspack = rspackOption.getValue({ commandLine: parsed_cli_1.parsedCli }).value; if (useRspack) { log_1.Log.warn({ indent: false, logLevel }, 'Enabling experimental Rspack bundler.'); } const result = await studio_server_1.StudioServerInternals.startStudio({ previewEntry: require.resolve('@remotion/studio/previewEntry'), browserArgs: parsed_cli_1.parsedCli['browser-args'], browserFlag: (_c = browserOption.getValue({ commandLine: parsed_cli_1.parsedCli }).value) !== null && _c !== void 0 ? _c : '', logLevel, shouldOpenBrowser: !noOpenOption.getValue({ commandLine: parsed_cli_1.parsedCli }).value, fullEntryPath, getCurrentInputProps: () => inputProps, getEnvVariables: () => envVariables, desiredPort, keyboardShortcutsEnabled, experimentalClientSideRenderingEnabled, maxTimelineTracks: config_1.ConfigInternals.getMaxTimelineTracks(), remotionRoot, relativePublicDir, webpackOverride: config_1.ConfigInternals.getWebpackOverrideFn(), poll: webpackPollOption.getValue({ commandLine: parsed_cli_1.parsedCli }).value, getRenderDefaults: get_render_defaults_1.getRenderDefaults, getRenderQueue: queue_1.getRenderQueue, numberOfAudioTags: numberOfSharedAudioTagsOption.getValue({ commandLine: parsed_cli_1.parsedCli, }).value, queueMethods: { addJob: queue_1.addJob, cancelJob: queue_1.cancelJob, removeJob: queue_1.removeJob, }, gitSource, bufferStateDelayInMilliseconds: config_1.ConfigInternals.getBufferStateDelayInMilliseconds(), binariesDirectory, forceIPv4: ipv4Option.getValue({ commandLine: parsed_cli_1.parsedCli }).value, audioLatencyHint: audioLatencyHintOption.getValue({ commandLine: parsed_cli_1.parsedCli, }).value, previewSampleRate: previewSampleRateOption.getValue({ commandLine: parsed_cli_1.parsedCli, }).value, enableCrossSiteIsolation, askAIEnabled, interactivityEnabled, forceNew: forceNewStudioOption.getValue({ commandLine: parsed_cli_1.parsedCli }).value, rspack: useRspack, }); if (result.type === 'already-running') { return; } // If the server is restarted through the UI, let's do the whole thing again. await (0, exports.studioCommand)(remotionRoot, args, logLevel); }; exports.studioCommand = studioCommand;