mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-27 20:40:22 +08:00
command to run a command in all extension and app dirs
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
namespace yii\build\controllers;
|
namespace yii\build\controllers;
|
||||||
|
|
||||||
use Yii;
|
use Yii;
|
||||||
|
use yii\base\InvalidParamException;
|
||||||
use yii\console\Controller;
|
use yii\console\Controller;
|
||||||
use yii\helpers\Console;
|
use yii\helpers\Console;
|
||||||
use yii\helpers\FileHelper;
|
use yii\helpers\FileHelper;
|
||||||
@@ -77,6 +78,33 @@ class DevController extends Controller
|
|||||||
return 0;
|
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
|
* 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
|
* Finds linkable applications
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user