bevy_remote_wasm 0.1.0

Wasm transport for the Bevy Remote Protocol
Documentation
use std::path::PathBuf;

const TS_IN_FILES: &[&str] = &[
    "bevy-remote-wasm-types/bridge.d.ts",
    "bevy-remote-wasm-types/builtin.d.ts",
];
const TS_OUT_FILE: &str = "ts_types.d.ts";

fn main() {
    // The `bevy-remote-wasm::TS_TYPES` constant is used by wasm-bindgen to add
    // TypeScript definitions to generated bindings.
    // - The issue: some files contain "import" lines, which are not valid for
    // verbatim output since all types land in the same generated file.
    // - The solution: combine all files, dropping the "import" lines.
    let combined = TS_IN_FILES
        .iter()
        .filter_map(|file| {
            std::fs::read_to_string(file)
                .inspect_err(|err| println!("cargo::error=input {file}: {err}"))
                .map(|content| {
                    content
                        .lines()
                        .filter(|line| !line.trim_start().starts_with("import "))
                        .collect::<Vec<_>>()
                        .join("\n")
                })
                .ok()
        })
        .collect::<Vec<_>>()
        .join("\n");

    let out_file = PathBuf::from(std::env::var("OUT_DIR").unwrap()).join(TS_OUT_FILE);
    let _ =
        std::fs::write(&out_file, combined).inspect_err(|err| println!("cargo::error=output file {out_file:?}: {err}"));

    TS_IN_FILES
        .iter()
        .for_each(|file| println!("cargo::rerun-if-changed={file}"));
}