~starkingdoms/starkingdoms

6b3395b587077941daa156a28e30ee0d9c5d0920 — core 2 years ago 03ef6f7
fix builds not having proper urls
3 files changed, 36 insertions(+), 1 deletions(-)

M Cargo.lock
M spacetime_rs/Cargo.toml
M spacetime_rs/src/commands/docker.rs
M Cargo.lock => Cargo.lock +10 -0
@@ 2991,6 2991,15 @@ dependencies = [
]

[[package]]
name = "sedregex"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19411e23596093f03bbd11dc45603b6329bb4bfec77b9fd13e2b9fc9b02efe3e"
dependencies = [
 "regex",
]

[[package]]
name = "semver"
version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"


@@ 3167,6 3176,7 @@ dependencies = [
name = "spacetime"
version = "0.1.0"
dependencies = [
 "sedregex",
 "tabwriter",
 "which",
]

M spacetime_rs/Cargo.toml => spacetime_rs/Cargo.toml +2 -1
@@ 7,4 7,5 @@ edition = "2021"

[dependencies]
tabwriter = "1.2.1"
which = "4.4.0"
\ No newline at end of file
which = "4.4.0"
sedregex = "0.2.5"
\ No newline at end of file

M spacetime_rs/src/commands/docker.rs => spacetime_rs/src/commands/docker.rs +24 -0
@@ 3,8 3,10 @@ use crate::commands::client::build_client_prod;
use crate::commands::server::build_server_prod;
use crate::ninja::exec;
use std::error::Error;
use std::fs;
use std::path::PathBuf;
use std::process::Command;
use sedregex::find_and_replace;

fn _build(img: &str, channel: &str, root: &PathBuf) -> Result<(), Box<dyn Error>> {
    // compile the various thingies


@@ 13,6 15,28 @@ fn _build(img: &str, channel: &str, root: &PathBuf) -> Result<(), Box<dyn Error>
    } else if img == "api" {
        build_api_prod(vec![], root.clone())?;
    } else {
        // we need to swap out the urls
        // TODO
        // for now i am just adding all three to all clients

        // "s/let api_server = \"http:\\/\\/localhost:8080\";/let api_server = \"https:\\/\\/api.${1}.${2}\";/" "$SCRIPT_DIR/client/index.html"
        // "s/let servers = \[\"localhost:3000\"\];/let servers = [\"${1}.${2}\"];/" "$SCRIPT_DIR/client/index.html"

        let (a, b) = match channel {
            "stable" => ("starkingdoms", "tk"),
            _ => (channel, "starkingdoms.tk")
        };

        let mut index_html_path = root.clone().join("client/").join("index.html");

        let index_html_src = fs::read_to_string(&index_html_path)?;
        let index_html_patched = find_and_replace(&index_html_src, &[
            format!("s/let api_server = \"http:\\/\\/localhost:8080\";/let api_server = \"https:\\/\\/api.{}.{}\";/", a, b)
        ])?;

        fs::write(&index_html_path, index_html_patched.as_bytes())?;
        fs::write(index_html_path.join(".orig"), index_html_src)?;

        build_client_prod(vec![], root.clone())?
    }