Files
ulthon_admin/extend/base/common/command/tools/ua/ToolsUaBuildBase.php
augushong 9669bc61a3 feat(tools): 添加 Ulthon Admin 前端静态构建工具
- 新增 `tools:ua:build` 命令,用于合并前端模块文件
- 添加构建配置文件 `ua.build.json` 定义源文件和输出
- 引入基础服务类 `ToolsUaServiceBase` 处理路径和配置读取
- 创建命令基类 `ToolsUaBuildBase` 实现文件合并逻辑
- 注册新命令到 UlthonAdminService 服务容器
- 提供完整的模块化前端代码结构(core、common、table、listen、api、utils)
- 添加详细的使用说明文档 README.md
- 包含示例 Scheme 文件展示功能
2026-01-30 22:24:44 +08:00

66 lines
2.4 KiB
PHP

<?php
namespace base\common\command\tools\ua;
use base\common\service\ToolsUaServiceBase;
use think\console\Command;
use think\console\Input;
use think\console\input\Option;
use think\console\Output;
class ToolsUaBuildBase extends Command
{
protected function configure()
{
$this->setName('tools:ua:build')
->setDescription('构建 ulthon-admin 静态合并文件')
->addOption('config', null, Option::VALUE_OPTIONAL, '配置文件路径', 'public/static/plugs/ulthon-admin/ua.build.json')
->addOption('help', 'h', Option::VALUE_NONE, '显示帮助信息');
}
protected function execute(Input $input, Output $output)
{
$service = new ToolsUaServiceBase();
$configOption = $input->getOption('config');
$configPath = $service->getConfigPath($configOption);
[$ok, $config] = $service->readConfig($configPath);
if (!$ok) {
$output->writeln($config);
return 1;
}
if (!isset($config['sources']) || !is_array($config['sources']) || count($config['sources']) === 0) {
$output->writeln('配置文件 sources 不能为空');
return 1;
}
if (!isset($config['output']) || !$config['output']) {
$output->writeln('配置文件 output 不能为空');
return 1;
}
$baseDir = dirname($configPath);
$outputPath = $service->resolvePath($config['output'], $baseDir);
$contents = [];
foreach ($config['sources'] as $source) {
if (!is_string($source) || $source === '') {
$output->writeln('sources 中存在无效路径');
return 1;
}
$sourcePath = $service->resolvePath($source, $baseDir);
if (!is_file($sourcePath)) {
$output->writeln('源文件不存在: ' . $sourcePath);
return 1;
}
$contents[] = file_get_contents($sourcePath);
}
$final = implode("\n\n", $contents);
$outputDir = dirname($outputPath);
if (!is_dir($outputDir)) {
mkdir($outputDir, 0755, true);
}
file_put_contents($outputPath, $final);
$output->writeln('构建完成: ' . $outputPath);
$output->writeln('源文件数量: ' . count($contents));
$output->writeln('输出大小: ' . strlen($final));
return 0;
}
}