71 lines
2.0 KiB
Rust
71 lines
2.0 KiB
Rust
use std::path::Path;
|
|
use std::process::Command;
|
|
|
|
fn main() {
|
|
let runtime_ts_dir = Path::new("runtime-ts");
|
|
let dist_runtime = runtime_ts_dir.join("dist/runtime.js");
|
|
|
|
if !runtime_ts_dir.exists() {
|
|
println!("cargo::warning=runtime-ts directory not found, using existing runtime.js");
|
|
return;
|
|
}
|
|
|
|
println!("cargo::rerun-if-changed=runtime-ts/src");
|
|
println!("cargo::rerun-if-changed=runtime-ts/package.json");
|
|
println!("cargo::rerun-if-changed=runtime-ts/tsconfig.json");
|
|
println!("cargo::rerun-if-changed=runtime-ts/build.mjs");
|
|
|
|
if !runtime_ts_dir.join("node_modules").exists() {
|
|
println!("Installing npm dependencies...");
|
|
let npm_cmd = if cfg!(target_os = "windows") {
|
|
"npm.cmd"
|
|
} else {
|
|
"npm"
|
|
};
|
|
let status = Command::new(npm_cmd)
|
|
.arg("install")
|
|
.current_dir(runtime_ts_dir)
|
|
.status()
|
|
.expect("Failed to run npm install. Is Node.js installed?");
|
|
|
|
if !status.success() {
|
|
panic!("npm install failed. Please check your Node.js installation.");
|
|
}
|
|
}
|
|
|
|
println!("Running TypeScript type checking...");
|
|
let npm_cmd = if cfg!(target_os = "windows") {
|
|
"npm.cmd"
|
|
} else {
|
|
"npm"
|
|
};
|
|
let status = Command::new(npm_cmd)
|
|
.arg("run")
|
|
.arg("typecheck")
|
|
.current_dir(runtime_ts_dir)
|
|
.status()
|
|
.expect("Failed to run type checking");
|
|
|
|
if !status.success() {
|
|
panic!("TypeScript type checking failed! Fix type errors before building.");
|
|
}
|
|
|
|
println!("Building runtime.js from TypeScript...");
|
|
let status = Command::new(npm_cmd)
|
|
.arg("run")
|
|
.arg("build")
|
|
.current_dir(runtime_ts_dir)
|
|
.status()
|
|
.expect("Failed to build runtime");
|
|
|
|
if !status.success() {
|
|
panic!("Runtime build failed!");
|
|
}
|
|
|
|
if dist_runtime.exists() {
|
|
println!("Successfully built runtime.js",);
|
|
} else {
|
|
panic!("dist/runtime.js not found after build");
|
|
}
|
|
}
|