use std::path::{Path, PathBuf};
use anyhow::Result;
use async_fs as fs;
use futures_lite::prelude::*;
pub fn remove_source_file_ext(path: &Path) -> PathBuf {
if path
.extension()
.is_some_and(|ext| matches!(ext.to_str(), Some("lua" | "luau")))
{
path.with_extension("")
} else {
path.to_path_buf()
}
}
pub async fn write_executable_file_to(
path: impl AsRef<Path>,
bytes: impl AsRef<[u8]>,
) -> Result<(), std::io::Error> {
let mut options = fs::OpenOptions::new();
options.write(true).create(true).truncate(true);
#[cfg(unix)]
{
use fs::unix::OpenOptionsExt;
options.mode(0o755); }
let mut file = options.open(path).await?;
file.write_all(bytes.as_ref()).await?;
file.flush().await?;
Ok(())
}