"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 getPort = () => { if (parsed_cli_1.parsedCli.port) { return parsed_cli_1.parsedCli.port; } const serverPort = config_1.ConfigInternals.getStudioPort(); if (serverPort) { return serverPort; } return null; }; const { binariesDirectoryOption, publicDirOption, disableGitSourceOption, enableCrossSiteIsolationOption, askAIOption, experimentalClientSideRenderingOption, keyboardShortcutsOption, forceNewStudioOption, numberOfSharedAudioTagsOption, audioLatencyHintOption, ipv4Option, } = client_1.BrowserSafeApis.options; const studioCommand = async (remotionRoot, args, logLevel) => { 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 = getPort(); const fullEntryPath = (0, convert_entry_point_to_serve_url_1.convertEntryPointToServeUrl)(file); 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 gitSource = (0, get_github_repository_1.getGitSource)({ remotionRoot, disableGitSource, logLevel }); const result = await studio_server_1.StudioServerInternals.startStudio({ previewEntry: require.resolve('@remotion/studio/previewEntry'), browserArgs: parsed_cli_1.parsedCli['browser-args'], browserFlag: parsed_cli_1.parsedCli.browser, logLevel, configValueShouldOpenBrowser: config_1.ConfigInternals.getShouldOpenBrowser(), fullEntryPath, getCurrentInputProps: () => inputProps, getEnvVariables: () => envVariables, desiredPort, keyboardShortcutsEnabled, experimentalClientSideRenderingEnabled, maxTimelineTracks: config_1.ConfigInternals.getMaxTimelineTracks(), remotionRoot, relativePublicDir, webpackOverride: config_1.ConfigInternals.getWebpackOverrideFn(), poll: config_1.ConfigInternals.getWebpackPolling(), 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, }, // Minimist quirk: Adding `--no-open` flag will result in {['no-open']: false, open: true} // @ts-expect-error parsedCliOpen: parsed_cli_1.parsedCli.open, 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, enableCrossSiteIsolation, askAIEnabled, forceNew: forceNewStudioOption.getValue({ commandLine: parsed_cli_1.parsedCli }).value, }); 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;