From fb93cd5a03219103ecdfb2d46feae9ac179cd916 Mon Sep 17 00:00:00 2001 From: Danny Browning Date: Fri, 22 Sep 2023 12:40:27 -0600 Subject: [PATCH] Global install --- cli/src/install/ceramic_app_template.rs | 2 +- cli/src/install/ceramic_daemon.rs | 2 +- cli/src/install/compose_db.rs | 2 +- cli/src/install/npm.rs | 7 ++++++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cli/src/install/ceramic_app_template.rs b/cli/src/install/ceramic_app_template.rs index 9ea1098..6d7bd63 100644 --- a/cli/src/install/ceramic_app_template.rs +++ b/cli/src/install/ceramic_app_template.rs @@ -44,7 +44,7 @@ pub async fn install_ceramic_app_template( tokio::fs::rename(&unzip_dir, &output_dir).await?; - npm_install(&output_dir, &None).await?; + npm_install(&output_dir, &None, false).await?; let readme = output_dir.join("README.md"); let mut f = tokio::fs::OpenOptions::new() diff --git a/cli/src/install/ceramic_daemon.rs b/cli/src/install/ceramic_daemon.rs index 41b4b2b..4899020 100644 --- a/cli/src/install/ceramic_daemon.rs +++ b/cli/src/install/ceramic_daemon.rs @@ -39,7 +39,7 @@ pub async fn install_ceramic_daemon( if let Some(v) = version.as_ref() { program.push_str(&format!("@{}", v.to_string())); } - npm_install_package(&working_directory, &program).await?; + npm_install_package(&working_directory, &program, true).await?; let ans = match start_ceramic { Some(true) => true, diff --git a/cli/src/install/compose_db.rs b/cli/src/install/compose_db.rs index 8109e64..1b88ced 100644 --- a/cli/src/install/compose_db.rs +++ b/cli/src/install/compose_db.rs @@ -30,7 +30,7 @@ pub async fn install_compose_db( if let Some(v) = version.as_ref() { program.push_str(&format!("@{}", v.to_string())); } - npm_install_package(working_directory, &program).await?; + npm_install_package(working_directory, &program, true).await?; let env_file = working_directory.join("composedb.env"); let mut f = tokio::fs::OpenOptions::new() diff --git a/cli/src/install/npm.rs b/cli/src/install/npm.rs index d5a6d99..7d3622d 100644 --- a/cli/src/install/npm.rs +++ b/cli/src/install/npm.rs @@ -5,6 +5,7 @@ use tokio::process::Command; pub async fn npm_install_package( working_directory: impl AsRef, package: &str, + globally: bool, ) -> anyhow::Result<()> { let status = Command::new("npm") .args(&["init", "--yes"]) @@ -16,7 +17,7 @@ pub async fn npm_install_package( anyhow::bail!("Failed to init npm, cannot download {}", package); } - npm_install(working_directory, &Some(&package)).await?; + npm_install(working_directory, &Some(&package), globally).await?; Ok(()) } @@ -24,9 +25,13 @@ pub async fn npm_install_package( pub async fn npm_install( working_directory: impl AsRef, package: &Option<&str>, + globally: bool, ) -> anyhow::Result<()> { let msg = "Installing dependencies"; let mut args = vec!["install"]; + if globally { + args.push("-g"); + } let msg = if let Some(p) = package { args.push(p); format!("{} for {}", msg, p)