Skip to content

Commit

Permalink
WIP: trial building assets
Browse files Browse the repository at this point in the history
  • Loading branch information
brianmay committed Dec 22, 2024
1 parent 01ebccc commit db5640c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
30 changes: 30 additions & 0 deletions packages/cli/src/cli/build_assets.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use std::path::PathBuf;

use crate::{Result, StructuredOutput};
use clap::Parser;
use dioxus_cli_opt::AssetManifest;

#[derive(Clone, Debug, Parser)]
pub struct BuildAssets {
/// The source executable to build assets for.
pub(crate) executable: PathBuf,

/// The destination directory for the assets
pub(crate) destination: PathBuf,
}

impl BuildAssets {
pub async fn run(self) -> Result<StructuredOutput> {
let assets =
AssetManifest::load_from_file(&self.executable).expect("Failed to load asset manifest");

for (key, value) in assets.assets.iter() {
let path = self.destination.join(key);
println!("Writing asset to {path:?} {value:?}");

// std::fs::write(path, &value.data).expect("Failed to write asset");
}

Ok(StructuredOutput::Success)
}
}
6 changes: 6 additions & 0 deletions packages/cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub(crate) mod autoformat;
pub(crate) mod build;
pub(crate) mod build_assets;
pub(crate) mod bundle;
pub(crate) mod check;
pub(crate) mod clean;
Expand Down Expand Up @@ -95,6 +96,10 @@ pub(crate) enum Commands {
#[clap(subcommand)]
#[clap(name = "config")]
Config(config::Config),

/// Build the assets for a specific target.
#[clap(name = "build_assets")]
BuildAssets(build_assets::BuildAssets),
}

impl Display for Commands {
Expand All @@ -112,6 +117,7 @@ impl Display for Commands {
Commands::Bundle(_) => write!(f, "bundle"),
Commands::Run(_) => write!(f, "run"),
Commands::Doctor(_) => write!(f, "doctor"),
Commands::BuildAssets(_) => write!(f, "build_assets"),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ async fn main() {
Commands::Bundle(opts) => opts.bundle().await,
Commands::Run(opts) => opts.run().await,
Commands::Doctor(opts) => opts.run().await,
Commands::BuildAssets(opts) => opts.run().await,
};

// Provide a structured output for third party tools that can consume the output of the CLI
Expand Down

0 comments on commit db5640c

Please sign in to comment.