From 2620e444201ef2131a07a94e0ec890f29f310d1c Mon Sep 17 00:00:00 2001 From: augushong Date: Sat, 24 Sep 2022 10:50:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=88=A0=E9=99=A4=E4=B8=B4?= =?UTF-8?q?=E6=97=B6=E7=9B=AE=E5=BD=95=E7=9A=84=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/command/admin/Clear.php | 52 ++++++++++++++++++++++++++++++ config/console.php | 4 ++- 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 app/common/command/admin/Clear.php diff --git a/app/common/command/admin/Clear.php b/app/common/command/admin/Clear.php new file mode 100644 index 0000000..81056e3 --- /dev/null +++ b/app/common/command/admin/Clear.php @@ -0,0 +1,52 @@ +setName('admin:clear') + ->setDescription('删除开发临时生成目录'); + } + + protected function execute(Input $input, Output $output) + { + // 指令输出 + $output->writeln('删除测试目录'); + + + $command_line = ''; + + $dir = App::getRootPath() . '/runtime/source/'; + + if (!is_dir($dir)) { + $output->writeln('删除成功'); + return; + } + + if (strpos(strtolower(PHP_OS), 'win') === 0) { + $command_line = implode(' ', ['rd', '/s', '/q', str_replace('/', '\\', $dir)]); + } else { + $command_line = implode(' ', ['rm', '-rf', $dir]); + } + + $output->info('删除目录:' . $command_line); + + $output->info('run command: ' . $command_line); + + exec($command_line); + + $output->info('删除成功'); + } +} diff --git a/config/console.php b/config/console.php index 1acfddc..0652cad 100644 --- a/config/console.php +++ b/config/console.php @@ -3,6 +3,7 @@ // | 控制台配置 // +---------------------------------------------------------------------- +use app\common\command\admin\Clear; use app\common\command\admin\Version; use app\common\command\admin\ResetPassword; use app\common\command\curd\Migrate; @@ -17,6 +18,7 @@ return [ ResetPassword::class, Timer::class, Version::class, - Migrate::class + Migrate::class, + Clear::class ], ];