File size: 7,102 Bytes
0e0fe0a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/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');