use super::base_compiler::{BaseCompiler, BaseCompilerContext};
use super::helpers::manual_restart::display_manual_restart_tip;
use super::helpers::tsconfig_provider::{TsConfigData, TsConfigProvider};
use super::plugins::plugins_loader::MultiNestCompilerPlugins;
use super::rust_toolchain_loader::RustToolchainLoader;
pub use super::{AssetDeleteOnUnlink, WatchOptions};
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct WatchCompiler {
pub base: BaseCompiler,
pub ts_config_provider: TsConfigProvider,
pub rust_toolchain_loader: RustToolchainLoader,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct WatchCompilerRunPlan {
pub ts_config_path: String,
pub app_name: Option<String>,
pub preserve_watch_output: Option<bool>,
pub manual_restart: bool,
pub manual_restart_tip: Option<String>,
pub ts_config: TsConfigData,
pub plugins: MultiNestCompilerPlugins,
}
impl WatchCompiler {
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: &str,
app_name: Option<&str>,
preserve_watch_output: Option<bool>,
) -> Result<WatchCompilerRunPlan, String> {
self.rust_toolchain_loader.load()?;
let ts_config = self
.ts_config_provider
.get_by_config_filename(ts_config_path)?;
let compiler_options = context.compiler_options_for(app_name);
let plugins = self.base.load_plugins(context, ts_config_path, app_name)?;
Ok(WatchCompilerRunPlan {
ts_config_path: ts_config_path.to_string(),
app_name: app_name.map(ToString::to_string),
preserve_watch_output,
manual_restart: compiler_options.manual_restart,
manual_restart_tip: compiler_options
.manual_restart
.then(display_manual_restart_tip),
ts_config,
plugins,
})
}
pub fn is_success_status(message: &str) -> bool {
message.contains("0 errors")
}
}