mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-01 15:32:48 +08:00
- 新增 `tools:ua:build` 命令,用于合并前端模块文件 - 添加构建配置文件 `ua.build.json` 定义源文件和输出 - 引入基础服务类 `ToolsUaServiceBase` 处理路径和配置读取 - 创建命令基类 `ToolsUaBuildBase` 实现文件合并逻辑 - 注册新命令到 UlthonAdminService 服务容器 - 提供完整的模块化前端代码结构(core、common、table、listen、api、utils) - 添加详细的使用说明文档 README.md - 包含示例 Scheme 文件展示功能
66 lines
2.4 KiB
PHP
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;
|
|
}
|
|
}
|