fix merge and reorganize the CLI a bit

This commit is contained in:
Evan Almloff committed 2024-01-08 13:39:12 -06:00
1 parent 0269a59c95
commit 2cc6f2f51f
10 files changed
+100 -61

No files matched your search

+60
View File
@@ -0,0 +1,60 @@
use std::{fs::File, io::Write, path::PathBuf};
use crate::Result;
use dioxus_cli_config::CrateConfig;
use manganis_cli_support::{AssetManifest, AssetManifestExt};
pub fn asset_manifest(crate_config: &CrateConfig) -> AssetManifest {
AssetManifest::load_from_path(
crate_config.crate_dir.join("Cargo.toml"),
crate_config.workspace_dir.join("Cargo.lock"),
)
}
/// Create a head file that contains all of the imports for assets that the user project uses
pub fn create_assets_head(config: &CrateConfig) -> Result<()> {
let manifest = asset_manifest(config);
let mut file = File::create(config.out_dir.join("__assets_head.html"))?;
file.write_all(manifest.head().as_bytes())?;
Ok(())
}
/// Process any assets collected from the binary
pub(crate) fn process_assets(config: &CrateConfig) -> anyhow::Result<()> {
let manifest = asset_manifest(config);
let static_asset_output_dir = PathBuf::from(
config
.dioxus_config
.web
.app
.base_path
.clone()
.unwrap_or_default(),
);
let static_asset_output_dir = config.out_dir.join(static_asset_output_dir);
manifest.copy_static_assets_to(static_asset_output_dir)?;
Ok(())
}
/// A guard that sets up the environment for the web renderer to compile in. This guard sets the location that assets will be served from
pub(crate) struct WebAssetConfigDropGuard;
impl WebAssetConfigDropGuard {
pub fn new() -> Self {
// Set up the collect asset config
manganis_cli_support::Config::default()
.with_assets_serve_location("/")
.save();
Self {}
}
}
impl Drop for WebAssetConfigDropGuard {
fn drop(&mut self) {
// Reset the config
manganis_cli_support::Config::default().save();
}
}