mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-09 19:42:47 +08:00
完成打包和最小化格式化
This commit is contained in:
@@ -74,7 +74,6 @@ if (!function_exists('xdebug')) {
|
||||
function xdebug($data, $type = 'xdebug', $suffix = null, $force = false, $file = null)
|
||||
{
|
||||
// 调试
|
||||
__DIR__;
|
||||
!is_dir(runtime_path() . 'xdebug/') && mkdir(runtime_path() . 'xdebug/');
|
||||
if (is_null($file)) {
|
||||
$file = is_null($suffix) ? runtime_path() . 'xdebug/' . date('Ymd') . '.txt' : runtime_path() . 'xdebug/' . date('Ymd') . "_{$suffix}" . '.txt';
|
||||
|
||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace app\common\command\build;
|
||||
|
||||
use app\common\tools\PathTools;
|
||||
use app\common\tools\phpparser\MinifyPrinterTools;
|
||||
use app\common\tools\phpparser\NodeVisitorTools;
|
||||
use League\Flysystem\Adapter\Local;
|
||||
use League\Flysystem\Filesystem;
|
||||
@@ -158,9 +159,9 @@ class Dist extends Command
|
||||
PathTools::intiDir($lib_php_path);
|
||||
|
||||
$this->buildIncludeIndexFile([
|
||||
$lib_function_file,
|
||||
$lib_dir_const_file,
|
||||
$lib_php_file,
|
||||
$lib_function_file,
|
||||
]);
|
||||
|
||||
|
||||
@@ -206,18 +207,13 @@ class Dist extends Command
|
||||
));
|
||||
}
|
||||
|
||||
$prettyPrinter = new Standard();
|
||||
$prettyPrinter = new MinifyPrinterTools();
|
||||
|
||||
$dir_const_code = $prettyPrinter->prettyPrintFile($dir_const_stmts);
|
||||
|
||||
file_put_contents($lib_dir_const_path, $dir_const_code);
|
||||
}
|
||||
|
||||
public function buildDirConstCode($stmt)
|
||||
{
|
||||
# code...
|
||||
}
|
||||
|
||||
public function buildFunctionFile($lib_function_path)
|
||||
{
|
||||
$function_path = Config::get('dist.function_path', []);
|
||||
@@ -257,8 +253,8 @@ class Dist extends Command
|
||||
return new ConstFetch(new Name($const_key));
|
||||
}
|
||||
|
||||
if($node instanceof Comment){
|
||||
return NodeTraverser::REMOVE_NODE;
|
||||
if ($node->hasAttribute('comments')) {
|
||||
$node->setAttribute('comments', []);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -272,7 +268,7 @@ class Dist extends Command
|
||||
}
|
||||
|
||||
|
||||
$prettyPrinter = new Standard();
|
||||
$prettyPrinter = new MinifyPrinterTools();
|
||||
|
||||
$function_code = $prettyPrinter->prettyPrintFile($function_stmts);
|
||||
|
||||
@@ -303,7 +299,7 @@ class Dist extends Command
|
||||
foreach ($files as $file_name) {
|
||||
$file_stmts[] = new Expression(new Include_(new Concat(new Dir, new String_($file_name)), Include_::TYPE_REQUIRE_ONCE));
|
||||
}
|
||||
$prettyPrinter = new Standard();
|
||||
$prettyPrinter = new MinifyPrinterTools();
|
||||
|
||||
|
||||
$newCode = $prettyPrinter->prettyPrintFile($file_stmts);
|
||||
|
||||
47
app/common/tools/phpparser/MinifyPrinterTools.php
Normal file
47
app/common/tools/phpparser/MinifyPrinterTools.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\tools\phpparser;
|
||||
|
||||
|
||||
class MinifyPrinterTools extends PrettyPrinterTools
|
||||
{
|
||||
/**
|
||||
* Reset pretty printing state.
|
||||
*/
|
||||
protected function resetState()
|
||||
{
|
||||
$this->indentLevel = 0;
|
||||
$this->nl = "";
|
||||
$this->origTokens = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set indentation level
|
||||
*
|
||||
* @param int $level Level in number of spaces
|
||||
*/
|
||||
protected function setIndentLevel(int $level)
|
||||
{
|
||||
$this->indentLevel = $level;
|
||||
$this->nl = "" . \str_repeat('', $level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Increase indentation level.
|
||||
*/
|
||||
protected function indent()
|
||||
{
|
||||
$this->indentLevel += 4;
|
||||
$this->nl .= '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrease indentation level.
|
||||
*/
|
||||
protected function outdent()
|
||||
{
|
||||
assert($this->indentLevel >= 4);
|
||||
$this->indentLevel -= 4;
|
||||
$this->nl = "" . str_repeat('', $this->indentLevel);
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,9 @@ return [
|
||||
// 全局函数库,否则无论是否以/开头,都以项目根目录开头定位,如果有其他的文件,在这里声明
|
||||
// 不支持项目以外的位置定义
|
||||
// 只能包含函数,不支持命名空间
|
||||
// 这些代码不能包含__DIR__、__FILE__等代码位置常量,不会影响打包,但代码逻辑会被破坏
|
||||
// 将忽略注释和注解,代码业务请不要依赖注解
|
||||
// 这些代码将忽略include、require表达式,所以如果用include 方式引入其他函数库,要在这里声明,
|
||||
// !如果使用include方式读取文件内容或配置,将失败
|
||||
// !将忽略注释和注解,代码业务请不要依赖注解
|
||||
'function_path' => [
|
||||
'app/common.php'
|
||||
],
|
||||
@@ -14,6 +15,7 @@ return [
|
||||
'/^\.git/',
|
||||
'/^dist/',
|
||||
'/^runtime/',
|
||||
'/app\/common.php/',
|
||||
],
|
||||
// 支持正则表达式,将文件原封不动的挪到输出目录
|
||||
'ignore_path' => [
|
||||
@@ -26,7 +28,6 @@ return [
|
||||
'/provider\.php/',
|
||||
'/service\.php/',
|
||||
'/^app\/.*\/config\/.*/',
|
||||
'/app\/common.php/',
|
||||
'/config.php/',
|
||||
'/^public\/index\.php/',
|
||||
'/^public\/router\.php/',
|
||||
|
||||
Reference in New Issue
Block a user