chore: 新增项目规则文档、构建别名及忽略规则 添加 AGENTS.md 项目规则文件,涵盖语言与工具链、模块设计、 Git 提交规范及验证流程等内容。 变更要点: - .cargo/config.toml 新增 xtask 命令别名 - .gitignore 忽略运行时地图缓存、接收器配置文件、 构建锁文件及本地 docs/ 目录 - 新增 AGENTS.md 定义项目编码、提交与审查规则 ```
61 lines
2.0 KiB
Rust
61 lines
2.0 KiB
Rust
use std::{
|
|
env, fs,
|
|
path::{Path, PathBuf},
|
|
};
|
|
|
|
fn collect(root: &Path, folder: &Path, output: &mut String) {
|
|
let mut files: Vec<_> = fs::read_dir(folder)
|
|
.expect("frontend assets")
|
|
.map(|f| f.unwrap().path())
|
|
.collect();
|
|
files.sort();
|
|
for path in files {
|
|
if path.file_name().unwrap().to_string_lossy().starts_with('.') {
|
|
continue;
|
|
}
|
|
assert!(!path.is_symlink(), "frontend assets must not be symlinks");
|
|
if path.is_dir() {
|
|
collect(root, &path, output);
|
|
continue;
|
|
}
|
|
let relative = path
|
|
.strip_prefix(root)
|
|
.unwrap()
|
|
.to_string_lossy()
|
|
.replace('\\', "/");
|
|
let mime = match path.extension().and_then(|e| e.to_str()).unwrap_or("") {
|
|
"html" => "text/html; charset=utf-8",
|
|
"js" | "mjs" => "text/javascript; charset=utf-8",
|
|
"wasm" => "application/wasm",
|
|
"css" => "text/css; charset=utf-8",
|
|
"png" => "image/png",
|
|
"svg" => "image/svg+xml",
|
|
"json" => "application/json",
|
|
_ => continue,
|
|
};
|
|
output.push_str(&format!(
|
|
"{:?} => Some((include_bytes!({:?}), {:?})),\n",
|
|
format!("/{relative}"),
|
|
path.to_string_lossy(),
|
|
mime
|
|
));
|
|
}
|
|
}
|
|
fn main() {
|
|
let root = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()).join("dist/web-ui");
|
|
println!("cargo:rerun-if-changed={}", root.display());
|
|
assert!(
|
|
root.join("index.html").is_file(),
|
|
"Build Rust frontend first: cargo xtask web"
|
|
);
|
|
let mut output = r#"pub fn resource(path: &str) -> Option<(&'static [u8], &'static str)> { let path = if path == "/" || path == "/realtime" { "/index.html" } else { path }; match path {
|
|
"#.to_owned();
|
|
collect(&root, &root, &mut output);
|
|
output.push_str("_ => None } }\n");
|
|
fs::write(
|
|
PathBuf::from(env::var("OUT_DIR").unwrap()).join("web_assets.rs"),
|
|
output,
|
|
)
|
|
.unwrap();
|
|
}
|