Browse Source

Prendre en compte 'composer install' pour SPIP 4.2+

master
Matthieu Marcillaud 12 months ago
parent
commit
c40168a18c
  1. 51
      checkout.php

51
checkout.php

@ -1,7 +1,7 @@
#!/usr/bin/env php
<?php
/**
* v 1.7.1
* v 1.8.0
*
* checkout --help
*
@ -14,6 +14,9 @@
* Historique
* ----------
*
* 1.8.0 :
* - On lance composer install sur la commande `spip` (pour SPIP4.2+)
*
* 1.7.1 :
* - Le script nettoie les branches et tags qui ne sont plus présents sur origin (fetch --prune --prune-tags)
*
@ -242,6 +245,8 @@ function interprete_commande($args){
$options['logupdate'] = true;
} elseif (strncmp($a, '-b', 2)==0) {
$options['branche'] = substr($a, 2);
} elseif (strncmp($a, '--no-dev', 8)==0) {
$options['composer-no-dev'] = true;
} else {
if (!isset($options['literal'])){
$options['literal'] = array();
@ -377,6 +382,50 @@ function spip_checkout($source, $dest, $options){
$json = json_decode($json, true);
spip_checkout_plugins_json($json, $url_repo_base, $dest, $branche);
}
if (file_exists("$dest/composer.json")) {
spip_run_composer_install("$dest", $options);
}
}
/**
* S’il y a un require dans le composer.json, on fait une installation.
* permet de cibler SPIP 4.2+
*
* @param string $source
* @param array $options
*/
function spip_run_composer_install($source, $options) {
$json = file_get_contents($source . '/composer.json');
$json = json_decode($json, true);
$requires = $json['require'] ?? [];
$requires = array_filter($requires, function($req) {
return $req !== 'php' and substr($req, 0, 4) !== 'ext-';
}, ARRAY_FILTER_USE_KEY);
if ($requires) {
$composer = spip_find_composer($source);
if ($composer) {
$nodev = (isset($options['composer-no-dev']) and $options['composer-no-dev']) ? '--no-dev' : '';
$command = "cd $source && $composer install $nodev";
echo "\n$command\n";
passthru($command);
echo "\n";
} else {
echo "\n/!\ Composer has not been found.";
echo "\n/!\ Can’t make composer installation.";
}
}
}
function spip_find_composer($source) {
if (file_exists($source . '/composer.phar')) {
return PHP_BINARY . ' composer.phar';
}
exec("which composer", $output, $res);
if ($res === 0) {
return trim(implode($output));
}
return null;
}

Loading…
Cancel
Save