cli/
cli.rs

1use manganis_cli_support::{AssetManifestExt, ManganisSupportGuard};
2use manganis_common::{AssetManifest, Config};
3
4fn main() {
5    use std::process::Command;
6
7    // This is the location where the assets will be copied to in the filesystem
8    let assets_file_location = "./assets";
9    // This is the location where the assets will be served from
10    let assets_serve_location = "/assets";
11
12    // First set any settings you need for the build
13    Config::default()
14        .with_assets_serve_location(assets_serve_location)
15        .save();
16
17    // Next, tell manganis that you support assets
18    let _guard = ManganisSupportGuard::default();
19
20    // Then build your application
21    Command::new("cargo")
22        .args(["build"])
23        .spawn()
24        .unwrap()
25        .wait()
26        .unwrap();
27
28    // Then collect the assets
29    let manifest = AssetManifest::load(Some("test-package"));
30
31    // Remove the old assets
32    let _ = std::fs::remove_dir_all(assets_file_location);
33
34    // And copy the static assets to the public directory
35    manifest
36        .copy_static_assets_to(assets_file_location)
37        .unwrap();
38
39    // Then collect the tailwind CSS
40    let css = manifest.collect_tailwind_css(true, &mut Vec::new());
41
42    // And write the CSS to the public directory
43    std::fs::write(format!("{}/tailwind.css", assets_file_location), css).unwrap();
44}