Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Run composer (fix #71)
Browse files Browse the repository at this point in the history
  • Loading branch information
r-darwish committed Oct 2, 2018
1 parent e9e743a commit 4cc0762
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 38 additions & 0 deletions src/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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<PathBuf, Error> {
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
}
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 4cc0762

Please sign in to comment.