133 lines
4.4 KiB
JavaScript
133 lines
4.4 KiB
JavaScript
|
|
#!/usr/bin/env node
|
|||
|
|
|
|||
|
|
const fs = require('fs');
|
|||
|
|
const path = require('path');
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 简化版迁移工具测试
|
|||
|
|
* 用于诊断迁移工具卡住的问题
|
|||
|
|
*/
|
|||
|
|
class SimpleMigrationTest {
|
|||
|
|
constructor() {
|
|||
|
|
this.discoveryData = null;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
async run() {
|
|||
|
|
console.log('🚀 开始简化版迁移测试...');
|
|||
|
|
|
|||
|
|
try {
|
|||
|
|
// 第1步:加载数据
|
|||
|
|
console.log('📊 第1步:加载PHP文件发现结果...');
|
|||
|
|
await this.loadDiscoveryData();
|
|||
|
|
|
|||
|
|
// 第2步:分析数据
|
|||
|
|
console.log('📊 第2步:分析数据结构...');
|
|||
|
|
this.analyzeData();
|
|||
|
|
|
|||
|
|
// 第3步:测试模块提取
|
|||
|
|
console.log('📊 第3步:测试模块提取...');
|
|||
|
|
this.testModuleExtraction();
|
|||
|
|
|
|||
|
|
console.log('✅ 简化版迁移测试完成');
|
|||
|
|
|
|||
|
|
} catch (error) {
|
|||
|
|
console.error('❌ 测试失败:', error.message);
|
|||
|
|
console.error('错误堆栈:', error.stack);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
async loadDiscoveryData() {
|
|||
|
|
const filePath = path.join(__dirname, 'php-discovery-result.json');
|
|||
|
|
|
|||
|
|
console.log(' 📁 检查文件存在性...');
|
|||
|
|
if (!fs.existsSync(filePath)) {
|
|||
|
|
throw new Error(`发现结果文件不存在: ${filePath}`);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
const stats = fs.statSync(filePath);
|
|||
|
|
console.log(` 📏 文件大小: ${(stats.size / 1024).toFixed(2)} KB`);
|
|||
|
|
|
|||
|
|
console.log(' 📖 开始读取文件...');
|
|||
|
|
const fileContent = fs.readFileSync(filePath, 'utf8');
|
|||
|
|
console.log(` 📄 文件内容长度: ${fileContent.length} 字符`);
|
|||
|
|
|
|||
|
|
console.log(' 🔍 开始解析JSON...');
|
|||
|
|
this.discoveryData = JSON.parse(fileContent);
|
|||
|
|
console.log(' ✅ JSON解析成功');
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
analyzeData() {
|
|||
|
|
if (!this.discoveryData) {
|
|||
|
|
throw new Error('数据未加载');
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
console.log(' 📊 数据统计:');
|
|||
|
|
console.log(` - 控制器模块数: ${Object.keys(this.discoveryData.controllers || {}).length}`);
|
|||
|
|
console.log(` - 服务层数: ${Object.keys(this.discoveryData.services || {}).length}`);
|
|||
|
|
console.log(` - 模型模块数: ${Object.keys(this.discoveryData.models || {}).length}`);
|
|||
|
|
|
|||
|
|
// 显示前5个控制器模块
|
|||
|
|
const controllerModules = Object.keys(this.discoveryData.controllers || {});
|
|||
|
|
console.log(` - 控制器模块示例: ${controllerModules.slice(0, 5).join(', ')}`);
|
|||
|
|
|
|||
|
|
// 显示前5个服务层
|
|||
|
|
const serviceModules = Object.keys(this.discoveryData.services || {});
|
|||
|
|
console.log(` - 服务层示例: ${serviceModules.slice(0, 5).join(', ')}`);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
testModuleExtraction() {
|
|||
|
|
const modules = new Set();
|
|||
|
|
|
|||
|
|
// 从控制器中提取模块
|
|||
|
|
console.log(' 🔨 从控制器提取模块...');
|
|||
|
|
for (const moduleName of Object.keys(this.discoveryData.controllers || {})) {
|
|||
|
|
modules.add(moduleName);
|
|||
|
|
}
|
|||
|
|
console.log(` - 提取到 ${modules.size} 个控制器模块`);
|
|||
|
|
|
|||
|
|
// 从服务中提取模块
|
|||
|
|
console.log(' 🔨 从服务提取模块...');
|
|||
|
|
let serviceModuleCount = 0;
|
|||
|
|
for (const [layerName, services] of Object.entries(this.discoveryData.services || {})) {
|
|||
|
|
for (const [serviceName, serviceInfo] of Object.entries(services)) {
|
|||
|
|
const moduleName = this.extractModuleNameFromServicePath(serviceInfo.filePath);
|
|||
|
|
if (!modules.has(moduleName)) {
|
|||
|
|
serviceModuleCount++;
|
|||
|
|
}
|
|||
|
|
modules.add(moduleName);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
console.log(` - 从服务提取到 ${serviceModuleCount} 个新模块`);
|
|||
|
|
|
|||
|
|
// 从模型中提取模块
|
|||
|
|
console.log(' 🔨 从模型提取模块...');
|
|||
|
|
let modelModuleCount = 0;
|
|||
|
|
for (const moduleName of Object.keys(this.discoveryData.models || {})) {
|
|||
|
|
if (!modules.has(moduleName)) {
|
|||
|
|
modelModuleCount++;
|
|||
|
|
}
|
|||
|
|
modules.add(moduleName);
|
|||
|
|
}
|
|||
|
|
console.log(` - 从模型提取到 ${modelModuleCount} 个新模块`);
|
|||
|
|
|
|||
|
|
console.log(` 📂 总共提取到 ${modules.size} 个模块`);
|
|||
|
|
console.log(` - 模块列表: ${Array.from(modules).slice(0, 10).join(', ')}${modules.size > 10 ? '...' : ''}`);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
extractModuleNameFromServicePath(filePath) {
|
|||
|
|
// 简化版模块名提取
|
|||
|
|
const parts = filePath.split('/');
|
|||
|
|
const serviceIndex = parts.findIndex(part => part === 'service');
|
|||
|
|
if (serviceIndex !== -1 && serviceIndex + 1 < parts.length) {
|
|||
|
|
return parts[serviceIndex + 1];
|
|||
|
|
}
|
|||
|
|
return 'unknown';
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (require.main === module) {
|
|||
|
|
const test = new SimpleMigrationTest();
|
|||
|
|
test.run().catch(console.error);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
module.exports = SimpleMigrationTest;
|