|
| 1 | +/** |
| 2 | + * POC: GSoC 2026 - Stack Modernization & API Audit Tool |
| 3 | + * This script demonstrates the automated assessment mechanism for upgrading |
| 4 | + * EmbeddedChat to modern versions (Node 20, React 18, latest Rocket.Chat APIs). |
| 5 | + */ |
| 6 | + |
| 7 | +const fs = require('fs'); |
| 8 | +const path = require('path'); |
| 9 | + |
| 10 | +const rootDir = process.cwd(); |
| 11 | +const packagePath = path.join(rootDir, 'package.json'); |
| 12 | +const reactPkgPath = path.join(rootDir, 'packages/react/package.json'); |
| 13 | + |
| 14 | +console.log('--- EmbeddedChat 2026: Upgrade & API Audit POC ---\n'); |
| 15 | + |
| 16 | +function auditPackageJson(filePath, label) { |
| 17 | + if (!fs.existsSync(filePath)) { |
| 18 | + console.error(`[Error] ${label} package.json not found.`); |
| 19 | + return; |
| 20 | + } |
| 21 | + const pkg = JSON.parse(fs.readFileSync(filePath, 'utf8')); |
| 22 | + console.log(`[Audit] Scanning ${label}...`); |
| 23 | + console.log(` - Name: ${pkg.name}`); |
| 24 | + console.log(` - Current Version: ${pkg.version}`); |
| 25 | + |
| 26 | + const deps = { ...pkg.dependencies, ...pkg.devDependencies }; |
| 27 | + const criticalUpdates = [ |
| 28 | + { name: 'react', target: '^18.3.0', reason: 'Modernization requirement' }, |
| 29 | + { name: 'node', target: '>=20.0.0', reason: 'LTS requirement' }, |
| 30 | + { name: '@rocket.chat/sdk', target: '^1.0.0', reason: 'API Unified schema support' }, |
| 31 | + { name: 'eslint', target: '^8.0.0', reason: 'Compatibility with React 18 plugins' } |
| 32 | + ]; |
| 33 | + |
| 34 | + criticalUpdates.forEach(update => { |
| 35 | + const current = deps[update.name] || 'Not found'; |
| 36 | + const status = (current === update.target) ? 'OK' : 'NEEDS UPGRADE'; |
| 37 | + console.log(` - ${update.name.padEnd(16)}: ${current.padEnd(10)} -> Target: ${update.target.padEnd(10)} [${status}]`); |
| 38 | + }); |
| 39 | +} |
| 40 | + |
| 41 | +function scanForDeprecatedPatterns(dir) { |
| 42 | + const patterns = [ |
| 43 | + { regex: /ReactDOM\.render/g, name: 'ReactDOM.render', fix: 'createRoot (React 18)' }, |
| 44 | + { regex: /componentWillReceiveProps/g, name: 'Legacy Lifecycle', fix: 'getDerivedStateFromProps' }, |
| 45 | + { regex: /stream-room-messages/g, name: 'Legacy WS Subscription', fix: 'Realtime API v2' } |
| 46 | + ]; |
| 47 | + |
| 48 | + console.log('\n[Code Audit] Scanning for deprecated patterns in src/ ...'); |
| 49 | + |
| 50 | + const files = getAllFiles(dir).filter(f => f.endsWith('.js') || f.endsWith('.jsx')); |
| 51 | + const findings = []; |
| 52 | + |
| 53 | + files.forEach(file => { |
| 54 | + const content = fs.readFileSync(file, 'utf8'); |
| 55 | + patterns.forEach(p => { |
| 56 | + if (p.regex.test(content)) { |
| 57 | + findings.push(`[${p.name}] found in ${path.relative(rootDir, file)}. Suggested fix: ${p.fix}`); |
| 58 | + } |
| 59 | + }); |
| 60 | + }); |
| 61 | + |
| 62 | + if (findings.length > 0) { |
| 63 | + findings.slice(0, 5).forEach(f => console.log(` ! ${f}`)); |
| 64 | + if (findings.length > 5) console.log(` ... and ${findings.length - 5} more findings.`); |
| 65 | + } else { |
| 66 | + console.log(' - No deprecated patterns found in the sampled files.'); |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +function getAllFiles(dirPath, arrayOfFiles) { |
| 71 | + const files = fs.readdirSync(dirPath); |
| 72 | + arrayOfFiles = arrayOfFiles || []; |
| 73 | + files.forEach(function(file) { |
| 74 | + if (fs.statSync(dirPath + "/" + file).isDirectory()) { |
| 75 | + if (file !== 'node_modules' && file !== 'dist') { |
| 76 | + arrayOfFiles = getAllFiles(dirPath + "/" + file, arrayOfFiles); |
| 77 | + } |
| 78 | + } else { |
| 79 | + arrayOfFiles.push(path.join(dirPath, "/", file)); |
| 80 | + } |
| 81 | + }); |
| 82 | + return arrayOfFiles; |
| 83 | +} |
| 84 | + |
| 85 | +auditPackageJson(packagePath, 'Root Monorepo'); |
| 86 | +auditPackageJson(reactPkgPath, 'React Package'); |
| 87 | +scanForDeprecatedPatterns(path.join(rootDir, 'packages/react/src')); |
| 88 | + |
| 89 | +console.log('\n[Conclusion] Automated audit complete. Summary generated for GSoC 2026 Roadmap.'); |
0 commit comments