You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.6 KiB
Rust
60 lines
1.6 KiB
Rust
use std::fs::File;
|
|
use std::io::Write;
|
|
|
|
fn main() {
|
|
write_version_file();
|
|
|
|
write_monologues_file();
|
|
}
|
|
|
|
fn write_version_file() {
|
|
use chrono::prelude::*;
|
|
use std::process::Command;
|
|
|
|
// Date of build
|
|
let now = Utc::now().format("%Y%m%d%H%M%S");
|
|
|
|
// Latest commit ID
|
|
let git_sha = String::from_utf8(
|
|
Command::new("git")
|
|
.arg("rev-parse")
|
|
.arg("--short")
|
|
.arg("HEAD")
|
|
.output()
|
|
.expect("Failed to get git sha")
|
|
.stdout,
|
|
)
|
|
.expect("Read stdout from git sha command");
|
|
|
|
// If the workspace is dirty or clean
|
|
let clean = Command::new("git")
|
|
.arg("diff")
|
|
.arg("--quiet")
|
|
.status()
|
|
.expect("Failed to run git diff")
|
|
.success();
|
|
|
|
let mut file = File::create("VERSION").expect("Create VERSION file");
|
|
|
|
if clean {
|
|
write!(file, "0.0.0-{now}+{}", git_sha.trim()).expect("Write version to VERSION file");
|
|
} else {
|
|
write!(file, "0.0.0-{now}+{}-dirty", git_sha.trim())
|
|
.expect("Write version to VERSION file");
|
|
}
|
|
}
|
|
|
|
fn write_monologues_file() {
|
|
let mut file = File::create("assets/trees/MONOLOGUES").expect("Create MONOLOGUES file");
|
|
|
|
walkdir::WalkDir::new("assets/trees")
|
|
.into_iter()
|
|
.filter_map(|entry| entry.ok())
|
|
.filter(|entry| {
|
|
entry.path().extension() == Some(std::ffi::OsStr::new("mono"))
|
|
})
|
|
.for_each(|entry| {
|
|
let _ = writeln!(file, "{}", entry.path().to_string_lossy().strip_prefix("assets/").unwrap());
|
|
});
|
|
}
|