Skip to content
This repository has been archived by the owner on Dec 21, 2024. It is now read-only.

Commit

Permalink
feat: add rivet backend generate-sdk command
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFlurry committed Oct 2, 2024
1 parent 4250c20 commit 5bc4b14
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/backend/cli/tasks/gen_sdk.ts
Original file line number Diff line number Diff line change
@@ -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,
});
},
});
21 changes: 21 additions & 0 deletions packages/cli/src/commands/backend/gen_sdk.rs
Original file line number Diff line number Diff line change
@@ -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
}
}
4 changes: 4 additions & 0 deletions packages/cli/src/commands/backend/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod build;
pub mod gen_openapi;
pub mod gen_sdk;
pub mod show;

use clap::Subcommand;
Expand All @@ -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 {
Expand All @@ -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,
}
}
}

0 comments on commit 5bc4b14

Please sign in to comment.