forked from waterwoodwind/cursor-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
60 lines (48 loc) · 1.61 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use std::io::Result;
use std::path::Path;
use std::process::Command;
fn check_and_install_deps() -> Result<()> {
let scripts_dir = Path::new("scripts");
let node_modules = scripts_dir.join("node_modules");
// 如果 node_modules 不存在,运行 npm install
if !node_modules.exists() {
println!("cargo:warning=Installing HTML minifier dependencies...");
let status = Command::new("npm")
.current_dir(scripts_dir)
.arg("install")
.status()?;
if !status.success() {
panic!("Failed to install npm dependencies");
}
println!("cargo:warning=Dependencies installed successfully");
}
Ok(())
}
fn minify_html() -> Result<()> {
println!("cargo:warning=Minifying HTML files...");
let status = Command::new("node")
.args(&["scripts/minify-html.js"])
.status()?;
if !status.success() {
panic!("HTML minification failed");
}
Ok(())
}
fn main() -> Result<()> {
// Proto 文件处理
println!("cargo:rerun-if-changed=src/message.proto");
let mut config = prost_build::Config::new();
config.type_attribute(".", "#[derive(serde::Serialize, serde::Deserialize)]");
config
.compile_protos(&["src/message.proto"], &["src/"])
.unwrap();
// HTML 文件处理
println!("cargo:rerun-if-changed=static/tokeninfo.html");
println!("cargo:rerun-if-changed=scripts/minify-html.js");
println!("cargo:rerun-if-changed=scripts/package.json");
// 检查并安装依赖
check_and_install_deps()?;
// 运行 HTML 压缩
minify_html()?;
Ok(())
}