Skip to content

Instantly share code, notes, and snippets.

@pauloiankoski
Created July 24, 2025 20:25
Show Gist options
  • Save pauloiankoski/a62a5de7d1c05d733e943997f9c00776 to your computer and use it in GitHub Desktop.
Save pauloiankoski/a62a5de7d1c05d733e943997f9c00776 to your computer and use it in GitHub Desktop.
const { exec } = require('child_process');
const fs = require('fs');
const path = require('path');
const scriptName = 'php83-checker.ts';
const currentDir = process.cwd();
const reportFile = 'php-compatibility-report.txt';
// Store results for final report
let results = [];
let completedFolders = 0;
let totalFolders = 0;
fs.readdir(currentDir, { withFileTypes: true }, (err, files) => {
if (err) {
console.error('Failed to read directory:', err);
return;
}
const folders = files.filter(dirent => dirent.isDirectory()).map(dirent => dirent.name);
totalFolders = folders.length;
console.log(`Found ${totalFolders} folders to check...`);
folders.forEach(folder => {
const command = `bun ${scriptName} ${folder}/`;
console.log(`Running: ${command}`);
exec(command, (error, stdout, stderr) => {
const output = stdout || '';
const stderrOutput = stderr || '';
// Determine if this was a successful scan or actual script failure
let scriptSuccess = true;
let phpIssuesFound = false;
let actualError = '';
if (error) {
// Check if this is just the script reporting PHP issues (exit code 1)
// vs actual execution failure
if (output.includes('Summary:') || output.includes('PHP 8.3 Compatibility Checker')) {
// Script ran successfully but found PHP issues
scriptSuccess = true;
if (output.includes('Some files have compatibility issues') ||
output.includes('Issues found') ||
error.code === 1) {
phpIssuesFound = true;
}
} else {
// Actual script execution error
scriptSuccess = false;
actualError = error.message;
}
}
const result = {
folder: folder,
scriptSuccess: scriptSuccess,
phpIssuesFound: phpIssuesFound,
output: output,
error: actualError,
stderr: stderrOutput
};
results.push(result);
completedFolders++;
// Console output for immediate feedback
if (!scriptSuccess) {
console.error(`❌ Script failed for "${folder}":`, actualError);
} else if (phpIssuesFound) {
console.log(`⚠️ PHP issues found in "${folder}"`);
} else {
console.log(`✅ No PHP issues in "${folder}"`);
}
// Generate report when all folders are processed
if (completedFolders === totalFolders) {
generateReport();
}
});
});
});
function generateReport() {
const timestamp = new Date().toISOString();
let report = `PHP Compatibility Check Report\n`;
report += `Generated: ${timestamp}\n`;
report += `Total folders checked: ${totalFolders}\n`;
report += `${'='.repeat(50)}\n\n`;
// Extract all PHP compatibility issues from outputs
let allPhpIssues = [];
results.forEach(result => {
report += `${result.folder}: `;
if (!result.scriptSuccess) {
report += `SCRIPT FAILED\n`;
} else if (result.phpIssuesFound) {
report += `PHP ISSUES FOUND\n`;
// Extract issues from output
if (result.output) {
const lines = result.output.split('\n');
let inCopyPasteSection = false;
let inOneLineSection = false;
let currentFile = '';
for (const line of lines) {
// Look for copy-paste friendly section
if (line.includes('All Issues (copy-paste friendly):')) {
inCopyPasteSection = true;
continue;
}
// Look for one-line format section
if (line.includes('One-line format:')) {
inCopyPasteSection = false;
inOneLineSection = true;
continue;
}
// Extract issues from copy-paste section
if (inCopyPasteSection && line.trim()) {
if (line.startsWith('File: ')) {
currentFile = line.replace('File: ', '').trim();
} else if (line.startsWith(' Line ')) {
const issue = line.trim();
allPhpIssues.push({
folder: result.folder,
file: currentFile,
issue: issue,
oneLine: `${result.folder}/${currentFile}:${issue.replace('Line ', '').replace(': ', ' - ')}`
});
}
}
}
}
} else {
report += `PHP 8.3 COMPATIBLE\n`;
}
});
// Summary
const scriptFailures = results.filter(r => !r.scriptSuccess).length;
const phpIssues = results.filter(r => r.scriptSuccess && r.phpIssuesFound).length;
const cleanPlugins = results.filter(r => r.scriptSuccess && !r.phpIssuesFound).length;
report += `\n${'='.repeat(50)}\n`;
report += `SUMMARY:\n`;
report += `Script Failures: ${scriptFailures}\n`;
report += `Plugins with PHP Issues: ${phpIssues}\n`;
report += `PHP 8.3 Compatible Plugins: ${cleanPlugins}\n`;
report += `Total PHP Issues Found: ${allPhpIssues.length}\n`;
// PHP Issues section - only if there are issues
if (allPhpIssues.length > 0) {
report += `\n${'='.repeat(50)}\n`;
report += `PHP COMPATIBILITY ISSUES\n`;
report += `${'='.repeat(50)}\n\n`;
// Copy-paste friendly format
report += `Copy-Paste Friendly Format:\n`;
report += `${'-'.repeat(30)}\n`;
// Group by folder
const issuesByFolder = allPhpIssues.reduce((acc, issue) => {
if (!acc[issue.folder]) {
acc[issue.folder] = {};
}
if (!acc[issue.folder][issue.file]) {
acc[issue.folder][issue.file] = [];
}
acc[issue.folder][issue.file].push(issue.issue);
return acc;
}, {});
for (const [folder, files] of Object.entries(issuesByFolder)) {
report += `\nFolder: ${folder}\n`;
for (const [file, issues] of Object.entries(files)) {
report += `File: ${file}\n`;
for (const issue of issues) {
report += ` ${issue}\n`;
}
}
}
// One-line format
report += `\n${'-'.repeat(30)}\n`;
report += `One-Line Format:\n`;
report += `${'-'.repeat(30)}\n`;
for (const issue of allPhpIssues) {
report += `${issue.oneLine}\n`;
}
}
// Write report to file
fs.writeFileSync(reportFile, report);
console.log(`\n📄 Report generated: ${reportFile}`);
console.log(`📊 Summary: ${cleanPlugins} compatible, ${phpIssues} with PHP issues, ${scriptFailures} script failures`);
if (allPhpIssues.length > 0) {
console.log(`⚠️ Total PHP compatibility issues: ${allPhpIssues.length}`);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment