mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-23 04:33:06 +00:00
fix merge and reorganize the CLI a bit
This commit is contained in:
parent
0269a59c95
commit
2cc6f2f51f
10 changed files with 100 additions and 61 deletions
|
@ -18,8 +18,8 @@ once_cell = "1.18.0"
|
|||
tracing.workspace = true
|
||||
|
||||
# bundling
|
||||
tauri-bundler = { version = "=1.3.0", features = ["native-tls-vendored"], optional = true }
|
||||
tauri-utils = { version = "=1.4.*", optional = true }
|
||||
tauri-bundler = { version = "=1.4.0", features = ["native-tls-vendored"], optional = true }
|
||||
tauri-utils = { version = "=1.5.*", optional = true }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
|
|
|
@ -200,6 +200,7 @@ impl From<NsisSettings> for tauri_bundler::NsisSettings {
|
|||
display_language_selector: val.display_language_selector,
|
||||
custom_language_files: None,
|
||||
template: None,
|
||||
compression: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -353,6 +353,8 @@ pub struct CrateConfig {
|
|||
pub verbose: bool,
|
||||
pub custom_profile: Option<String>,
|
||||
pub features: Option<Vec<String>>,
|
||||
pub target: Option<String>,
|
||||
pub cargo_args: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
|
@ -415,6 +417,8 @@ impl CrateConfig {
|
|||
let verbose = false;
|
||||
let custom_profile = None;
|
||||
let features = None;
|
||||
let target = None;
|
||||
let cargo_args = vec![];
|
||||
|
||||
Ok(Self {
|
||||
out_dir,
|
||||
|
@ -432,6 +436,8 @@ impl CrateConfig {
|
|||
custom_profile,
|
||||
features,
|
||||
verbose,
|
||||
target,
|
||||
cargo_args,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -469,6 +475,16 @@ impl CrateConfig {
|
|||
self.features = Some(features);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_target(&mut self, target: String) -> &mut Self {
|
||||
self.target = Some(target);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_cargo_args(&mut self, cargo_args: Vec<String>) -> &mut Self {
|
||||
self.cargo_args = cargo_args;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
fn true_bool() -> bool {
|
||||
|
|
|
@ -76,7 +76,7 @@ toml_edit = "0.19.11"
|
|||
tauri-bundler = { version = "=1.4.*", features = ["native-tls-vendored"] }
|
||||
tauri-utils = "=1.5.*"
|
||||
|
||||
manganis-cli-support= { git = "https://github.com/DioxusLabs/collect-assets", features = ["webp", "html"] }
|
||||
manganis-cli-support = { git = "https://github.com/DioxusLabs/collect-assets", features = ["webp", "html"] }
|
||||
|
||||
dioxus-autofmt = { workspace = true }
|
||||
dioxus-check = { workspace = true }
|
||||
|
|
60
packages/cli/src/assets.rs
Normal file
60
packages/cli/src/assets.rs
Normal 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();
|
||||
}
|
||||
}
|
|
@ -1,19 +1,18 @@
|
|||
use crate::{
|
||||
assets::{asset_manifest, create_assets_head, process_assets, WebAssetConfigDropGuard},
|
||||
error::{Error, Result},
|
||||
tools::Tool,
|
||||
};
|
||||
use cargo_metadata::{diagnostic::Diagnostic, Message};
|
||||
use dioxus_cli_config::crate_root;
|
||||
use dioxus_cli_config::CrateConfig;
|
||||
use dioxus_cli_config::DioxusConfig;
|
||||
use dioxus_cli_config::ExecutableType;
|
||||
use indicatif::{ProgressBar, ProgressStyle};
|
||||
use lazy_static::lazy_static;
|
||||
use manganis_cli_support::AssetManifestExt;
|
||||
use serde::Serialize;
|
||||
use std::{
|
||||
fs::{copy, create_dir_all, File},
|
||||
io::{Read, Write},
|
||||
io::Read,
|
||||
panic,
|
||||
path::PathBuf,
|
||||
time::Duration,
|
||||
|
@ -415,13 +414,6 @@ pub fn build_desktop(
|
|||
})
|
||||
}
|
||||
|
||||
fn create_assets_head(config: &CrateConfig) -> Result<()> {
|
||||
let manifest = config.asset_manifest();
|
||||
let mut file = File::create(config.out_dir.join("__assets_head.html"))?;
|
||||
file.write_all(manifest.head().as_bytes())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn prettier_build(cmd: subprocess::Exec) -> anyhow::Result<Vec<Diagnostic>> {
|
||||
let mut warning_messages: Vec<Diagnostic> = vec![];
|
||||
|
||||
|
@ -478,10 +470,10 @@ fn prettier_build(cmd: subprocess::Exec) -> anyhow::Result<Vec<Diagnostic>> {
|
|||
Ok(warning_messages)
|
||||
}
|
||||
|
||||
pub fn gen_page(config: &DioxusConfig, serve: bool, skip_assets: bool) -> String {
|
||||
pub fn gen_page(config: &CrateConfig, serve: bool, skip_assets: bool) -> String {
|
||||
let _gaurd = WebAssetConfigDropGuard::new();
|
||||
|
||||
let crate_root = crate::cargo::crate_root().unwrap();
|
||||
let crate_root = crate_root().unwrap();
|
||||
let custom_html_file = crate_root.join("index.html");
|
||||
let mut html = if custom_html_file.is_file() {
|
||||
let mut buf = String::new();
|
||||
|
@ -514,11 +506,17 @@ pub fn gen_page(config: &DioxusConfig, serve: bool, skip_assets: bool) -> String
|
|||
&style.to_str().unwrap(),
|
||||
))
|
||||
}
|
||||
if config.application.tools.clone().contains_key("tailwindcss") {
|
||||
if config
|
||||
.dioxus_config
|
||||
.application
|
||||
.tools
|
||||
.clone()
|
||||
.contains_key("tailwindcss")
|
||||
{
|
||||
style_str.push_str("<link rel=\"stylesheet\" href=\"/{base_path}/tailwind.css\">\n");
|
||||
}
|
||||
if !skip_assets {
|
||||
let manifest = config.asset_manifest();
|
||||
let manifest = asset_manifest(config);
|
||||
style_str.push_str(&manifest.head());
|
||||
}
|
||||
|
||||
|
@ -569,7 +567,7 @@ pub fn gen_page(config: &DioxusConfig, serve: bool, skip_assets: bool) -> String
|
|||
);
|
||||
}
|
||||
|
||||
let title = config.web.app.title.clone();
|
||||
let title = config.dioxus_config.web.app.title.clone();
|
||||
|
||||
replace_or_insert_before("{app_title}", &title, "</title", &mut html);
|
||||
|
||||
|
@ -734,42 +732,3 @@ fn build_assets(config: &CrateConfig) -> Result<Vec<PathBuf>> {
|
|||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
/// Process any assets collected from the binary
|
||||
fn process_assets(config: &CrateConfig) -> anyhow::Result<()> {
|
||||
let manifest = config.asset_manifest();
|
||||
|
||||
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(())
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use crate::assets::WebAssetConfigDropGuard;
|
||||
#[cfg(feature = "plugin")]
|
||||
use crate::plugin::PluginManager;
|
||||
use crate::server::fullstack::FullstackServerEnvGuard;
|
||||
use crate::server::fullstack::FullstackWebEnvGuard;
|
||||
use crate::WebAssetConfigDropGuard;
|
||||
use dioxus_cli_config::Platform;
|
||||
|
||||
use super::*;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
pub const DIOXUS_CLI_VERSION: &str = "0.4.1";
|
||||
|
||||
mod assets;
|
||||
pub mod builder;
|
||||
pub mod server;
|
||||
pub mod tools;
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
use dioxus_cli_config::CrateConfig;
|
||||
|
||||
use crate::{
|
||||
assets::WebAssetConfigDropGuard,
|
||||
cfg::{ConfigOptsBuild, ConfigOptsServe},
|
||||
CrateConfig, Result, WebAssetConfigDropGuard,
|
||||
Result,
|
||||
};
|
||||
|
||||
use super::{desktop, Platform};
|
||||
|
@ -86,7 +89,7 @@ fn build_web(serve: ConfigOptsServe, target_directory: &std::path::Path) -> Resu
|
|||
}
|
||||
None => web_config.features = Some(vec![web_feature]),
|
||||
};
|
||||
web_config.platform = Some(crate::cfg::Platform::Web);
|
||||
web_config.platform = Some(dioxus_cli_config::Platform::Web);
|
||||
|
||||
let _gaurd = FullstackWebEnvGuard::new(&web_config);
|
||||
crate::cli::build::Build { build: web_config }.build(None, Some(target_directory))
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::{cfg::ConfigOptsServe, BuildResult, Result};
|
||||
use crate::{BuildResult, Result};
|
||||
use dioxus_cli_config::CrateConfig;
|
||||
|
||||
use cargo_metadata::diagnostic::Diagnostic;
|
||||
|
|
Loading…
Reference in a new issue