@re-shell/cli
Version:
Full-stack development platform uniting microservices and microfrontends. Build complete applications with .NET (ASP.NET Core Web API, Minimal API), Java (Spring Boot, Quarkus, Micronaut, Vert.x), Rust (Actix-Web, Warp, Rocket, Axum), Python (FastAPI, Dja
225 lines (224 loc) โข 11.7 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.testPlatformCapabilities = testPlatformCapabilities;
exports.runPlatformDiagnostics = runPlatformDiagnostics;
exports.quickPlatformCheck = quickPlatformCheck;
const chalk_1 = __importDefault(require("chalk"));
const spinner_1 = require("../utils/spinner");
const error_handler_1 = require("../utils/error-handler");
const file_watcher_1 = require("../utils/file-watcher");
// Test platform file watching capabilities
async function testPlatformCapabilities(options = {}) {
const { verbose = false, json = false, test = false, capabilities = false, all = false } = options;
try {
if (all || capabilities) {
const spinner = (0, spinner_1.createSpinner)('Detecting platform capabilities...');
spinner.start();
const platformCapabilities = (0, file_watcher_1.getPlatformCapabilities)();
spinner.stop();
if (json) {
console.log(JSON.stringify(platformCapabilities, null, 2));
return;
}
console.log(chalk_1.default.cyan('\n๐ Platform File Watching Capabilities\n'));
displayPlatformCapabilities(platformCapabilities, verbose);
}
if (all || test) {
const spinner = (0, spinner_1.createSpinner)('Testing file watching methods...');
spinner.start();
const testResults = await (0, file_watcher_1.testPlatformWatching)();
spinner.stop();
if (json && !capabilities && !all) {
console.log(JSON.stringify(testResults, null, 2));
return;
}
console.log(chalk_1.default.cyan('\n๐งช File Watching Method Tests\n'));
displayTestResults(testResults, verbose);
}
if (all) {
console.log(chalk_1.default.cyan('\n๐ Platform Optimization Test\n'));
const spinner = (0, spinner_1.createSpinner)('Testing cross-platform watcher...');
spinner.start();
const watcher = await (0, file_watcher_1.createCrossPlatformWatcher)();
const stats = watcher.getStats();
await watcher.stopWatching();
spinner.stop();
console.log(chalk_1.default.green('โ
Cross-platform watcher created successfully'));
console.log(chalk_1.default.gray(` Platform: ${stats.platformCapabilities.platform}`));
console.log(chalk_1.default.gray(` Recommended method: ${stats.platformCapabilities.recommendedWatchMethod}`));
console.log(chalk_1.default.gray(` Max watched files: ${stats.platformCapabilities.maxWatchedFiles.toLocaleString()}`));
}
if (!test && !capabilities && !all) {
// Default: show basic capabilities
const platformCapabilities = (0, file_watcher_1.getPlatformCapabilities)();
displayPlatformCapabilities(platformCapabilities, false);
}
}
catch (error) {
throw new error_handler_1.ValidationError(`Platform test failed: ${error instanceof Error ? error.message : String(error)}`);
}
}
// Display platform capabilities in formatted output
function displayPlatformCapabilities(capabilities, verbose) {
console.log(chalk_1.default.yellow('Platform Information:'));
console.log(` OS: ${chalk_1.default.white(capabilities.platform)} (${capabilities.architecture})`);
console.log(` Recommended method: ${chalk_1.default.green(capabilities.recommendedWatchMethod)}`);
console.log(` Max watched files: ${chalk_1.default.white(capabilities.maxWatchedFiles.toLocaleString())}`);
console.log(chalk_1.default.yellow('\nSupported Methods:'));
console.log(` Native watching: ${capabilities.supportsNativeWatching ? chalk_1.default.green('โ') : chalk_1.default.red('โ')}`);
console.log(` Polling: ${capabilities.supportsPolling ? chalk_1.default.green('โ') : chalk_1.default.red('โ')}`);
console.log(` FSEvents (macOS): ${capabilities.supportsFSEvents ? chalk_1.default.green('โ') : chalk_1.default.red('โ')}`);
console.log(` inotify (Linux): ${capabilities.supportsInotify ? chalk_1.default.green('โ') : chalk_1.default.red('โ')}`);
console.log(chalk_1.default.yellow('\\nFallback Methods:'));
capabilities.fallbackMethods.forEach((method, index) => {
console.log(` ${index + 1}. ${chalk_1.default.white(method)}`);
});
if (capabilities.limitations.length > 0) {
console.log(chalk_1.default.yellow('\\nKnown Limitations:'));
capabilities.limitations.forEach((limitation, index) => {
console.log(` ${index + 1}. ${chalk_1.default.gray(limitation)}`);
});
}
if (verbose) {
console.log(chalk_1.default.yellow('\\nDetailed Information:'));
console.log(` Architecture: ${capabilities.architecture}`);
console.log(` Platform: ${capabilities.platform}`);
console.log(` Native support: ${capabilities.supportsNativeWatching}`);
console.log(` Polling support: ${capabilities.supportsPolling}`);
console.log(` FSEvents support: ${capabilities.supportsFSEvents}`);
console.log(` inotify support: ${capabilities.supportsInotify}`);
}
}
// Display test results in formatted output
function displayTestResults(results, verbose) {
console.log(chalk_1.default.yellow('Test Results:'));
console.log(` Platform: ${chalk_1.default.white(results.platform)}`);
console.log(` Native watching: ${results.nativeWatching ? chalk_1.default.green('โ PASS') : chalk_1.default.red('โ FAIL')}`);
console.log(` Polling: ${results.polling ? chalk_1.default.green('โ PASS') : chalk_1.default.red('โ FAIL')}`);
if (results.platform === 'darwin') {
console.log(` FSEvents: ${results.fsevents ? chalk_1.default.green('โ PASS') : chalk_1.default.red('โ FAIL')}`);
}
if (results.platform === 'linux') {
console.log(` inotify: ${results.inotify ? chalk_1.default.green('โ PASS') : chalk_1.default.red('โ FAIL')}`);
}
console.log(` Max watched files: ${chalk_1.default.white(results.maxWatchedFiles.toLocaleString())}`);
if (results.recommendations.length > 0) {
console.log(chalk_1.default.yellow('\\nRecommendations:'));
results.recommendations.forEach((rec, index) => {
console.log(` ${index + 1}. ${chalk_1.default.cyan(rec)}`);
});
}
if (verbose) {
console.log(chalk_1.default.yellow('\\nDetailed Test Results:'));
console.log(JSON.stringify(results, null, 2));
}
}
// Run comprehensive platform diagnostics
async function runPlatformDiagnostics(options = {}) {
const { verbose = false, json = false } = options;
try {
const spinner = (0, spinner_1.createSpinner)('Running comprehensive platform diagnostics...');
spinner.start();
// Get capabilities
const capabilities = (0, file_watcher_1.getPlatformCapabilities)();
// Run tests
const testResults = await (0, file_watcher_1.testPlatformWatching)();
// Test cross-platform watcher
const watcher = await (0, file_watcher_1.createCrossPlatformWatcher)();
const watcherStats = watcher.getStats();
await watcher.stopWatching();
spinner.stop();
const diagnostics = {
timestamp: new Date().toISOString(),
capabilities,
testResults,
watcherStats: {
platformCapabilities: watcherStats.platformCapabilities,
activeWatchers: watcherStats.activeWatchers,
watcherFailures: watcherStats.watcherFailures
},
recommendations: generateRecommendations(capabilities, testResults)
};
if (json) {
console.log(JSON.stringify(diagnostics, null, 2));
return;
}
console.log(chalk_1.default.cyan('\\n๐ Platform File Watching Diagnostics\\n'));
displayPlatformCapabilities(capabilities, verbose);
console.log('');
displayTestResults(testResults, verbose);
console.log(chalk_1.default.cyan('\\n๐ก Recommendations\\n'));
diagnostics.recommendations.forEach((rec, index) => {
console.log(`${index + 1}. ${chalk_1.default.white(rec)}`);
});
}
catch (error) {
throw new error_handler_1.ValidationError(`Platform diagnostics failed: ${error instanceof Error ? error.message : String(error)}`);
}
}
// Generate platform-specific recommendations
function generateRecommendations(capabilities, testResults) {
const recommendations = [];
// Basic functionality checks
if (!testResults.nativeWatching && testResults.polling) {
recommendations.push('Use polling-based file watching for reliability on this platform');
}
if (!testResults.polling) {
recommendations.push('โ ๏ธ Critical: Polling is not working - file watching may not function properly');
}
// Platform-specific recommendations
switch (capabilities.platform) {
case 'linux':
if (capabilities.maxWatchedFiles < 65536) {
recommendations.push('Consider increasing inotify limits: echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf');
}
if (!testResults.inotify) {
recommendations.push('inotify is not working - check kernel configuration and permissions');
}
break;
case 'darwin':
if (!testResults.fsevents) {
recommendations.push('FSEvents is not working - check macOS permissions and disk access');
}
recommendations.push('Enable full disk access for your terminal app in System Preferences > Security & Privacy');
break;
case 'win32':
recommendations.push('Enable Developer Mode in Windows Settings for better file watching performance');
if (capabilities.maxWatchedFiles < 16384) {
recommendations.push('Consider increasing Windows file watching limits in the registry');
}
break;
default:
recommendations.push('Unknown platform - use polling for maximum compatibility');
break;
}
// Performance recommendations
if (capabilities.maxWatchedFiles < 8192) {
recommendations.push('Low file watching limits detected - consider using selective watching for large projects');
}
// General recommendations
recommendations.push('Use .gitignore patterns to exclude unnecessary files from watching');
recommendations.push('Consider using workspace-level watching instead of repository-wide watching for better performance');
return recommendations;
}
// Quick platform check
async function quickPlatformCheck() {
try {
const capabilities = (0, file_watcher_1.getPlatformCapabilities)();
const testResults = await (0, file_watcher_1.testPlatformWatching)();
// Basic health check
const isHealthy = testResults.polling || testResults.nativeWatching;
if (!isHealthy) {
console.log(chalk_1.default.red('โ ๏ธ Platform file watching may not work properly'));
console.log(chalk_1.default.gray(' Run: re-shell platform-test --all for detailed diagnostics'));
}
return isHealthy;
}
catch (error) {
console.log(chalk_1.default.red('โ ๏ธ Failed to check platform file watching capabilities'));
return false;
}
}