forklaunch 1.33.0

Launch faster with forklaunch
use anyhow::Result;
use clap::{ArgMatches, Command};

use crate::{
    CliCommand,
    core::command::command,
    sdk::{generate::GenerateCommand, mode::ModeCommand, watch::WatchCommand},
};

pub(crate) mod generate;
pub(crate) mod typescript_build;
mod http_sources;
mod layout;
mod media;
pub(crate) mod mode;
mod models;
mod modern;
use forklaunch_core::build::service_package;
mod openapi;
mod render;
mod workspace;
pub(crate) use workspace::include_typescript_sdk;
pub(crate) use layout::sdk_base;
mod schema;
use forklaunch_core::typescript as schema_runtime;
mod versions;
pub(crate) mod watch;
pub(crate) mod websocket;

#[derive(Debug)]
pub(crate) struct SdkCommand {
    generate: GenerateCommand,
    build: typescript_build::BuildCommand,
    mode: ModeCommand,
    watch: WatchCommand,
}

impl SdkCommand {
    pub(crate) fn new() -> Self {
        Self {
            generate: GenerateCommand::new(),
            build: typescript_build::BuildCommand,
            mode: ModeCommand::new(),
            watch: WatchCommand::new(),
        }
    }
}

impl CliCommand for SdkCommand {
    fn command(&self) -> Command {
        command("sdk", "Manage SDKs")
            .subcommand_required(true)
            .subcommand(self.generate.command())
            .subcommand(self.build.command())
            .subcommand(self.mode.command())
            .subcommand(self.watch.command())
    }

    fn handler(&self, matches: &ArgMatches) -> Result<()> {
        match matches.subcommand() {
            Some(("generate", sub_matches)) => self.generate.handler(sub_matches),
            Some(("build", sub_matches)) => self.build.handler(sub_matches),
            Some(("mode", sub_matches)) => self.mode.handler(sub_matches),
            Some(("watch", sub_matches)) => self.watch.handler(sub_matches),
            _ => unreachable!(),
        }
    }
}

/// Avoid waking development watchers when generated bytes have not changed.
fn write_if_changed(
    path: impl AsRef<std::path::Path>,
    content: impl AsRef<[u8]>,
) -> std::io::Result<()> {
    forklaunch_core::build::write_generated_output(path, content).map_err(std::io::Error::other)
}