Skip to content

Commit

Permalink
command to run a command in all extension and app dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
cebe committed Mar 23, 2015
1 parent 7365243 commit dd3cc91
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions build/controllers/DevController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -77,6 +78,33 @@ public function actionAll()
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
*
Expand Down Expand Up @@ -234,6 +262,29 @@ protected function unlink($file)
}
}

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
*
Expand Down

0 comments on commit dd3cc91

Please sign in to comment.