feat: rewrite runtime.js with typescript

This commit is contained in:
2026-01-02 20:46:07 +08:00
parent d2ed3935ca
commit 210923fd92
28 changed files with 1990 additions and 495 deletions

67
nix-js/build.rs Normal file
View File

@@ -0,0 +1,67 @@
use std::process::Command;
use std::path::Path;
use std::env;
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");
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");
}
// Print build info
if env::var("CARGO_CFG_DEBUG_ASSERTIONS").is_ok() {
println!("Built runtime.js in DEBUG mode");
}
}