[F] Fix cargo publish #405

This commit is contained in:
Azalea Gui 2025-08-21 08:31:32 -04:00
parent 13acc0b6b6
commit 4ac698817d
3 changed files with 21 additions and 12 deletions

View file

@ -1,6 +1,7 @@
use std::env;
use std::fmt::Write as _;
use std::path::Path;
use std::{env, fs};
use std::fs;
use std::path::{Path, PathBuf};
use indexmap::IndexMap;
use regex::Regex;
@ -24,17 +25,25 @@ impl AsciiDistro {
}
fn main() {
let neofetch_path = Path::new(env!("CARGO_WORKSPACE_DIR")).join("neofetch");
// 1. Get workspace and OUT_DIR paths
let workspace_dir = PathBuf::from(env::var_os("CARGO_WORKSPACE_DIR").unwrap());
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
println!(
"cargo:rerun-if-changed={neofetch_path}",
neofetch_path = neofetch_path.display()
);
let src_neofetch = workspace_dir.join("neofetch");
let src_font_logos = workspace_dir.join("hyfetch/data/font_logos.json");
let dst_neofetch = out_dir.join("neofetch");
let dst_font_logos = out_dir.join("font_logos.json");
let out_dir = env::var_os("OUT_DIR").unwrap();
let out_path = Path::new(&out_dir);
// Tell Cargo to re-run if original files change
println!("cargo:rerun-if-changed={}", src_neofetch.display());
println!("cargo:rerun-if-changed={}", src_font_logos.display());
export_distros(neofetch_path, out_path);
// 2. Copy neofetch script and font logos to OUT_DIR
fs::copy(&src_neofetch, &dst_neofetch).expect("Failed to copy neofetch script to OUT_DIR");
fs::copy(&src_font_logos, &dst_font_logos).expect("Failed to copy font logos data to OUT_DIR");
// 3. Export distros from neofetch script
export_distros(&dst_neofetch, &out_dir);
}
fn export_distros<P>(neofetch_path: P, out_path: &Path)

View file

@ -6,7 +6,7 @@ use std::collections::HashMap;
use std::fs::{self, File};
use std::io::{Read, Write};
const FONT_LOGOS: &str = include_str!("../../../hyfetch/data/font_logos.json");
const FONT_LOGOS: &str = include_str!(concat!(env!("OUT_DIR"), "/data/font_logos.json"));
pub fn get_font_logo(backend: Backend) -> Result<String> {
// Check if the cache file exists and return its contents if it does

View file

@ -53,7 +53,7 @@ _/\_\_ _/_/\_
pub const NEOFETCH_COLOR_PATTERNS: [&str; 6] =
["${c1}", "${c2}", "${c3}", "${c4}", "${c5}", "${c6}"];
pub static NEOFETCH_COLORS_AC: OnceLock<AhoCorasick> = OnceLock::new();
pub const NEOFETCH_SCRIPT: &str = include_str!("../../../neofetch");
pub const NEOFETCH_SCRIPT: &str = include_str!(concat!(env!("OUT_DIR"), "/neofetch"));
#[derive(Clone, Eq, PartialEq, Debug, AsRefStr, Deserialize, Serialize)]
#[serde(tag = "mode")]