Skip to content

Commit 5e82b97

Browse files
fix windows
1 parent 56dab5b commit 5e82b97

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

tools/building/src/lib.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
pub mod deps;
2-
1+
use std::path::PathBuf;
32
use std::process;
43

4+
pub mod deps;
5+
56
pub enum Target {
67
Web,
78
Desktop,
@@ -54,19 +55,22 @@ pub fn run(command: &str) -> Result<(), Error> {
5455
run_from(command, None)
5556
}
5657

57-
pub fn run_in_frontend_dir(command: &str) -> Result<(), Error> {
58-
run_from(command, Some("frontend"))
58+
pub fn npm_run_in_frontend_dir(args: &str) -> Result<(), Error> {
59+
let workspace_dir = std::path::PathBuf::from(env!("CARGO_WORKSPACE_DIR"));
60+
let frontend_dir = workspace_dir.join("frontend");
61+
let npm = if cfg!(target_os = "windows") { "npm.cmd" } else { "npm" };
62+
run_from(&format!("{npm} run {args}"), Some(&frontend_dir))
5963
}
6064

61-
pub fn run_from(command: &str, dir: Option<&str>) -> Result<(), Error> {
62-
let workspace_dir = std::path::PathBuf::from(env!("CARGO_WORKSPACE_DIR"));
63-
let dir = if let Some(dir) = dir { workspace_dir.join(dir) } else { workspace_dir };
65+
fn run_from(command: &str, dir: Option<&PathBuf>) -> Result<(), Error> {
6466
let command = command.split_whitespace().collect::<Vec<_>>();
6567
let mut cmd = process::Command::new(command[0]);
6668
if command.len() > 1 {
6769
cmd.args(&command[1..]);
6870
}
69-
cmd.current_dir(dir);
71+
if let Some(dir) = dir {
72+
cmd.current_dir(dir);
73+
}
7074
let exit_code = cmd
7175
.spawn()
7276
.map_err(|e| Error::Io(e, format!("Failed to spawn command '{}'", command.join(" "))))?

tools/building/src/main.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,33 +35,33 @@ fn run_task(task: &Task) -> Result<(), Error> {
3535
deps::check(task)?;
3636

3737
match (&task.target, &task.action, &task.profile) {
38-
(Target::Web, Action::Run, Profile::Debug | Profile::Default) => run_in_frontend_dir("npm run start")?,
39-
(Target::Web, Action::Run, Profile::Release) => run_in_frontend_dir("npm run production")?,
40-
(Target::Web, Action::Run, Profile::Profiling) => run_in_frontend_dir("npm run profiling")?,
38+
(Target::Web, Action::Run, Profile::Debug | Profile::Default) => npm_run_in_frontend_dir("start")?,
39+
(Target::Web, Action::Run, Profile::Release) => npm_run_in_frontend_dir("production")?,
40+
(Target::Web, Action::Run, Profile::Profiling) => npm_run_in_frontend_dir("profiling")?,
4141

42-
(Target::Web, Action::Build, Profile::Debug) => run_in_frontend_dir("npm run build-dev")?,
43-
(Target::Web, Action::Build, Profile::Release | Profile::Default) => run_in_frontend_dir("npm run build")?,
44-
(Target::Web, Action::Build, Profile::Profiling) => run_in_frontend_dir("npm run build-profiling")?,
42+
(Target::Web, Action::Build, Profile::Debug) => npm_run_in_frontend_dir("build-dev")?,
43+
(Target::Web, Action::Build, Profile::Release | Profile::Default) => npm_run_in_frontend_dir("build")?,
44+
(Target::Web, Action::Build, Profile::Profiling) => npm_run_in_frontend_dir("build-profiling")?,
4545

4646
(Target::Desktop, Action::Run, Profile::Debug | Profile::Default) => {
47-
run_in_frontend_dir("npm run build-native-dev")?;
47+
npm_run_in_frontend_dir("build-native-dev")?;
4848
run("cargo run -p third-party-licenses --features desktop")?;
4949
run("cargo run -p graphite-desktop-bundle -- open")?;
5050
}
5151
(Target::Desktop, Action::Run, Profile::Release) => {
52-
run_in_frontend_dir("npm run build-native")?;
52+
npm_run_in_frontend_dir("build-native")?;
5353
run("cargo run -p third-party-licenses --features desktop")?;
5454
run("cargo run -r -p graphite-desktop-bundle -- open")?;
5555
}
5656
(Target::Desktop, Action::Run, Profile::Profiling) => todo!("profiling run for desktop"),
5757

5858
(Target::Desktop, Action::Build, Profile::Debug) => {
59-
run_in_frontend_dir("npm run build-native-dev")?;
59+
npm_run_in_frontend_dir("build-native-dev")?;
6060
run("cargo run -p third-party-licenses --features desktop")?;
6161
run("cargo run -p graphite-desktop-bundle")?;
6262
}
6363
(Target::Desktop, Action::Build, Profile::Release | Profile::Default) => {
64-
run_in_frontend_dir("npm run build-native")?;
64+
npm_run_in_frontend_dir("build-native")?;
6565
run("cargo run -p third-party-licenses --features desktop")?;
6666
run("cargo run -r -p graphite-desktop-bundle")?;
6767
}

0 commit comments

Comments
 (0)