From 75521d1c50cdae34f81b620d2d5fa641ac437188 Mon Sep 17 00:00:00 2001 From: Lynn Date: Thu, 3 Nov 2022 01:53:31 +0100 Subject: [PATCH 1/2] Call yarn as "yarn.cmd" on Windows --- create-rust-app_cli/template/.cargo/bin/fullstack.rs | 8 +++++++- create-rust-app_cli/template/.cargo/bin/tsync.rs | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/create-rust-app_cli/template/.cargo/bin/fullstack.rs b/create-rust-app_cli/template/.cargo/bin/fullstack.rs index ba316988..94da7c6a 100644 --- a/create-rust-app_cli/template/.cargo/bin/fullstack.rs +++ b/create-rust-app_cli/template/.cargo/bin/fullstack.rs @@ -1,6 +1,12 @@ use std::io; use std::process::Command; +#[cfg(windows)] +pub const YARN_COMMAND: &'static str = "yarn.cmd"; + +#[cfg(not(windows))] +pub const YARN_COMMAND: &'static str = "yarn"; + pub fn main() -> Result<(), io::Error> { if !create_rust_app::net::is_port_free(21012) { println!("========================================================"); @@ -10,7 +16,7 @@ pub fn main() -> Result<(), io::Error> { panic!("Port 21012 is taken but is required for development!") } - Command::new("yarn") + Command::new(YARN_COMMAND) .arg("fullstack") .current_dir("frontend") .spawn() diff --git a/create-rust-app_cli/template/.cargo/bin/tsync.rs b/create-rust-app_cli/template/.cargo/bin/tsync.rs index e79849c0..de468adc 100644 --- a/create-rust-app_cli/template/.cargo/bin/tsync.rs +++ b/create-rust-app_cli/template/.cargo/bin/tsync.rs @@ -2,12 +2,18 @@ use std::io; use std::process::Command; use std::path::PathBuf; +#[cfg(windows)] +pub const YARN_COMMAND: &'static str = "yarn.cmd"; + +#[cfg(not(windows))] +pub const YARN_COMMAND: &'static str = "yarn"; + pub fn main() -> Result<(), io::Error> { let dir = env!("CARGO_MANIFEST_DIR"); println!("Running `yarn tsync` in `$project_dir/frontend/`..."); - Command::new("yarn") + Command::new(YARN_COMMAND) .arg("tsync") .current_dir(PathBuf::from_iter([dir, "frontend"])) .spawn() From fe45a4091fa09e47d5e82b8040cd0340ea8b7b75 Mon Sep 17 00:00:00 2001 From: Lynn Date: Thu, 3 Nov 2022 02:14:25 +0100 Subject: [PATCH 2/2] Rename template/.cargo/bin binaries to avoid "tsync" collision --- create-rust-app_cli/src/content/project.rs | 8 ++++---- .../.cargo/bin/{fullstack.rs => run_yarn_fullstack.rs} | 0 .../template/.cargo/bin/{tsync.rs => run_yarn_tsync.rs} | 0 create-rust-app_cli/template/.cargo/config | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) rename create-rust-app_cli/template/.cargo/bin/{fullstack.rs => run_yarn_fullstack.rs} (100%) rename create-rust-app_cli/template/.cargo/bin/{tsync.rs => run_yarn_tsync.rs} (100%) diff --git a/create-rust-app_cli/src/content/project.rs b/create-rust-app_cli/src/content/project.rs index 85b95baa..914eaf0c 100644 --- a/create-rust-app_cli/src/content/project.rs +++ b/create-rust-app_cli/src/content/project.rs @@ -80,12 +80,12 @@ fn add_bins_to_cargo_toml(project_dir: &std::path::PathBuf) -> Result<(), std::i let append_to_toml = format!( r#" [[bin]] -name = "fullstack" -path = ".cargo/bin/fullstack.rs" +name = "run_yarn_fullstack" +path = ".cargo/bin/run_yarn_fullstack.rs" [[bin]] -name = "tsync" -path = ".cargo/bin/tsync.rs" +name = "run_yarn_tsync" +path = ".cargo/bin/run_yarn_tsync.rs" [[bin]] name = "{project_name}" diff --git a/create-rust-app_cli/template/.cargo/bin/fullstack.rs b/create-rust-app_cli/template/.cargo/bin/run_yarn_fullstack.rs similarity index 100% rename from create-rust-app_cli/template/.cargo/bin/fullstack.rs rename to create-rust-app_cli/template/.cargo/bin/run_yarn_fullstack.rs diff --git a/create-rust-app_cli/template/.cargo/bin/tsync.rs b/create-rust-app_cli/template/.cargo/bin/run_yarn_tsync.rs similarity index 100% rename from create-rust-app_cli/template/.cargo/bin/tsync.rs rename to create-rust-app_cli/template/.cargo/bin/run_yarn_tsync.rs diff --git a/create-rust-app_cli/template/.cargo/config b/create-rust-app_cli/template/.cargo/config index 662714ca..ed5e15fc 100644 --- a/create-rust-app_cli/template/.cargo/config +++ b/create-rust-app_cli/template/.cargo/config @@ -1,6 +1,6 @@ [alias] -fullstack="run --bin fullstack" -tsync="run --bin tsync" +fullstack="run --bin run_yarn_fullstack" +tsync="run --bin run_yarn_tsync" [build] target-dir=".cargo/.build"