初始化本地仓库

This commit is contained in:
2026-08-31 11:33:59 +08:00
commit 663f74b633
2390 changed files with 402918 additions and 0 deletions
@@ -0,0 +1,91 @@
<?php
declare(strict_types=1);
/**
*+------------------
* madong
*+------------------
* Copyright (c) https://gitee.com/motion-code All rights reserved.
*+------------------
* Author: Mr. April (405784684@qq.com)
*+------------------
* Official Website: http://www.madong.tech
*/
namespace app\command\plugin;
use app\command\BaseCommand;
use app\service\core\plugin\PluginUninstallService;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
/**
* 插件删除命令
* 使用方法:
* - 删除插件:php webman madong-plugin:delete plugin-name
* - 移除插件(别名):php webman madong-plugin:remove plugin-name
*
* 注意:删除前必须先卸载插件
*
* @author Mr.April
* @since 1.0.0
*/
#[AsCommand(
name: 'madong-plugin:delete',
description: 'Delete plugin package from the system (requires plugin to be uninstalled first)',
aliases: ['madong-plugin:delete', 'madong-plugin:remove'],
hidden: false
)]
class DeleteCommand extends BaseCommand
{
/**
* 配置命令
*/
protected function configure(): void
{
$this->addArgument('name', InputArgument::REQUIRED, 'Plugin name');
}
/**
* 执行命令
*/
public function __invoke(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$io->title('Plugin Deleter');
// 获取参数
$name = $input->getArgument('name');
$io->info("Deleting plugin: {$name}");
$io->note("Note: Plugin must be uninstalled before deletion");
// 确认删除
if (!$this->confirm($io, "Are you sure you want to delete plugin {$name}? This action cannot be undone.")) {
$io->note("Deletion cancelled");
return Command::SUCCESS;
}
try {
// 创建删除服务实例(统一入口)
$deleteService = new PluginUninstallService();
// 执行删除流程
$result = $deleteService->delete($name);
if ($result) {
return $this->outputSuccess($io, "Plugin '{$name}' deleted successfully!");
} else {
return $this->outputError($io, "Plugin '{$name}' deletion failed!");
}
} catch (\Exception $e) {
return $this->outputError($io, sprintf("Deletion failed: %s", $e->getMessage()), $e);
}
}
}
@@ -0,0 +1,86 @@
<?php
declare(strict_types=1);
/**
*+------------------
* madong
*+------------------
* Copyright (c) https://gitee.com/motion-code All rights reserved.
*+------------------
* Author: Mr. April (405784684@qq.com)
*+------------------
* Official Website: http://www.madong.tech
*/
namespace app\command\plugin;
use app\command\BaseCommand;
use app\service\core\plugin\PluginDevelopService;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
/**
* 打包插件命令
*
* @author Mr.April
* @since 1.0.0
*/
#[AsCommand(
name: 'madong-plugin:develop:build',
description: 'Build plugin',
aliases: ['madong-plugin:dev:build'],
hidden: false
)]
class DevelopBuildCommand extends BaseCommand
{
/**
* 配置命令
*/
protected function configure(): void
{
$this
->addArgument('key', InputArgument::REQUIRED, 'Plugin key (kebab-case format, e.g. test-demo)')
->addOption('target', 't', InputOption::VALUE_OPTIONAL, 'Target directory path', null);
}
/**
* 执行命令
*/
public function __invoke(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$io->title('Build Plugin');
// 获取参数
$pluginKey = $input->getArgument('key');
$targetDirectory = $input->getOption('target');
$io->info(sprintf("Building plugin: %s", $pluginKey));
if ($targetDirectory) {
$io->info(sprintf("Target directory: %s", $targetDirectory));
} else {
$io->info("Target directory: Default (runtime/plugins)");
}
try {
// 创建插件开发服务实例
$pluginDevelopService = new PluginDevelopService();
// 构建插件
$result = $pluginDevelopService->build($pluginKey, $targetDirectory);
if ($result['code'] === 200) {
$io->success("Plugin built successfully!");
$io->text(sprintf("ZIP file path: %s", $result['data']['zip_file_path']));
return parent::SUCCESS;
} else {
return $this->outputError($io, sprintf("Build failed: %s", $result['message']));
}
} catch (\Exception $e) {
return $this->outputError($io, sprintf("Build failed: %s", $e->getMessage()), $e);
}
}
}
@@ -0,0 +1,85 @@
<?php
declare(strict_types=1);
/**
*+------------------
* madong
*+------------------
* Copyright (c) https://gitee.com/motion-code All rights reserved.
*+------------------
* Author: Mr. April (405784684@qq.com)
*+------------------
* Official Website: http://www.madong.tech
*/
namespace app\command\plugin;
use app\command\BaseCommand;
use app\service\core\plugin\PluginDevelopService;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
/**
* 创建插件模板命令
*
* @author Mr.April
* @since 1.0.0
*/
#[AsCommand(
name: 'madong-plugin:develop:create',
description: 'Create plugin template',
aliases: ['madong-plugin:dev:create'],
hidden: false
)]
class DevelopCreateCommand extends BaseCommand
{
/**
* 配置命令
*/
protected function configure(): void
{
$this
->addArgument('name', InputArgument::REQUIRED, 'Plugin name (snake_case format, e.g. test_demo)')
->addArgument('title', InputArgument::REQUIRED, 'Plugin title')
->addArgument('description', InputArgument::OPTIONAL, 'Plugin description', '');
}
/**
* 执行命令
*/
public function __invoke(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$io->title('Create Plugin Template');
// 获取参数
$pluginName = $input->getArgument('name');
$pluginTitle = $input->getArgument('title');
$pluginDescription = $input->getArgument('description');
$io->info(sprintf("Creating plugin template: %s", $pluginName));
$io->info(sprintf("Plugin title: %s", $pluginTitle));
$io->info(sprintf("Plugin description: %s", $pluginDescription));
try {
// 创建插件开发服务实例
$pluginDevelopService = new PluginDevelopService();
// 生成插件模板
$result = $pluginDevelopService->generatePluginTemplate($pluginName, $pluginTitle, $pluginDescription);
if ($result['code'] === 200) {
$io->success("Plugin template created successfully!");
$io->text(sprintf("Frontend path: %s", $result['data']['frontend_path']));
$io->text(sprintf("Backend path: %s", $result['data']['backend_path']));
return parent::SUCCESS;
} else {
return $this->outputError($io, sprintf("Creation failed: %s", $result['message']));
}
} catch (\Exception $e) {
return $this->outputError($io, sprintf("Creation failed: %s", $e->getMessage()), $e);
}
}
}
@@ -0,0 +1,106 @@
<?php
declare(strict_types=1);
/**
*+------------------
* madong
*+------------------
* Copyright (c) https://gitee.com/motion-code All rights reserved.
*+------------------
* Author: Mr. April (405784684@qq.com)
*+------------------
* Official Website: http://www.madong.tech
*/
namespace app\command\plugin;
use app\command\BaseCommand;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
/**
* 删除插件命令
*
* @author Mr.April
* @since 1.0.0
*/
#[AsCommand(
name: 'madong-plugin:develop:delete',
description: 'Delete plugin',
aliases: ['madong-plugin:dev:delete'],
hidden: false
)]
class DevelopDeleteCommand extends BaseCommand
{
/**
* 配置命令
*/
protected function configure(): void
{
$this->addArgument('key', InputArgument::REQUIRED, 'Plugin key (kebab-case format, e.g. test-demo)');
}
/**
* 执行命令
*/
public function __invoke(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$io->title('Delete Plugin');
// 获取参数
$pluginKey = $input->getArgument('key');
$pluginName = str_replace('-', '_', $pluginKey);
$io->info(sprintf("Deleting plugin: %s", $pluginKey));
try {
// 使用 base_path() 计算路径
$basePath = base_path();
$projectPath = dirname($basePath);
// 定义路径
$frontendPath = $projectPath . '/admin/src/apps/' . $pluginName;
$backendPath = $basePath . '/plugin/' . $pluginName;
$runtimePath = $basePath . '/runtime/plugins/' . $pluginKey;
$runtimeZipPath = $basePath . '/runtime/plugins/' . $pluginKey . '.zip';
$buildPath = $basePath . '/runtime/build/' . $pluginKey;
// 删除前端目录
if (is_dir($frontendPath)) {
$this->deleteDirectory($frontendPath);
$io->text(sprintf("Deleted frontend directory: %s", $frontendPath));
}
// 删除后端目录
if (is_dir($backendPath)) {
$this->deleteDirectory($backendPath);
$io->text(sprintf("Deleted backend directory: %s", $backendPath));
}
// 删除构建目录
if (is_dir($buildPath)) {
$this->deleteDirectory($buildPath);
$io->text(sprintf("Deleted build directory: %s", $buildPath));
}
// 删除运行时目录
if (is_dir($runtimePath)) {
$this->deleteDirectory($runtimePath);
$io->text(sprintf("Deleted runtime directory: %s", $runtimePath));
}
// 删除运行时ZIP文件
if (file_exists($runtimeZipPath)) {
unlink($runtimeZipPath);
$io->text(sprintf("Deleted runtime ZIP file: %s", $runtimeZipPath));
}
return $this->outputSuccess($io, "Plugin deleted successfully!");
} catch (\Exception $e) {
return $this->outputError($io, sprintf("Deletion failed: %s", $e->getMessage()), $e);
}
}
}
@@ -0,0 +1,76 @@
<?php
declare(strict_types=1);
/**
*+------------------
* madong
*+------------------
* Copyright (c) https://gitee.com/motion-code All rights reserved.
*+------------------
* Author: Mr. April (405784684@qq.com)
*+------------------
* Official Website: http://www.madong.tech
*/
namespace app\command\plugin;
use app\command\BaseCommand;
use app\service\core\plugin\PluginInstallService;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
/**
* 插件安装命令
* 使用方法:
* - 安装插件:php webman madong-plugin:install plugin-name
* - 从市场安装:php webman madong-plugin:install plugin-name market
*
* @author Mr.April
* @since 1.0.0
*/
#[AsCommand(
name: 'madong-plugin:install',
description: 'Install plugin to the system',
aliases: ['madong-plugin:install'],
hidden: false
)]
class InstallCommand extends BaseCommand
{
/**
* 配置命令
*/
protected function configure(): void
{
$this->addArgument('name', InputArgument::REQUIRED, 'Plugin name')
->addArgument('mode', InputArgument::OPTIONAL, 'Install mode (local/market)', 'local');
}
/**
* 执行命令
*/
public function __invoke(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$io->title('Plugin Installer');
// 获取参数
$name = $input->getArgument('name');
$mode = $input->getArgument('mode');
$io->info("Installing plugin: {$name}");
$io->info("Install mode: {$mode}");
try {
// 创建安装服务实例
$installService = new PluginInstallService();
// 执行安装流程(使用基类的流式处理)
return $this->executeStream($installService->install($name, $mode), $io, $name);
} catch (\Exception $e) {
return $this->outputError($io, sprintf("Installation failed: %s", $e->getMessage()), $e);
}
}
}
+184
View File
@@ -0,0 +1,184 @@
<?php
declare(strict_types=1);
/**
*+------------------
* madong
*+------------------
* Copyright (c) https://gitee.com/motion-code All rights reserved.
*+------------------
* Author: Mr. April (405784684@qq.com)
*+------------------
* Official Website: http://www.madong.tech
*/
namespace app\command\plugin;
use app\command\BaseCommand;
use app\service\core\plugin\PluginUninstallService;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
/**
* 插件运行器命令
*
* 使用方法:
* php webman madong-plugin:run plugin-name install
* php webman madong-plugin:run plugin-name uninstall # 使用统一的卸载服务
* php webman madong-plugin:run plugin-name delete # 删除插件包
* php webman madong-plugin:run plugin-name update
* php webman madong-plugin:run plugin-name export
*
* 自动调用插件的 Install 类或对应的服务
*/
#[AsCommand(
name: 'madong-plugin:run',
description: 'Run plugin actions: install, uninstall, delete, update, export',
aliases: ['madong-plugin:run'],
hidden: false
)]
class RunCommand extends BaseCommand
{
protected function configure(): void
{
$this->addArgument('name', InputArgument::REQUIRED, 'Plugin name')
->addArgument('action', InputArgument::REQUIRED, 'Action: install, uninstall, delete, update, export')
->addArgument('version', InputArgument::OPTIONAL, 'Version (for update)')
->addOption('force', 'f', InputOption::VALUE_NONE, 'Force run migrations (ignore previous records)')
->addOption('data', 'd', InputOption::VALUE_NONE, 'Export with data (for export action)')
->addOption('output', 'o', InputOption::VALUE_OPTIONAL, 'Output file path (for export action)');
}
public function __invoke(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$name = $input->getArgument('name');
$action = $input->getArgument('action');
$version = $input->getArgument('version') ?? '1.0.0';
$force = $input->getOption('force');
$io->title("Plugin Runner: {$name}");
$io->info("Action: {$action}" . ($force ? " (force)" : ""));
// 查找插件路径
$pluginPath = base_path('plugin/' . $name);
if (!is_dir($pluginPath)) {
$io->error("Plugin '{$name}' not found");
return Command::FAILURE;
}
// 查找 Install 类(支持多个位置)
$installFile = $pluginPath . '/Install.php';
if (!file_exists($installFile)) {
$installFile = $pluginPath . '/api/Install.php';
}
if (!file_exists($installFile)) {
$installFile = $pluginPath . '/install/Install.php';
}
if (!file_exists($installFile)) {
$io->error("Install.php not found");
return Command::FAILURE;
}
// 加载 Install 类
include $installFile;
// 确定类名
$className = "plugin\\{$name}\\Install";
if (!class_exists($className)) {
$io->error("Install class not found: {$className}");
return Command::FAILURE;
}
$io->info("Found: {$className}");
try {
// 实例化并调用对应方法
$instance = new $className();
$io->info("Instance created: " . get_class($instance));
switch ($action) {
case 'install':
// Force migration: clear logs first
if ($force && method_exists($instance, 'forceMigrate')) {
$io->info('>>> Force migration mode - clearing logs...');
$instance->forceMigrate();
} elseif (!method_exists($instance, 'install')) {
$io->warning('install() method not found');
return Command::FAILURE;
} else {
$io->info('>>> Calling install() method...');
$result = $instance->install($version);
$io->info('<<< install() completed');
}
$io->success("Plugin '{$name}' installed successfully!");
break;
case 'uninstall':
// 使用统一的卸载服务(会检查 undeletable 配置)
$io->info('>>> Calling uninstall via PluginUninstallService...');
$uninstallService = new PluginUninstallService();
return $this->executeStream($uninstallService->uninstall($name), $io, $name);
case 'delete':
// 使用统一的删除服务(会检查卸载状态)
$io->info('>>> Calling delete via PluginUninstallService...');
$io->note("Plugin must be uninstalled before deletion");
$deleteService = new PluginUninstallService();
$result = $deleteService->delete($name);
if ($result) {
$io->success("Plugin '{$name}' deleted successfully!");
return Command::SUCCESS;
} else {
$io->error("Plugin '{$name}' deletion failed!");
return Command::FAILURE;
}
case 'update':
if (!method_exists($instance, 'update')) {
$io->warning('update() method not found');
return Command::FAILURE;
}
$oldVersion = $version;
$io->info(">>> Calling update() from {$oldVersion}...");
$result = $instance->update($oldVersion, $version);
$io->info('<<< update() completed');
$io->success("Plugin '{$name}' updated successfully!");
break;
case 'export':
if (!method_exists($instance, 'exportSql')) {
$io->warning('exportSql() method not found');
return Command::FAILURE;
}
$withData = $input->getOption('data');
$outputFile = $input->getOption('output');
$io->info('>>> Exporting SQL' . ($withData ? ' (with data)' : ' (structure only)') . '...');
$result = $instance->exportSql($withData, $outputFile);
if ($result) {
$io->success("SQL exported successfully!");
} else {
$io->warning('Export failed or no tables found');
}
break;
default:
$io->error("Unknown action: {$action}");
return Command::FAILURE;
}
return Command::SUCCESS;
} catch (\Throwable $e) {
return $this->outputError($io, "Error: " . $e->getMessage(), $e);
}
}
}
@@ -0,0 +1,79 @@
<?php
declare(strict_types=1);
/**
*+------------------
* madong
*+------------------
* Copyright (c) https://gitee.com/motion-code All rights reserved.
*+------------------
* Author: Mr. April (405784684@qq.com)
*+------------------
* Official Website: http://www.madong.tech
*/
namespace app\command\plugin;
use app\command\BaseCommand;
use app\service\core\plugin\PluginUninstallService;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
/**
* 插件卸载命令
* 使用方法:
* - 卸载插件:php webman madong-plugin:uninstall plugin-name
*
* @author Mr.April
* @since 1.0.0
*/
#[AsCommand(
name: 'madong-plugin:uninstall',
description: 'Uninstall plugin from the system',
aliases: ['madong-plugin:uninstall'],
hidden: false
)]
class UninstallCommand extends BaseCommand
{
/**
* 配置命令
*/
protected function configure(): void
{
$this->addArgument('name', InputArgument::REQUIRED, 'Plugin name');
}
/**
* 执行命令
*/
public function __invoke(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$io->title('Plugin Uninstaller');
// 获取参数
$name = $input->getArgument('name');
$io->info("Uninstalling plugin: {$name}");
// 确认卸载
if (!$this->confirm($io, "Are you sure you want to uninstall plugin {$name}? This action cannot be undone.")) {
$io->note("Uninstallation cancelled");
return Command::SUCCESS;
}
try {
// 创建卸载服务实例(统一入口)
$uninstallService = new PluginUninstallService();
// 执行卸载流程(使用基类的流式处理)
return $this->executeStream($uninstallService->uninstall($name), $io, $name);
} catch (\Exception $e) {
return $this->outputError($io, sprintf("Uninstallation failed: %s", $e->getMessage()), $e);
}
}
}