mirror of
https://github.com/yiisoft/yii2.git
synced 2025-12-19 07:07:58 +08:00
application release automation
This commit is contained in:
@@ -27,6 +27,10 @@ class PhpDocController extends Controller
|
||||
* for copy and paste.
|
||||
*/
|
||||
public $updateFiles = true;
|
||||
/**
|
||||
* @var bool whether to add copyright header to php files. This should be skipped in application code.
|
||||
*/
|
||||
public $skipFrameworkRequirements = false;
|
||||
|
||||
|
||||
/**
|
||||
@@ -83,7 +87,9 @@ class PhpDocController extends Controller
|
||||
// fix line endings
|
||||
$lines = preg_split('/(\r\n|\n|\r)/', $contents);
|
||||
|
||||
$this->fixFileDoc($lines);
|
||||
if (!$this->skipFrameworkRequirements) {
|
||||
$this->fixFileDoc($lines);
|
||||
}
|
||||
$this->fixDocBlockIndentation($lines);
|
||||
$lines = array_values($this->fixLineSpacing($lines));
|
||||
|
||||
@@ -105,7 +111,7 @@ class PhpDocController extends Controller
|
||||
*/
|
||||
public function options($actionID)
|
||||
{
|
||||
return array_merge(parent::options($actionID), ['updateFiles']);
|
||||
return array_merge(parent::options($actionID), ['updateFiles', 'skipFrameworkRequirements']);
|
||||
}
|
||||
|
||||
protected function findFiles($root, $needsInclude = true)
|
||||
@@ -169,11 +175,7 @@ class PhpDocController extends Controller
|
||||
} elseif (preg_match('~extensions/([\w\d-]+)[\\\\/]?$~', $root, $matches)) {
|
||||
|
||||
$extensionPath = dirname(rtrim($root, '\\/'));
|
||||
foreach (scandir($extensionPath) as $extension) {
|
||||
if (ctype_alpha($extension) && is_dir($extensionPath . '/' . $extension)) {
|
||||
Yii::setAlias("@yii/$extension", "$extensionPath/$extension");
|
||||
}
|
||||
}
|
||||
$this->setUpExtensionAliases($extensionPath);
|
||||
|
||||
list(, $extension) = $matches;
|
||||
Yii::setAlias("@yii/$extension", "$root");
|
||||
@@ -194,6 +196,22 @@ class PhpDocController extends Controller
|
||||
// if ($extension === 'composer') {
|
||||
// return [];
|
||||
// }
|
||||
} elseif (preg_match('~apps/([\w\d-]+)[\\\\/]?$~', $root, $matches)) {
|
||||
|
||||
$extensionPath = dirname(dirname(rtrim($root, '\\/'))) . '/extensions';
|
||||
$this->setUpExtensionAliases($extensionPath);
|
||||
|
||||
list(, $appName) = $matches;
|
||||
Yii::setAlias("@app-$appName", "$root");
|
||||
if (is_file($autoloadFile = Yii::getAlias("@app-$appName/vendor/autoload.php"))) {
|
||||
include($autoloadFile);
|
||||
}
|
||||
|
||||
$except[] = '/runtime/';
|
||||
$except[] = '/vendor/';
|
||||
$except[] = '/tests/';
|
||||
$except[] = '/docs/';
|
||||
|
||||
}
|
||||
$root = FileHelper::normalizePath($root);
|
||||
$options = [
|
||||
@@ -219,6 +237,15 @@ class PhpDocController extends Controller
|
||||
return FileHelper::findFiles($root, $options);
|
||||
}
|
||||
|
||||
private function setUpExtensionAliases($extensionPath)
|
||||
{
|
||||
foreach (scandir($extensionPath) as $extension) {
|
||||
if (ctype_alpha($extension) && is_dir($extensionPath . '/' . $extension)) {
|
||||
Yii::setAlias("@yii/$extension", "$extensionPath/$extension");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix file PHPdoc
|
||||
*/
|
||||
@@ -459,7 +486,11 @@ class PhpDocController extends Controller
|
||||
|
||||
if (!$ref->isSubclassOf('yii\base\Object') && $className != 'yii\base\Object') {
|
||||
$this->stderr("[INFO] Skipping class $className as it is not a subclass of yii\\base\\Object.\n", Console::FG_BLUE, Console::BOLD);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($ref->isSubclassOf('yii\db\BaseActiveRecord')) {
|
||||
$this->stderr("[INFO] Skipping class $className as it is an ActiveRecord class, property handling is not supported yet.\n", Console::FG_BLUE, Console::BOLD);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -484,11 +515,13 @@ class PhpDocController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
if (!$seenSince) {
|
||||
$this->stderr("[ERR] No @since found in class doc in file: $file\n", Console::FG_RED);
|
||||
}
|
||||
if (!$seenAuthor) {
|
||||
$this->stderr("[ERR] No @author found in class doc in file: $file\n", Console::FG_RED);
|
||||
if (!$this->skipFrameworkRequirements) {
|
||||
if (!$seenSince) {
|
||||
$this->stderr("[ERR] No @since found in class doc in file: $file\n", Console::FG_RED);
|
||||
}
|
||||
if (!$seenAuthor) {
|
||||
$this->stderr("[ERR] No @author found in class doc in file: $file\n", Console::FG_RED);
|
||||
}
|
||||
}
|
||||
|
||||
if (trim($oldDoc) != trim($newDoc)) {
|
||||
@@ -563,6 +596,12 @@ class PhpDocController extends Controller
|
||||
unset($lines[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
// if no properties or other tags where present add properties at the end
|
||||
if ($propertyPosition === false) {
|
||||
$propertyPosition = count($lines) - 2;
|
||||
}
|
||||
|
||||
$finalDoc = '';
|
||||
foreach ($lines as $i => $line) {
|
||||
$finalDoc .= $line . "\n";
|
||||
|
||||
Reference in New Issue
Block a user