#!/usr/bin/env node /** * Test Discovery Script * Run this to debug why apps aren't being found */ const fs = require('fs'); const path = require('path'); console.log('\n╔══════════════════════════════════════════╗'); console.log('║ MVC App Discovery Tester ║'); console.log('╚══════════════════════════════════════════╝\n'); const rootDir = __dirname; console.log(`Root directory: ${rootDir}`); console.log(`Current directory: ${process.cwd()}\n`); // Test 1: Can we read the root directory? console.log('Test 1: Reading root directory...'); try { const entries = fs.readdirSync(rootDir); console.log(`✅ Root directory readable (${entries.length} items)`); console.log(` Contents:`, entries.slice(0, 10).join(', ') + (entries.length > 10 ? '...' : '')); } catch (e) { console.log(`❌ Cannot read root directory:`, e.message); } // Test 2: Can we find productionYARD2? console.log('\nTest 2: Looking for productionYARD2...'); const prodPath = path.join(rootDir, 'productionYARD2'); console.log(`Path: ${prodPath}`); try { if (fs.existsSync(prodPath)) { console.log('✅ productionYARD2 exists'); } else { console.log('❌ productionYARD2 does not exist'); } } catch (e) { console.log('❌ Error checking productionYARD2:', e.message); } // Test 3: Can we find sysSec-portWatcher? console.log('\nTest 3: Looking for sysSec-portWatcher...'); const sysSecPath = path.join(prodPath, 'sysSec-portWatcher'); console.log(`Path: ${sysSecPath}`); try { if (fs.existsSync(sysSecPath)) { console.log('✅ sysSec-portWatcher exists'); } else { console.log('❌ sysSec-portWatcher does not exist'); } } catch (e) { console.log('❌ Error checking sysSec-portWatcher:', e.message); } // Test 4: Can we find PortWatcher? console.log('\nTest 4: Looking for PortWatcher...'); const portWatcherPath = path.join(sysSecPath, 'PortWatcher'); console.log(`Path: ${portWatcherPath}`); try { if (fs.existsSync(portWatcherPath)) { console.log('✅ PortWatcher exists'); const contents = fs.readdirSync(portWatcherPath); console.log(` Contents (${contents.length} items):`, contents.join(', ')); } else { console.log('❌ PortWatcher does not exist'); } } catch (e) { console.log('❌ Error checking PortWatcher:', e.message); } // Test 5: Can we find PortWatcher.csproj? console.log('\nTest 5: Looking for PortWatcher.csproj...'); const csprojPath = path.join(portWatcherPath, 'PortWatcher.csproj'); console.log(`Path: ${csprojPath}`); try { if (fs.existsSync(csprojPath)) { console.log('✅ PortWatcher.csproj exists'); } else { console.log('❌ PortWatcher.csproj does not exist'); } } catch (e) { console.log('❌ Error checking PortWatcher.csproj:', e.message); } // Test 6: Can we find launchSettings.json? console.log('\nTest 6: Looking for launchSettings.json...'); const launchSettingsPath = path.join(portWatcherPath, 'Properties', 'launchSettings.json'); console.log(`Path: ${launchSettingsPath}`); try { if (fs.existsSync(launchSettingsPath)) { console.log('✅ launchSettings.json exists'); const content = fs.readFileSync(launchSettingsPath, 'utf8'); const settings = JSON.parse(content); console.log(` Profiles:`, Object.keys(settings.profiles || {})); } else { console.log('❌ launchSettings.json does not exist'); } } catch (e) { console.log('❌ Error checking launchSettings.json:', e.message); } // Test 7: Run the full discovery console.log('\n\nTest 7: Running full discovery scan...\n'); function discoverApps() { const apps = []; function scanDir(currentPath, depth = 0) { if (depth > 5) return; try { const entries = fs.readdirSync(currentPath, { withFileTypes: true }); for (const entry of entries) { if (entry.name.startsWith('.') || ['node_modules', '.git', 'obj', 'bin'].includes(entry.name)) { continue; } if (entry.isDirectory()) { const fullPath = path.join(currentPath, entry.name); try { const dirContents = fs.readdirSync(fullPath); const csprojFiles = dirContents.filter(f => f.endsWith('.csproj')); if (csprojFiles.length > 0) { console.log(`Found .csproj in: ${entry.name}`); for (const csprojFile of csprojFiles) { const appName = csprojFile.replace('.csproj', ''); const launchSettingsPath = path.join(fullPath, 'Properties', 'launchSettings.json'); if (fs.existsSync(launchSettingsPath)) { try { let settingsContent = fs.readFileSync(launchSettingsPath, 'utf8'); // Remove BOM if present if (settingsContent.charCodeAt(0) === 0xFEFF) { settingsContent = settingsContent.slice(1); } const launchSettings = JSON.parse(settingsContent); const httpProfile = launchSettings.profiles?.http || launchSettings.profiles?.https || Object.values(launchSettings.profiles || {})[0]; if (httpProfile && httpProfile.applicationUrl) { const url = httpProfile.applicationUrl.split(';')[0]; apps.push({ name: appName, url: url, path: fullPath }); console.log(`✅ Registered: ${appName} -> ${url}`); } } catch (e) { console.log(`❌ Error parsing launchSettings: ${e.message}`); } } } } } catch (e) { // Skip } scanDir(fullPath, depth + 1); } } } catch (e) { console.log(`Error scanning ${currentPath}: ${e.message}`); } } scanDir(rootDir); return apps; } const apps = discoverApps(); console.log(`\n✨ Discovery Results: ${apps.length} app(s) found\n`); if (apps.length === 0) { console.log('❌ NO APPS FOUND!'); console.log('\nDebugging tips:'); console.log('1. Verify PortWatcher.csproj exists'); console.log('2. Verify launchSettings.json exists'); console.log('3. Check that JSON is valid'); console.log('4. Verify the HTTP profile exists'); } else { apps.forEach(app => { console.log(`App: ${app.name}`); console.log(` URL: ${app.url}`); console.log(` Path: ${app.path}`); }); } console.log('\n');