From 6b3395b587077941daa156a28e30ee0d9c5d0920 Mon Sep 17 00:00:00 2001 From: core Date: Sat, 13 May 2023 17:21:40 -0400 Subject: [PATCH] fix builds not having proper urls --- Cargo.lock | 10 ++++++++++ spacetime_rs/Cargo.toml | 3 ++- spacetime_rs/src/commands/docker.rs | 24 ++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index ddf9a23ecabfb8815b6242b0bcba295c39f184c2..a01ac55481f412e3543945e87d56907cd094b911 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2990,6 +2990,15 @@ dependencies = [ "libc", ] +[[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" @@ -3167,6 +3176,7 @@ dependencies = [ name = "spacetime" version = "0.1.0" dependencies = [ + "sedregex", "tabwriter", "which", ] diff --git a/spacetime_rs/Cargo.toml b/spacetime_rs/Cargo.toml index 8c87c669b1f2cb913a0b90c1ed96741b2137f62d..3e45c78cf70cd16e1c3367f8a213415848a1ffa9 100644 --- a/spacetime_rs/Cargo.toml +++ b/spacetime_rs/Cargo.toml @@ -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 diff --git a/spacetime_rs/src/commands/docker.rs b/spacetime_rs/src/commands/docker.rs index aee1b4650557f48f0ffb771163221b697323cef5..0229dffff3c638c355d5352c0c0a91a5e8f2a9c0 100644 --- a/spacetime_rs/src/commands/docker.rs +++ b/spacetime_rs/src/commands/docker.rs @@ -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> { // compile the various thingies @@ -13,6 +15,28 @@ fn _build(img: &str, channel: &str, root: &PathBuf) -> Result<(), Box } 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())? }