@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
385 lines • 12.9 kB
JavaScript
"use strict";
/**
* 🔧 Configuration Sources
*
* Different sources for configuration data with priority handling.
*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultConfigSource = exports.EnvironmentConfigSource = exports.PackageJsonConfigSource = exports.AuditRCSource = exports.JSONConfigSource = exports.JSConfigSource = exports.CLIConfigSource = exports.BaseConfigSource = void 0;
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
class BaseConfigSource {
}
exports.BaseConfigSource = BaseConfigSource;
/**
* CLI Configuration Source - Highest priority
*/
class CLIConfigSource extends BaseConfigSource {
constructor(cliArgs) {
super();
this.cliArgs = cliArgs;
}
async isAvailable() {
return Object.keys(this.cliArgs).length > 0;
}
async load() {
const config = {};
// Map CLI arguments to config structure
if (this.cliArgs.maxPages)
config.maxPages = this.cliArgs.maxPages;
if (this.cliArgs.sitemapUrl)
config.sitemapUrl = this.cliArgs.sitemapUrl;
if (this.cliArgs.format || this.cliArgs.outputDir) {
config.output = {
format: this.cliArgs.format || 'html',
outputDir: this.cliArgs.outputDir
};
}
if (this.cliArgs.budget || this.cliArgs.lcpBudget || this.cliArgs.clsBudget) {
config.performance = {
budgets: this.cliArgs.budget || 'default',
customBudgets: {}
};
if (this.cliArgs.lcpBudget) {
config.performance.customBudgets.lcp = {
good: this.cliArgs.lcpBudget,
poor: this.cliArgs.lcpBudget * 1.6
};
}
if (this.cliArgs.clsBudget) {
config.performance.customBudgets.cls = {
good: this.cliArgs.clsBudget,
poor: this.cliArgs.clsBudget * 2.5
};
}
if (this.cliArgs.fcpBudget) {
config.performance.customBudgets.fcp = {
good: this.cliArgs.fcpBudget,
poor: this.cliArgs.fcpBudget * 1.7
};
}
if (this.cliArgs.inpBudget) {
config.performance.customBudgets.inp = {
good: this.cliArgs.inpBudget,
poor: this.cliArgs.inpBudget * 2.5
};
}
if (this.cliArgs.ttfbBudget) {
config.performance.customBudgets.ttfb = {
good: this.cliArgs.ttfbBudget,
poor: this.cliArgs.ttfbBudget * 2
};
}
}
if (this.cliArgs.unifiedQueue || this.cliArgs.maxConcurrent) {
config.testing = {
queueType: this.cliArgs.unifiedQueue ? 'parallel' : 'simple',
parallel: {
enabled: true,
maxConcurrent: this.cliArgs.maxConcurrent || 2
}
};
}
return {
type: 'cli',
priority: 100, // Highest priority
data: config
};
}
}
exports.CLIConfigSource = CLIConfigSource;
/**
* JavaScript Configuration File Source
*/
class JSConfigSource extends BaseConfigSource {
constructor(filename = 'audit.config.js') {
super();
this.filename = filename;
}
async isAvailable(basePath = process.cwd()) {
const configPath = path.join(basePath, this.filename);
return fs.existsSync(configPath);
}
async load(basePath = process.cwd()) {
const configPath = path.join(basePath, this.filename);
if (!await this.isAvailable(basePath)) {
return null;
}
try {
// Clear require cache to allow hot reloading
delete require.cache[require.resolve(configPath)];
const configModule = require(configPath);
const config = configModule.default || configModule;
return {
type: 'file',
path: configPath,
priority: 90,
data: config
};
}
catch (error) {
throw new Error(`Failed to load ${this.filename}: ${error}`);
}
}
}
exports.JSConfigSource = JSConfigSource;
/**
* JSON Configuration File Source
*/
class JSONConfigSource extends BaseConfigSource {
constructor(filename = 'audit.config.json') {
super();
this.filename = filename;
}
async isAvailable(basePath = process.cwd()) {
const configPath = path.join(basePath, this.filename);
return fs.existsSync(configPath);
}
async load(basePath = process.cwd()) {
const configPath = path.join(basePath, this.filename);
if (!await this.isAvailable(basePath)) {
return null;
}
try {
const configContent = fs.readFileSync(configPath, 'utf8');
const config = JSON.parse(configContent);
return {
type: 'file',
path: configPath,
priority: 85,
data: config
};
}
catch (error) {
throw new Error(`Failed to load ${this.filename}: ${error}`);
}
}
}
exports.JSONConfigSource = JSONConfigSource;
/**
* .auditrc Configuration File Source
*/
class AuditRCSource extends BaseConfigSource {
constructor(filename = '.auditrc') {
super();
this.filename = filename;
}
async isAvailable(basePath = process.cwd()) {
const configPath = path.join(basePath, this.filename);
return fs.existsSync(configPath);
}
async load(basePath = process.cwd()) {
const configPath = path.join(basePath, this.filename);
if (!await this.isAvailable(basePath)) {
return null;
}
try {
const configContent = fs.readFileSync(configPath, 'utf8');
// Try JSON first, then YAML
let config;
try {
config = JSON.parse(configContent);
}
catch {
// Try YAML parsing if available
try {
const yaml = require('js-yaml');
config = yaml.load(configContent);
}
catch {
throw new Error('Config file must be valid JSON or YAML');
}
}
return {
type: 'file',
path: configPath,
priority: 80,
data: config
};
}
catch (error) {
throw new Error(`Failed to load ${this.filename}: ${error}`);
}
}
}
exports.AuditRCSource = AuditRCSource;
/**
* Package.json Configuration Source
*/
class PackageJsonConfigSource extends BaseConfigSource {
async isAvailable(basePath = process.cwd()) {
const packagePath = path.join(basePath, 'package.json');
if (!fs.existsSync(packagePath))
return false;
try {
const packageContent = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
return packageContent.auditConfig !== undefined;
}
catch {
return false;
}
}
async load(basePath = process.cwd()) {
const packagePath = path.join(basePath, 'package.json');
if (!await this.isAvailable(basePath)) {
return null;
}
try {
const packageContent = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
const config = packageContent.auditConfig;
return {
type: 'package.json',
path: packagePath,
priority: 70,
data: config
};
}
catch (error) {
throw new Error(`Failed to load package.json config: ${error}`);
}
}
}
exports.PackageJsonConfigSource = PackageJsonConfigSource;
/**
* Environment Variables Configuration Source
*/
class EnvironmentConfigSource extends BaseConfigSource {
async isAvailable() {
// Check for common environment variables
return !!(process.env.AUDIT_SITEMAP_URL ||
process.env.AUDIT_MAX_PAGES ||
process.env.AUDIT_OUTPUT_FORMAT ||
process.env.AUDIT_BUDGET);
}
async load() {
if (!await this.isAvailable()) {
return null;
}
const config = {};
if (process.env.AUDIT_SITEMAP_URL) {
config.sitemapUrl = process.env.AUDIT_SITEMAP_URL;
}
if (process.env.AUDIT_MAX_PAGES) {
config.maxPages = parseInt(process.env.AUDIT_MAX_PAGES, 10);
}
if (process.env.AUDIT_OUTPUT_FORMAT || process.env.AUDIT_OUTPUT_DIR) {
config.output = {
format: process.env.AUDIT_OUTPUT_FORMAT || 'html',
outputDir: process.env.AUDIT_OUTPUT_DIR
};
}
if (process.env.AUDIT_BUDGET) {
config.performance = {
budgets: process.env.AUDIT_BUDGET
};
}
return {
type: 'environment',
priority: 60,
data: config
};
}
}
exports.EnvironmentConfigSource = EnvironmentConfigSource;
/**
* Default Configuration Source - Lowest priority
*/
class DefaultConfigSource extends BaseConfigSource {
async isAvailable() {
return true; // Always available
}
async load() {
const config = {
maxPages: 5,
standards: {
wcag: 'WCAG2AA',
strictMode: false,
failOnWarnings: false
},
performance: {
budgets: 'default',
collectMetrics: ['LCP', 'FCP', 'CLS', 'INP', 'TTFB'],
ignoreThresholds: false
},
output: {
format: 'html',
outputDir: './reports',
interactive: true,
detailedFixes: true
},
testing: {
parallel: {
enabled: true,
maxConcurrent: 2,
retries: 3
},
screenshots: {
enabled: false,
onErrors: true,
responsive: ['desktop']
},
coverage: {
accessibility: true,
performance: true,
seo: false,
security: false
},
queueType: 'parallel'
},
reporting: {
outputDir: './reports',
formats: ['html']
},
framework: {
type: 'static'
},
advanced: {
browser: {
viewport: { width: 1920, height: 1080 },
userAgent: 'auditmysite/1.6.0 (+https://github.com/casoon/AuditMySite)'
},
waitConditions: ['domcontentloaded']
}
};
return {
type: 'default',
priority: 10, // Lowest priority
data: config
};
}
}
exports.DefaultConfigSource = DefaultConfigSource;
//# sourceMappingURL=config-sources.js.map