From 4e17c7125f3396f502cbcacc93f01789d72feca8 Mon Sep 17 00:00:00 2001 From: augushong Date: Sat, 19 Nov 2022 17:03:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E8=B7=AF=E7=94=B1=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=9A=84=E6=89=93=E5=8C=85=E5=8E=8B=E7=BC=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/command/build/Dist.php | 70 ++++++++++++++++++++++++++++++- config/dist.php | 4 +- 2 files changed, 71 insertions(+), 3 deletions(-) diff --git a/app/common/command/build/Dist.php b/app/common/command/build/Dist.php index ef7aacb..1149529 100644 --- a/app/common/command/build/Dist.php +++ b/app/common/command/build/Dist.php @@ -150,6 +150,7 @@ class Dist extends Command $this->buildFunctionFile($lib_function_path); $this->buildMigrateFile(); + $this->buildRouteFile(); $lib_dir_const_file = '/lib.' . uniqid() . '.php'; $lib_dir_const_path = $this->distPath . '/lib' . $lib_dir_const_file; @@ -172,6 +173,69 @@ class Dist extends Command $output->info('打包完成'); } + /** + * 打包路由文件 + * + * @return void + */ + public function buildRouteFile() + { + $route_dir = 'route'; + + $list_files = $this->appFilesystem->listContents($route_dir, true); + + $parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7); + + $prettyPrinter = new MinifyPrinterTools(); + + foreach ($list_files as $item_file) { + if ($item_file['type'] == 'dir') { + continue; + } + + $file_content = $this->appFilesystem->read($item_file['path']); + + $file_stmts = $parser->parse($file_content); + + $traverser = new NodeTraverser(); + $traverser->addVisitor(new class($item_file['path'], $this) extends NodeVisitorAbstract + { + protected $name; + protected $mainClass; + public function __construct($name, $main_class) + { + $this->name = $name; + $this->mainClass = $main_class; + } + + public function leaveNode(Node $node) + { + $name = $this->name; + if ($node instanceof Dir) { + // Clean out the function body + $const_key = 'dirconst' . uniqid(); + + $this->mainClass->constDirList[$const_key] = dirname($name); + return new ConstFetch(new Name($const_key)); + } + + if ($node->hasAttribute('comments')) { + $node->setAttribute('comments', []); + } + } + }); + + $function_code = $prettyPrinter->prettyPrintFile($file_stmts); + + $this->distFilesystem->put($item_file['path'], $function_code); + } + } + + /** + * 处理数据库迁移代码 + * + * @return void + */ public function buildMigrateFile() { $database_dir = 'database'; @@ -629,7 +693,11 @@ class Dist extends Command public function isSkip($path) { - $system_skip_path = ['/app\/common.php/']; + $system_skip_path = [ + '/app\/common.php/', + '/^database\/*/', + '/^route\/*/', + ]; $skip_path = Config::get('dist.skip_path', []); diff --git a/config/dist.php b/config/dist.php index 3bc4d89..45d16b1 100644 --- a/config/dist.php +++ b/config/dist.php @@ -21,7 +21,7 @@ return [ '/^vendor/', '/^config/', '/^lib\//', - '/^database\/*/', + '/event\.php/', '/middleware\.php/', '/provider\.php/', @@ -30,7 +30,7 @@ return [ '/config.php/', '/^public\/index\.php/', '/^public\/router\.php/', - '/^route\/*/', + '/^app\/admin\/service\/initAdminData\/*/', ] ];