woaru
Version:
Universal Project Setup Autopilot - Analyze and automatically configure development tools for ANY programming language
90 lines • 2.39 kB
JavaScript
/**
* HybridBasePlugin - Base class for the new hybrid architecture
*
* Combines secure core plugin logic with dynamic configuration from tools.json
*/
export class HybridBasePlugin {
// ========== UTILITY METHODS ==========
/**
* Check if a file exists
*/
async fileExists(filePath) {
try {
const fs = await import('fs-extra');
return await fs.pathExists(filePath);
}
catch {
return false;
}
}
/**
* Read JSON file safely
*/
async readJsonFile(filePath) {
try {
const fs = await import('fs-extra');
return (await fs.readJson(filePath));
}
catch {
return null;
}
}
/**
* Get file extension
*/
async getFileExtension(filePath) {
const pathModule = await import('path');
const path = pathModule.default || pathModule;
return path.extname(filePath);
}
/**
* Check if file has specific extension
*/
async hasExtension(filePath, extensions) {
const ext = await this.getFileExtension(filePath);
return extensions.includes(ext);
}
/**
* Sanitize command arguments for security
*/
sanitizeArgs(args) {
return args.filter(arg => {
// Remove potentially dangerous arguments
if (arg.includes('&&') || arg.includes('||') || arg.includes(';')) {
return false;
}
if (arg.includes('`') || arg.includes('$(')) {
return false;
}
return true;
});
}
/**
* Validate file path for security
*/
async isValidFilePath(filePath) {
// Basic path traversal protection
if (filePath.includes('..') || filePath.includes('~')) {
return false;
}
// Must be a reasonable file extension
const ext = await this.getFileExtension(filePath);
const allowedExtensions = [
'.js',
'.jsx',
'.ts',
'.tsx',
'.py',
'.rs',
'.go',
'.java',
'.cs',
'.php',
'.rb',
'.vue',
'.svelte',
];
return allowedExtensions.includes(ext);
}
}
//# sourceMappingURL=HybridBasePlugin.js.map