From 78ead61684689ecc1ff24eb1d7715e6c6a4f1e69 Mon Sep 17 00:00:00 2001 From: augushong Date: Sat, 19 Nov 2022 16:48:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E8=BF=81=E7=A7=BB=E6=89=93=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/command/build/Dist.php | 60 ++++++++++++++++++++++++++ extend/think/log/driver/DebugMysql.php | 2 +- 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/app/common/command/build/Dist.php b/app/common/command/build/Dist.php index 2323001..ef7aacb 100644 --- a/app/common/command/build/Dist.php +++ b/app/common/command/build/Dist.php @@ -149,6 +149,7 @@ class Dist extends Command $lib_function_path = $this->distPath . '/lib' . $lib_function_file; $this->buildFunctionFile($lib_function_path); + $this->buildMigrateFile(); $lib_dir_const_file = '/lib.' . uniqid() . '.php'; $lib_dir_const_path = $this->distPath . '/lib' . $lib_dir_const_file; @@ -166,9 +167,68 @@ class Dist extends Command $this->buildAllAppDir(); + + $output->info('打包完成'); } + public function buildMigrateFile() + { + $database_dir = 'database'; + + $list_files = $this->appFilesystem->listContents($database_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', []); + } + } + }); + + + $file_stmts = $traverser->traverse($file_stmts); + + $function_code = $prettyPrinter->prettyPrintFile($file_stmts); + + $this->distFilesystem->put($item_file['path'], $function_code); + } + } + /** * 打包标准类文件(核心) diff --git a/extend/think/log/driver/DebugMysql.php b/extend/think/log/driver/DebugMysql.php index cbd9ac6..e1be62a 100644 --- a/extend/think/log/driver/DebugMysql.php +++ b/extend/think/log/driver/DebugMysql.php @@ -40,7 +40,7 @@ class DebugMysql implements LogHandlerInterface $dirname = dirname($log_path); if (!is_dir($dirname)) { - mkdir($log_path, 0777, true); + mkdir($dirname, 0777, true); } $first_line = false;