From b10140e63eb1b5390bcc0e27427d9df181ddcfd3 Mon Sep 17 00:00:00 2001 From: NathanFlurry Date: Wed, 2 Oct 2024 10:53:41 +0000 Subject: [PATCH] feat: add `rivet backend generate-sdk` command (#548) --- packages/backend/cli/tasks/gen_sdk.ts | 20 +++++++++++++++++++ packages/cli/src/commands/backend/gen_sdk.rs | 21 ++++++++++++++++++++ packages/cli/src/commands/backend/mod.rs | 4 ++++ 3 files changed, 45 insertions(+) create mode 100644 packages/backend/cli/tasks/gen_sdk.ts create mode 100644 packages/cli/src/commands/backend/gen_sdk.rs diff --git a/packages/backend/cli/tasks/gen_sdk.ts b/packages/backend/cli/tasks/gen_sdk.ts new file mode 100644 index 00000000..b9b73687 --- /dev/null +++ b/packages/backend/cli/tasks/gen_sdk.ts @@ -0,0 +1,20 @@ +import { globalOptsSchema, initProject } from "../common.ts"; +import { build, DbDriver, Format, Runtime } from "../../toolchain/build/mod.ts"; +import { runTask } from "../task.ts"; + +runTask({ + inputSchema: globalOptsSchema, + async run(input) { + const project = await initProject(input); + + await build(project, { + format: Format.Native, + runtime: Runtime.Deno, + dbDriver: DbDriver.NodePostgres, + sdk: {}, + // Require schemas to be generated in order to generate SDk + strictSchemas: true, + skipDenoCheck: true, + }); + }, +}); diff --git a/packages/cli/src/commands/backend/gen_sdk.rs b/packages/cli/src/commands/backend/gen_sdk.rs new file mode 100644 index 00000000..49236007 --- /dev/null +++ b/packages/cli/src/commands/backend/gen_sdk.rs @@ -0,0 +1,21 @@ +use clap::Parser; +use serde::Serialize; +use std::process::ExitCode; +use toolchain::{backend::run_backend_command_passthrough, paths}; + +use crate::util::global_opts::GlobalOpts; + +/// Generate the SDK. Usually not needed since the SDK is auto-generated in `rivet dev`. +#[derive(Parser, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct Opts { + #[clap(flatten)] + #[serde(flatten)] + global: GlobalOpts, +} + +impl Opts { + pub async fn execute(&self) -> ExitCode { + run_backend_command_passthrough("gen_sdk.ts", self, paths::BackendDataType::Dev).await + } +} diff --git a/packages/cli/src/commands/backend/mod.rs b/packages/cli/src/commands/backend/mod.rs index 6c7371bb..ae0bbf3e 100644 --- a/packages/cli/src/commands/backend/mod.rs +++ b/packages/cli/src/commands/backend/mod.rs @@ -1,5 +1,6 @@ pub mod build; pub mod gen_openapi; +pub mod gen_sdk; pub mod show; use clap::Subcommand; @@ -12,6 +13,8 @@ pub enum SubCommand { Show(show::Opts), #[clap(name = "generate-openapi")] GenerateOpenApi(gen_openapi::Opts), + #[clap(name = "generate-sdk")] + GenerateSdk(gen_sdk::Opts), } impl SubCommand { @@ -20,6 +23,7 @@ impl SubCommand { SubCommand::Build(opts) => opts.execute().await, SubCommand::Show(opts) => opts.execute().await, SubCommand::GenerateOpenApi(opts) => opts.execute().await, + SubCommand::GenerateSdk(opts) => opts.execute().await, } } }