🎥 Make videos programmatically with React
adding getCompositions, plus help messages
Matt McGillivrayededa787223c
diff --git a/packages/gcp/package.json b/packages/gcp/package.jsonindex 70d37c359a..57a3d55fc8 100644--- a/packages/gcp/package.json+++ b/packages/gcp/package.json@@ -4,10 +4,10 @@"description": "GCP alternative to lambda rendering","main": "dist/index.js","scripts": {- "build": "tsc -d && pnpm run buildContainer",+ "build": "tsc -d","buildContainer": "ts-node src/admin/bundle-renderLogic.ts","start": "functions-framework --target=TypescriptFunction",- "prestart": "pnpm run build"+ "watch": "tsc -w"},"bin": {"remotion-gcp": "remotion-gcp-cli.mjs"@@ -28,4 +28,4 @@"ts-node": "^10.8.0","@types/minimist": "1.2.2"}-}+}\ No newline at end of filediff --git a/packages/gcp/src/api/get-compositions-on-gcp.ts b/packages/gcp/src/api/get-compositions-on-gcp.tsnew file mode 100644index 0000000000..ff13bc485f--- /dev/null+++ b/packages/gcp/src/api/get-compositions-on-gcp.ts@@ -0,0 +1,27 @@+import type { TCompMetadata } from 'remotion';+import {+ getCompositions+} from '@remotion/renderer';++export type GetCompositionsOnGcpInput = { serveUrl: string;};++export type GetCompositionsOnGcpOutput = TCompMetadata[];++/**+ * @description Returns the compositions from a serveUrl+ * @link https://remotion.dev/docs/lambda/getcompositionsOnGcp+ * @param params.serveUrl The URL of the deployed project+ * @returns The compositions+ */+export const getCompositionsOnGcp = async ({+ serveUrl+}: GetCompositionsOnGcpInput): Promise<GetCompositionsOnGcpOutput> => {++ try {+ const comps = await getCompositions(serveUrl);+ return comps;+ }+ catch (err) {+ throw err;+ }+};diff --git a/packages/gcp/src/cli/args.ts b/packages/gcp/src/cli/args.tsindex e06bce043c..543a460316 100644--- a/packages/gcp/src/cli/args.ts+++ b/packages/gcp/src/cli/args.ts@@ -3,6 +3,7 @@ import {CliInternals} from '@remotion/cli';import type {GcpRegion} from '../pricing/gcp-regions';type GCPCommandLineOptions = {+ help: boolean;region: GcpRegion;['project-id']: string;['remotion-version']: string | undefined;diff --git a/packages/gcp/src/cli/commands/cloud-run/index.ts b/packages/gcp/src/cli/commands/cloud-run/index.tsindex c459af883e..30265d1cf1 100644--- a/packages/gcp/src/cli/commands/cloud-run/index.ts+++ b/packages/gcp/src/cli/commands/cloud-run/index.ts@@ -1,13 +1,24 @@+import {CliInternals} from '@remotion/cli';import {Log} from '@remotion/cli/dist/log';import {quit} from '../../helpers/quit';import {cloudRunDeploySubcommand, CLOUD_RUN_DEPLOY_SUBCOMMAND} from './deploy';+import {BINARY_NAME} from '../../../shared/constants';export const CLOUD_RUN_COMMAND = 'cloud-run';const printCloudRunHelp = () => {- // TODO: Add help text+ Log.info(`${BINARY_NAME} ${CLOUD_RUN_COMMAND} <subcommand>`);+ Log.info();+ Log.info('Available subcommands:');+ Log.info('');+ Log.info(+ `${BINARY_NAME} ${CLOUD_RUN_COMMAND} ${CLOUD_RUN_DEPLOY_SUBCOMMAND}`+ );+ Log.info(CliInternals.chalk.gray('Deploy a new Cloud Run service'));};+// TODO: Add LS, RM, RMALL subcommands+export const cloudRunCommand = (args: string[]) => {if (args[0] === CLOUD_RUN_DEPLOY_SUBCOMMAND) {return cloudRunDeploySubcommand();diff --git a/packages/gcp/src/cli/commands/compositions/index.ts b/packages/gcp/src/cli/commands/compositions/index.tsnew file mode 100644index 0000000000..b1d6335ff5--- /dev/null+++ b/packages/gcp/src/cli/commands/compositions/index.ts@@ -0,0 +1,33 @@+import {CliInternals} from '@remotion/cli';+import {getCompositionsOnGcp} from '../../../api/get-compositions-on-gcp';+import {BINARY_NAME} from '../../../shared/constants';+import {validateServeUrl} from '../../../shared/validate-serveurl';+import {quit} from '../../helpers/quit';+import {Log} from '../../log';++export const COMPOSITIONS_COMMAND = 'compositions';++export const compositionsCommand = async (+ args: string[],+ remotionRoot: string+) => {+ const serveUrl = args[0];++ if (!serveUrl) {+ Log.error('No serve URL passed.');+ Log.info(+ 'Pass an additional argument specifying a URL where your Remotion project is hosted.'+ );+ Log.info();+ Log.info(`${BINARY_NAME} ${COMPOSITIONS_COMMAND} <serve-url>`);+ quit(1);+ }++ validateServeUrl(serveUrl);++ const comps = await getCompositionsOnGcp({+ serveUrl+ });++ CliInternals.printCompositions(comps);+};diff --git a/packages/gcp/src/cli/commands/sites/index.ts b/packages/gcp/src/cli/commands/sites/index.tsindex 04fd2d1ce4..49357cfaba 100644--- a/packages/gcp/src/cli/commands/sites/index.ts+++ b/packages/gcp/src/cli/commands/sites/index.ts@@ -1,13 +1,24 @@+import {CliInternals} from '@remotion/cli';import {Log} from '@remotion/cli/dist/log';import {quit} from '../../helpers/quit';import {sitesCreateSubcommand, SITES_CREATE_SUBCOMMAND} from './create';+import {BINARY_NAME} from '../../../shared/constants';export const SITES_COMMAND = 'sites';const printSitesHelp = () => {- // TODO: Add help text+ Log.info(`${BINARY_NAME} ${SITES_COMMAND} <subcommand>`);+ Log.info();+ Log.info('Available subcommands:');+ Log.info('');+ Log.info(+ `${BINARY_NAME} ${SITES_COMMAND} ${SITES_CREATE_SUBCOMMAND}`+ );+ Log.info(CliInternals.chalk.gray('Creates a new site based on a Remotion project'));};+// TODO: Add LS, RM, RMALL subcommands+export const sitesCommand = (args: string[], remotionRoot: string) => {if (args[0] === SITES_CREATE_SUBCOMMAND) {return sitesCreateSubcommand(args.slice(1), remotionRoot);diff --git a/packages/gcp/src/cli/help.ts b/packages/gcp/src/cli/help.tsnew file mode 100644index 0000000000..d8316bcce5--- /dev/null+++ b/packages/gcp/src/cli/help.ts@@ -0,0 +1,33 @@+import {CliInternals} from '@remotion/cli';+import {BINARY_NAME} from '../shared/constants';+import {CLOUD_RUN_COMMAND} from './commands/cloud-run';+import {SITES_COMMAND} from './commands/sites';+import {Log} from './log';++const packagejson = require('../../package.json');++export const printHelp = () => {+ Log.info(+ `${BINARY_NAME} ${+ packagejson.version+ } © ${new Date().getFullYear()} The Remotion developers`+ );+ Log.info();+ Log.info('Available commands:');+ Log.info('');++ // Log.info(`${BINARY_NAME} ${RENDER_COMMAND} <s3-url> <composition-id>`);+ // Log.info(CliInternals.chalk.gray('Render a video in the cloud.'));++ // Log.info(`${BINARY_NAME} ${STILL_COMMAND} <s3-url> <composition-id>`);+ // Log.info(CliInternals.chalk.gray('Render a still image in the cloud.'));++ Log.info();+ Log.info(`${BINARY_NAME} ${CLOUD_RUN_COMMAND}`);+ Log.info(CliInternals.chalk.gray('Deploy and manage GCP Cloud Run services.'));++ Log.info();+ Log.info(`${BINARY_NAME} ${SITES_COMMAND}`);+ Log.info(CliInternals.chalk.gray('Deploy and manage Remotion projects.'));++};diff --git a/packages/gcp/src/cli/index.ts b/packages/gcp/src/cli/index.tsindex 1dc0628ce6..d0b58cd271 100644--- a/packages/gcp/src/cli/index.ts+++ b/packages/gcp/src/cli/index.ts@@ -3,10 +3,15 @@ import {quit} from './helpers/quit';import {parsedGcpCli} from './args';import {cloudRunCommand, CLOUD_RUN_COMMAND} from './commands/cloud-run';import {sitesCommand, SITES_COMMAND} from './commands/sites';+import {+ compositionsCommand,+ COMPOSITIONS_COMMAND,+} from './commands/compositions';+import {printHelp} from './help';const matchCommand = (args: string[], remotionRoot: string) => {if (parsedGcpCli.help || args.length === 0) {- // printHelp(); TODO: implement help+ printHelp();quit(0);}@@ -18,13 +23,17 @@ const matchCommand = (args: string[], remotionRoot: string) => {return sitesCommand(args.slice(1), remotionRoot);}+ if (args[0] === COMPOSITIONS_COMMAND) {+ return compositionsCommand(args.slice(1), remotionRoot);+ }+if (args[0] === 'deploy') {Log.info(`The "deploy" command does not exist.`);Log.info(`Did you mean "cloud-run deploy"?`);}Log.error(`Command ${args[0]} not found.`);- // printHelp(); TODO: implement help+ printHelp();quit(1);};diff --git a/packages/gcp/src/shared/validate-serveurl.ts b/packages/gcp/src/shared/validate-serveurl.tsnew file mode 100644index 0000000000..61132a60fd--- /dev/null+++ b/packages/gcp/src/shared/validate-serveurl.ts@@ -0,0 +1,9 @@+export const validateServeUrl = (serveUrl: unknown) => {+ if (typeof serveUrl !== 'string') {+ throw new TypeError(+ `"serveURL" parameter must be a string, but is ${JSON.stringify(+ serveUrl+ )}`+ );+ }+};diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 9c0ef1aff9..c0d224cf33 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -561,7 +561,7 @@ importers:devDependencies:'@remotion/compositor-linux-x64-musl': link:../compositor-linux-x64-musl'@types/minimist': 1.2.2- prettier-plugin-organize-imports: 3.2.2_j2odc4yr77iddtreafyicbq5hi+ prettier-plugin-organize-imports: 3.2.2_sleyu2lpiyw25c2kdlrjimfidits-node: 10.8.0_vnj66vw6pmisrnpmmxy72mdbpatypescript: 4.7.2@@ -18765,7 +18765,7 @@ packages:typescript: 4.7.2dev: true- /prettier-plugin-organize-imports/3.2.2_j2odc4yr77iddtreafyicbq5hi:+ /prettier-plugin-organize-imports/3.2.2_sleyu2lpiyw25c2kdlrjimfidi:resolution: {integrity: sha512-e97lE6odGSiHonHJMTYC0q0iLXQyw0u5z/PJpvP/3vRy6/Zi9kLBwFAbEGjDzIowpjQv8b+J04PDamoUSQbzGA==}peerDependencies:'@volar/vue-language-plugin-pug': ^1.0.4@@ -18778,7 +18778,7 @@ packages:'@volar/vue-typescript':optional: truedependencies:- prettier: 2.7.1+ prettier: 2.8.4typescript: 4.7.2dev: true@@ -18799,6 +18799,12 @@ packages:engines: {node: '>=10.13.0'}hasBin: true+ /prettier/2.8.4:+ resolution: {integrity: sha512-vIS4Rlc2FNh0BySk3Wkd6xmwxB0FpOndW5fisM5H8hsZSxU2VWVB5CWIkIjWvrHjIhxk2g3bfMKM87zNTrZddw==}+ engines: {node: '>=10.13.0'}+ hasBin: true+ dev: true+/pretty-error/4.0.0:resolution: {integrity: sha512-AoJ5YMAcXKYxKhuJGdcvse+Voc6v1RgnsR3nWcYU7q4t6z0Q6T86sv5Zq8VIRbOWWFpvdGE83LtdSMNd+6Y0xw==}dependencies: