@ui18n/cli
Version:
🌍 UI18n CLI工具 - 强大的国际化命令行工具
74 lines • 2.46 kB
JavaScript
/**
* 配置转换工具
* 用于将CLI配置转换为Core包兼容的配置
*/
export class ConfigConverter {
/**
* 将CLI配置转换为Core包配置
* @param config CLI配置
* @param logger 日志记录器
* @returns Core包配置
*/
static toCoreConfig(config, logger) {
const coreConfig = {
defaultLanguage: config.defaultLanguage,
fallbackLanguage: config.fallbackLanguage,
debug: false // 默认关闭调试模式
};
// 转换AI提供商配置
if (config.aiProvider) {
coreConfig.aiProvider = {
...config.aiProvider
};
}
// 转换缓存配置
if (config.cache) {
const cacheConfig = { ...config.cache };
// 将不支持的缓存类型映射为支持的类型
if (cacheConfig.type === 'file' || cacheConfig.type === 'redis') {
cacheConfig.type = 'memory';
if (logger) {
logger.warn(`缓存类型 "${config.cache.type}" 在当前版本中不支持,已自动切换为 "memory" 类型`);
}
}
coreConfig.cache = cacheConfig;
}
// 添加服务模式配置
coreConfig.serviceMode = 'self-hosted'; // 默认使用自托管模式
// 添加智能路由配置
coreConfig.enableSmartRouting = true;
// 添加质量检查配置
coreConfig.enableQualityCheck = true;
return coreConfig;
}
/**
* 验证Core配置是否有效
* @param config Core配置
* @returns 验证结果
*/
static validateCoreConfig(config) {
const errors = [];
// 验证必需字段
if (!config.defaultLanguage) {
errors.push('defaultLanguage 是必需的');
}
if (!config.fallbackLanguage) {
errors.push('fallbackLanguage 是必需的');
}
// 验证AI提供商配置
if (config.aiProvider) {
if (!config.aiProvider.type) {
errors.push('aiProvider.type 是必需的');
}
if (!config.aiProvider.apiKey) {
errors.push('aiProvider.apiKey 是必需的');
}
}
return {
valid: errors.length === 0,
errors
};
}
}
export default ConfigConverter;
//# sourceMappingURL=config-converter.js.map