nestrs-cli-rs 0.1.0

Rust port of the Nest CLI for the nestrs organization.
Documentation
//! Rust-native compiler planning.

use std::path::PathBuf;

use super::base_compiler::{BaseCompiler, BaseCompilerContext};
use super::helpers::tsconfig_provider::{TsConfigData, TsConfigProvider};
use super::hooks::tsconfig_paths_hook::TsconfigPathsHook;
use super::plugins::plugins_loader::MultiNestCompilerPlugins;
use super::rust_toolchain_loader::RustToolchainLoader;
pub use super::{BuildPlan, BuildPlanRequest, create_build_plan};

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Compiler {
    pub base: BaseCompiler,
    pub ts_config_provider: TsConfigProvider,
    pub rust_toolchain_loader: RustToolchainLoader,
}

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct CompilerRunPlan {
    pub ts_config_path: PathBuf,
    pub app_name: Option<String>,
    pub ts_config: TsConfigData,
    pub plugins: MultiNestCompilerPlugins,
    pub tsconfig_paths_hook: TsconfigPathsHook,
    pub on_success: bool,
}

impl Compiler {
    pub fn new(
        base: BaseCompiler,
        ts_config_provider: TsConfigProvider,
        rust_toolchain_loader: RustToolchainLoader,
    ) -> Self {
        Self {
            base,
            ts_config_provider,
            rust_toolchain_loader,
        }
    }

    pub fn plan_run(
        &mut self,
        context: &BaseCompilerContext,
        ts_config_path: impl Into<PathBuf>,
        app_name: Option<&str>,
        on_success: bool,
    ) -> Result<CompilerRunPlan, String> {
        self.rust_toolchain_loader.load()?;
        let ts_config_path = ts_config_path.into();
        let ts_config = self
            .ts_config_provider
            .get_by_config_filename(&ts_config_path.to_string_lossy())?;
        let plugins = self.base.load_plugins(context, &ts_config_path, app_name)?;
        let tsconfig_paths_hook = TsconfigPathsHook::default();
        Ok(CompilerRunPlan {
            ts_config_path,
            app_name: app_name.map(ToString::to_string),
            ts_config,
            plugins,
            tsconfig_paths_hook,
            on_success,
        })
    }

    pub fn report_after_compilation_diagnostic(diagnostics: &[String]) -> usize {
        diagnostics.len()
    }
}