toolbox-aoaostar/app/command/PluginPackage.php
AOAOSTAR 793855aefd feat: 🎸 重构用户系统、OAuth、插件系统、后台系统
使用naive ui重构后台面板
重构用户系统,方便支持更多OAuth认证方式
重构插件系统,方便静态资源的添加

BREAKING CHANGE: 🧨 更改管理员身份认证为用户id
2022-09-11 17:21:25 +08:00

56 lines
1.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
declare (strict_types=1);
namespace app\command;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\Output;
use ZipArchive;
class PluginPackage extends Command
{
protected function configure()
{
// 指令配置
$this->setName('plugin:package')
->addArgument('space', Argument::REQUIRED, '插件域例如aoaostar_com')
->setDescription('打包指定域的所有插件');
}
protected function execute(Input $input, Output $output)
{
$space = $input->getArgument('space');
// 指令输出
$rootPath = app()->getRootPath() . '/plugin/';
if (!is_dir($rootPath . $space)) {
$output->writeln("该域不存在:[$space]");
return;
}
$plugins = glob($rootPath . $space . '/*');
$output->writeln("正在打包:[$space]下的文件");
foreach ($plugins as $plugin) {
$zip = new ZipArchive();
$filename = $rootPath . 'output/' . $space . DIRECTORY_SEPARATOR . basename($plugin) . '.zip';
if (!is_dir(dirname($filename))) {
mkdir(dirname($filename), 0755, true);
}
if ($zip->open($filename, ZipArchive::CREATE | ZipArchive::OVERWRITE)) {
$tree_relative = tree_relative($plugin);
$files = multi2one($tree_relative, '', '/');
foreach ($files as $file) {
if ($file !== '.' && $file !== '..') {
$zip->addFile($plugin . '/' . $file, $space . '/' . basename($plugin) . '/' . $file);
}
}
}
$zip->close();
$output->writeln("打包成功:[$filename]");
}
$output->writeln("该域所有文件都已打包完成:[$space]");
}
}