@casoon/auditmysite
Version:
Professional website analysis suite with robust accessibility testing, Core Web Vitals performance monitoring, SEO analysis, and content optimization insights. Features isolated browser contexts, retry mechanisms, and comprehensive API endpoints for profe
139 lines • 3.44 kB
JavaScript
;
/**
* 🔧 Base Command Class
*
* Abstract base class for all CLI commands.
* Implements the Command Pattern for better separation of concerns.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaseCommand = void 0;
class BaseCommand {
constructor(name, description) {
this.name = name;
this.description = description;
}
/**
* Validate command arguments
*/
validate(args) {
// Default implementation - override in subclasses
return { valid: true, errors: [] };
}
/**
* Get command name
*/
getName() {
return this.name;
}
/**
* Get command description
*/
getDescription() {
return this.description;
}
/**
* Format error messages
*/
formatError(error) {
if (error instanceof Error) {
return error.message;
}
return String(error);
}
/**
* Create success result
*/
success(message, data) {
return {
success: true,
message,
data,
exitCode: 0
};
}
/**
* Create error result
*/
error(message, exitCode = 1) {
return {
success: false,
message,
exitCode
};
}
/**
* Log progress message
*/
logProgress(message) {
console.log(`🚀 ${message}`);
}
/**
* Log success message
*/
logSuccess(message) {
console.log(`✅ ${message}`);
}
/**
* Log warning message
*/
logWarning(message) {
console.log(`⚠️ ${message}`);
}
/**
* Log error message
*/
logError(message) {
console.error(`❌ ${message}`);
}
/**
* Format duration in human-readable format
*/
formatDuration(ms) {
if (ms < 1000)
return `${ms}ms`;
const seconds = Math.floor(ms / 1000);
if (seconds < 60)
return `${seconds}s`;
const minutes = Math.floor(seconds / 60);
const remainingSeconds = seconds % 60;
return `${minutes}m ${remainingSeconds}s`;
}
/**
* Parse sitemap URL and validate
*/
validateSitemapUrl(url) {
try {
const parsedUrl = new URL(url);
// Check if it's a valid HTTP/HTTPS URL
if (!['http:', 'https:'].includes(parsedUrl.protocol)) {
return { valid: false, error: 'URL must use HTTP or HTTPS protocol' };
}
// Check if it looks like a sitemap
const path = parsedUrl.pathname.toLowerCase();
if (!path.includes('sitemap') && !path.endsWith('.xml')) {
return {
valid: false,
error: 'URL should point to a sitemap.xml file or contain "sitemap" in the path'
};
}
return { valid: true };
}
catch (error) {
return { valid: false, error: 'Invalid URL format' };
}
}
/**
* Extract domain from URL for reporting
*/
extractDomain(url) {
try {
const parsedUrl = new URL(url);
return parsedUrl.hostname.replace(/\./g, '-');
}
catch {
return 'unknown-domain';
}
}
}
exports.BaseCommand = BaseCommand;
//# sourceMappingURL=base-command.js.map