- ✅ 成功运行迁移工具,生成28个模块的完整NestJS代码 - ✅ 生成所有实体、服务、控制器、验证器等组件 - ✅ 修复npm依赖冲突,更新package-lock.json - ✅ 添加Docker测试脚本和配置文件 - ✅ 完善迁移工具的调试日志和错误处理 - 🔧 包含增量更新工具和质量检查工具 - 📊 迁移统计:28个模块,数千个文件,耗时26.47秒 主要变更: - wwjcloud-nest/src/core/* - 生成的业务模块代码 - tools/* - 迁移工具和辅助脚本 - wwjcloud-nest/package.json - 依赖更新 - docker/* - 容器化配置和测试脚本
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; |