perf-audit-cli
Version: 
CLI tool for continuous performance monitoring and analysis
49 lines • 2 kB
JavaScript
import { BundleAnalyzer } from "../core/bundle-analyzer.js";
import { getCurrentTimestamp } from "./command-helpers.js";
export const applyBudgetsToAllBundles = (bundles, config) => {
    const clientBundles = bundles.filter(b => b.type === 'client');
    const serverBundles = bundles.filter(b => b.type === 'server');
    const bundlesWithBudgets = [];
    if (clientBundles.length > 0) {
        const clientBundlesWithBudgets = BundleAnalyzer.applyBudgets(clientBundles, config.budgets.client.bundles);
        bundlesWithBudgets.push(...clientBundlesWithBudgets);
    }
    if (serverBundles.length > 0) {
        const serverBundlesWithBudgets = BundleAnalyzer.applyBudgets(serverBundles, config.budgets.server.bundles);
        bundlesWithBudgets.push(...serverBundlesWithBudgets);
    }
    return bundlesWithBudgets;
};
export const getBudgetStatus = (bundles, totalStatus) => {
    const bundleHasError = bundles.some(b => b.status === 'error');
    const bundleHasWarning = bundles.some(b => b.status === 'warning');
    if (totalStatus) {
        const hasError = bundleHasError || totalStatus === 'error';
        const hasWarning = bundleHasWarning || totalStatus === 'warning';
        if (hasError)
            return 'error';
        if (hasWarning)
            return 'warning';
        return 'ok';
    }
    else {
        if (bundleHasError)
            return 'error';
        if (bundleHasWarning)
            return 'warning';
        return 'ok';
    }
};
export const createAuditResult = (bundlesWithBudgets, config, recommendations = []) => {
    const serverBundles = bundlesWithBudgets.filter(b => b.type === 'server');
    const clientBundles = bundlesWithBudgets.filter(b => b.type === 'client');
    return {
        timestamp: getCurrentTimestamp(),
        serverBundles,
        clientBundles,
        recommendations,
        budgetStatus: getBudgetStatus(bundlesWithBudgets),
        analysisType: config.analysis.target,
    };
};
//# sourceMappingURL=bundle.js.map