/** * @file update_includes.js * @brief 更新头文件包含路径 * @description 将 #include 替换为 #include * 扫描所有 .h, .hpp, .cpp 文件进行替换 */ const fs = require('fs'); const path = require('path'); // 配置 const TARGET_DIRS = [ path.join(__dirname, '..', 'Extra2D', 'include'), path.join(__dirname, '..', 'Extra2D', 'src'), path.join(__dirname, '..', 'examples') ]; const FILE_EXTENSIONS = ['.h', '.hpp', '.cpp']; // 替换规则:将 -> #include '); console.log(''); // 收集所有目标文件 let allFiles = []; for (const dir of TARGET_DIRS) { const files = getTargetFiles(dir); allFiles = allFiles.concat(files); } console.log(`📊 发现 ${allFiles.length} 个目标文件`); console.log(''); if (allFiles.length === 0) { console.log('⚠️ 没有找到目标文件'); return; } // 处理文件 let modifiedCount = 0; let totalChanges = 0; const modifiedFiles = []; for (const filePath of allFiles) { const result = processFile(filePath); if (result.modified) { modifiedCount++; totalChanges += result.changes; const relativePath = path.relative(path.join(__dirname, '..'), filePath); modifiedFiles.push({ path: relativePath, changes: result.changes }); console.log(`✅ 已更新: ${relativePath} (${result.changes} 处替换)`); } } console.log(''); console.log('========================================'); console.log('✨ 处理完成!'); console.log(` 扫描文件: ${allFiles.length} 个`); console.log(` 修改文件: ${modifiedCount} 个`); console.log(` 总替换数: ${totalChanges} 处`); console.log('========================================'); // 显示修改的文件列表 if (modifiedFiles.length > 0) { console.log(''); console.log('📋 修改的文件列表:'); modifiedFiles.forEach((file, index) => { console.log(` ${index + 1}. ${file.path} (${file.changes} 处)`); }); } } // 执行主函数 main();