command to run a command in all extension and app dirs

This commit is contained in:
Carsten Brandt
2015-03-23 15:43:30 +01:00
parent 73652437bb
commit dd3cc91fef

View File

@@ -8,6 +8,7 @@
namespace yii\build\controllers;
use Yii;
use yii\base\InvalidParamException;
use yii\console\Controller;
use yii\helpers\Console;
use yii\helpers\FileHelper;
@@ -77,6 +78,33 @@ class DevController extends Controller
return 0;
}
/**
* Runs a command in all extension and application directories
*
* Can be used to run e.g. `git pull`.
*
* ./build/build dev/run git pull
*
* @param string $command the command to run
*/
public function actionRun($command)
{
$command = implode(' ', func_get_args());
// root of the dev repo
$base = dirname(dirname(__DIR__));
$dirs = $this->listSubDirs("$base/extensions");
$dirs = array_merge($dirs, $this->listSubDirs("$base/apps"));
asort($dirs);
foreach($dirs as $dir) {
$displayDir = substr($dir, strlen($base));
$this->stdout("Running '$command' in $displayDir...\n", Console::BOLD);
passthru($command);
$this->stdout("done.\n", Console::BOLD, Console::FG_GREEN);
}
}
/**
* This command installs an application template in the `apps` directory and links the framework and extensions
*
@@ -234,6 +262,29 @@ class DevController extends Controller
}
}
protected function listSubDirs($dir)
{
$list = [];
$handle = opendir($dir);
if ($handle === false) {
throw new InvalidParamException("Unable to open directory: $dir");
}
while (($file = readdir($handle)) !== false) {
if ($file === '.' || $file === '..') {
continue;
}
// ignore hidden directories
if ($file[0] === '.') {
continue;
}
if (is_dir("$dir/$file")) {
$list[] = "$dir/$file";
}
}
closedir($handle);
return $list;
}
/**
* Finds linkable applications
*