Files
wwjcloud/tools/run-migration.js
wanwu 8da4047110 feat: v0.3.3 - 清理代码结构,删除common层,保留core层企业级基础设施
- 删除common层业务代码(将通过real-business-logic-generator.js重新生成)
- 清理重复的core层生成工具
- 保留完整的企业级core层基础设施(Security/Cache/Tracing/Event/Queue/Health)
- 版本号升级到0.3.3
- 项目架构现已完整,接下来专注优化PHP到TypeScript语法转换
2025-09-27 03:28:46 +08:00

172 lines
4.6 KiB
JavaScript
Executable File
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env node
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
/**
* 统一迁移执行脚本
* 按步骤执行完整的PHP到NestJS迁移
*/
class MigrationRunner {
constructor() {
this.toolsDir = path.join(__dirname);
this.steps = [
{
name: '步骤1: PHP文件发现',
tool: 'php-file-discovery.js',
description: '扫描PHP项目结构发现所有相关文件'
},
{
name: '步骤2: 生成NestJS结构',
tool: 'real-business-logic-generator.js',
description: '基于PHP结构生成NestJS代码框架'
},
{
name: '步骤3: 生成模块文件',
tool: 'module-generator.js',
description: '为每个模块生成.module.ts文件并正确引用所有组件'
}
];
this.stats = {
totalSteps: this.steps.length,
completedSteps: 0,
failedSteps: 0,
startTime: null,
endTime: null
};
}
/**
* 运行完整迁移流程
*/
async run() {
console.log('🚀 启动PHP到NestJS完整迁移流程');
console.log('=====================================\n');
this.stats.startTime = new Date();
try {
// 检查工具文件是否存在
await this.checkTools();
// 执行每个步骤
for (let i = 0; i < this.steps.length; i++) {
const step = this.steps[i];
console.log(`\n📋 ${step.name}`);
console.log(`📝 ${step.description}`);
console.log('─'.repeat(50));
try {
await this.executeStep(step, i + 1);
this.stats.completedSteps++;
console.log(`${step.name} 完成\n`);
} catch (error) {
this.stats.failedSteps++;
console.error(`${step.name} 失败:`, error.message);
// 询问是否继续
if (!await this.askContinue()) {
console.log('🛑 迁移流程已停止');
break;
}
}
}
this.stats.endTime = new Date();
this.generateFinalReport();
} catch (error) {
console.error('❌ 迁移流程发生严重错误:', error.message);
process.exit(1);
}
}
/**
* 检查工具文件是否存在
*/
async checkTools() {
console.log('🔍 检查工具文件...');
for (const step of this.steps) {
const toolPath = path.join(this.toolsDir, step.tool);
if (!fs.existsSync(toolPath)) {
throw new Error(`工具文件不存在: ${step.tool}`);
}
}
console.log('✅ 所有工具文件检查通过\n');
}
/**
* 执行单个步骤
*/
async executeStep(step, stepNumber) {
const toolPath = path.join(this.toolsDir, step.tool);
console.log(`🔄 执行工具: ${step.tool}`);
try {
// 执行工具
const output = execSync(`node "${toolPath}"`, {
encoding: 'utf8',
cwd: process.cwd(),
stdio: 'inherit'
});
return output;
} catch (error) {
throw new Error(`工具执行失败: ${error.message}`);
}
}
/**
* 询问是否继续执行
*/
async askContinue() {
// 在非交互模式下自动继续
if (process.env.NODE_ENV === 'production' || process.env.CI) {
return true;
}
// 这里可以添加交互式询问逻辑
// 目前默认继续执行
return true;
}
/**
* 生成最终报告
*/
generateFinalReport() {
const duration = this.stats.endTime - this.stats.startTime;
const durationMinutes = Math.round(duration / 1000 / 60 * 100) / 100;
console.log('\n' + '='.repeat(60));
console.log('📊 迁移完成报告');
console.log('='.repeat(60));
console.log(`⏱️ 总耗时: ${durationMinutes} 分钟`);
console.log(`📋 总步骤: ${this.stats.totalSteps}`);
console.log(`✅ 完成步骤: ${this.stats.completedSteps}`);
console.log(`❌ 失败步骤: ${this.stats.failedSteps}`);
console.log(`📈 完成率: ${Math.round(this.stats.completedSteps / this.stats.totalSteps * 100)}%`);
if (this.stats.failedSteps === 0) {
console.log('\n🎉 恭喜!所有步骤都成功完成!');
console.log('📁 请检查 wwjcloud/src/common/ 目录查看生成的代码');
} else {
console.log('\n⚠ 部分步骤失败,请检查错误信息并重试');
}
console.log('='.repeat(60));
}
}
// 运行迁移
if (require.main === module) {
const runner = new MigrationRunner();
runner.run().catch(console.error);
}
module.exports = MigrationRunner;