diff --git a/README.md b/README.md index 9f1069a5..9702d3d4 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,7 @@ Just run `topgrade`. It will run the following steps: * Node * Run `yarn global update` if yarn is installed. * Run `npm update -g` if NPM is installed and `npm root -g` is a path inside your home directory. +* Run `composer global update` if Composer's home directory is inside the home directory of the user. * Upgrade Atom packages * Run `gem upgrade --user-install` if `~/.gem` exists * *Linux*: Update Flatpak packages diff --git a/src/generic.rs b/src/generic.rs index 598d1b4d..970c2155 100644 --- a/src/generic.rs +++ b/src/generic.rs @@ -3,6 +3,8 @@ use super::terminal::Terminal; use super::utils::{self, Check, PathExt}; use directories::BaseDirs; use failure::Error; +use std::path::PathBuf; +use std::process::Command; const EMACS_UPGRADE: &str = include_str!("emacs.el"); @@ -145,3 +147,39 @@ pub fn run_custom_command(name: &str, command: &str, terminal: &mut Terminal, dr Ok(()) } + +#[must_use] +pub fn run_composer_update( + base_dirs: &BaseDirs, + terminal: &mut Terminal, + dry_run: bool, +) -> Option<(&'static str, bool)> { + if let Some(composer) = utils::which("composer") { + let composer_home = || -> Result { + let output = Command::new(&composer) + .args(&["global", "config", "--absolute", "home"]) + .output()?; + output.status.check()?; + Ok(PathBuf::from(&String::from_utf8(output.stdout)?)) + }(); + + if let Ok(composer_home) = composer_home { + if composer_home.is_descendant_of(base_dirs.home_dir()) { + terminal.print_separator("Composer"); + + let success = || -> Result<(), Error> { + Executor::new(&composer, dry_run) + .args(&["global", "update"]) + .spawn()? + .wait()? + .check()?; + Ok(()) + }().is_ok(); + + return Some(("Composer", success)); + } + } + } + + None +} diff --git a/src/main.rs b/src/main.rs index 9cc63ade..cf44d467 100644 --- a/src/main.rs +++ b/src/main.rs @@ -230,6 +230,10 @@ fn run() -> Result<(), Error> { |terminal| node::run_npm_upgrade(&base_dirs, terminal, opt.dry_run), &mut terminal, )); + report.push_result(execute( + |terminal| generic::run_composer_update(&base_dirs, terminal, opt.dry_run), + &mut terminal, + )); report.push_result(execute( |terminal| node::yarn_global_update(terminal, opt.dry_run), &mut terminal,