Files
ulthon_admin/extend/base/common/service/ToolsUaServiceBase.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

50 lines
1.3 KiB
PHP

<?php
namespace base\common\service;
use think\facade\App;
class ToolsUaServiceBase
{
public function getConfigPath($configPath)
{
if ($this->isAbsolutePath($configPath)) {
return $configPath;
}
$root = App::getRootPath();
return rtrim($root, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . ltrim($configPath, DIRECTORY_SEPARATOR);
}
public function readConfig($configPath)
{
if (!is_file($configPath)) {
return [false, '配置文件不存在: ' . $configPath];
}
$content = file_get_contents($configPath);
$data = json_decode($content, true);
if (!$data || !is_array($data)) {
return [false, '配置文件JSON格式不正确: ' . $configPath];
}
return [true, $data];
}
public function resolvePath($path, $baseDir)
{
if ($this->isAbsolutePath($path)) {
return $path;
}
return rtrim($baseDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . ltrim($path, DIRECTORY_SEPARATOR);
}
public function isAbsolutePath($path)
{
if ($path === '' || $path === null) {
return false;
}
if ($path[0] === '/' || $path[0] === '\\') {
return true;
}
return preg_match('/^[a-zA-Z]:[\\\\\\/]/', $path) === 1;
}
}