codebase-asset-optimizer
Version:
Professional CLI development tool for optimizing and managing assets in codebases. Detects unused assets, optimizes images to WebP, optimizes videos, and automatically replaces asset references. GIFs are preserved unchanged to maintain animation functiona
214 lines • 6.49 kB
TypeScript
/**
* Core types and interfaces for the Asset Optimizer
*/
export interface AssetInfo {
/** Original filename */
filename: string;
/** Full absolute path to the file */
fullPath: string;
/** Relative path from project root */
relativePath: string;
/** File size in bytes */
size: number;
/** File extension (including dot) */
extension: string;
/** Asset type: 'image' or 'video' */
assetType: "image" | "video";
/** Whether the asset is used in the codebase */
used: boolean;
/** List of file references where this asset is used */
references: AssetReference[];
/** Whether this asset can be optimized */
optimizable: boolean;
/** MIME type of the asset */
mimeType?: string;
}
export interface AssetReference {
/** File path where the asset is referenced */
file: string;
/** The search pattern that matched */
pattern: string;
/** Line number where the reference was found */
line?: number;
/** Context around the reference */
context: string;
}
export interface OptimizationResult {
/** Whether the optimization was successful */
success: boolean;
/** Original file size in bytes */
originalSize: number;
/** New file size in bytes */
newSize: number;
/** Percentage savings (negative if file got larger) */
savings: number;
/** Output format used */
format?: string;
/** Error message if optimization failed */
error?: string;
/** Path to the optimized file */
outputPath?: string;
}
export interface AuditResults {
/** Total number of assets found */
totalAssets: number;
/** Total size of all assets in bytes */
totalSize: number;
/** Assets that are in use */
usedAssets: AssetInfo[];
/** Assets that are not used */
unusedAssets: AssetInfo[];
/** Large assets (over threshold) */
largeAssets: AssetInfo[];
/** Assets that can be optimized */
optimizableAssets: AssetInfo[];
/** Summary statistics */
summary: AuditSummary;
}
export interface AuditSummary {
/** Number of used assets */
usedCount: number;
/** Total size of used assets */
usedSize: number;
/** Number of unused assets */
unusedCount: number;
/** Total size of unused assets */
unusedSize: number;
/** Number of large unused assets */
largeUnusedCount: number;
/** Number of large used assets */
largeUsedCount: number;
/** Number of assets that can be optimized */
optimizableCount: number;
/** Total size of optimizable assets */
optimizableSize: number;
/** Potential savings from removing unused assets */
potentialSavings: number;
/** Breakdown by asset type */
assetsByType: {
images: AssetTypeStats;
videos: AssetTypeStats;
};
}
export interface AssetTypeStats {
/** Total count of this asset type */
total: number;
/** Number used */
used: number;
/** Number unused */
unused: number;
/** Number that can be optimized */
optimizable: number;
}
export interface OptimizerConfig {
/** Project root directory */
projectRoot: string;
/** Public/assets directory to scan */
publicDir: string;
/** Source code directory to search for references */
sourceDir: string;
/** Image file extensions to process */
imageExtensions: string[];
/** Video file extensions to process */
videoExtensions: string[];
/** Patterns to exclude from scanning */
excludePatterns: string[];
/** File size threshold for "large" files */
largeFileThreshold: number;
/** Path for audit reports */
reportFile: string;
/** Backup directory */
backupDir: string;
/** Optimization settings */
optimization: OptimizationSettings;
}
export interface OptimizationSettings {
/** Image optimization settings */
images: {
/** Target format (default: webp) */
targetFormat: string;
/** Quality setting (0-100) */
quality: number;
/** Maximum width */
maxWidth: number;
/** Maximum height */
maxHeight: number;
/** Only optimize if size reduction is achieved */
onlyIfSmaller: boolean;
};
/** Video optimization settings */
videos: {
/** Target formats to try */
targetFormats: string[];
/** Quality setting */
quality: string;
/** Maximum width */
maxWidth: number;
/** Maximum height */
maxHeight: number;
/** Only optimize if size reduction is achieved */
onlyIfSmaller: boolean;
};
}
export interface BackupInfo {
/** Timestamp when backup was created */
timestamp: string;
/** List of backed up files */
files: string[];
/** Backup directory path */
backupPath: string;
}
export interface ReplacementOperation {
/** File path where replacement occurred */
filePath: string;
/** Original asset path */
originalPath: string;
/** New asset path */
newPath: string;
/** Number of replacements made */
replacements: number;
/** Whether the operation was successful */
success: boolean;
/** Error message if operation failed */
error?: string;
}
export interface ProcessingStats {
/** Number of assets processed */
processed: number;
/** Number of assets optimized successfully */
optimized: number;
/** Number of assets that failed optimization */
failed: number;
/** Total size before optimization */
sizeBefore: number;
/** Total size after optimization */
sizeAfter: number;
/** Total time taken in milliseconds */
duration: number;
}
export type LogLevel = "error" | "warn" | "info" | "debug";
export interface CliOptions {
/** Project directory */
dir?: string;
/** Working directory */
cwd?: string;
/** Public/assets directory */
publicDir?: string;
/** Source directory to scan for references */
sourceDir?: string;
/** Enable backup creation */
backup?: boolean;
/** Skip confirmation prompts */
yes?: boolean;
/** Verbose output */
verbose?: boolean;
/** Dry run mode */
dryRun?: boolean;
/** Force operation without size checks */
force?: boolean;
/** Only process unused assets */
unusedOnly?: boolean;
/** Only process optimizable assets */
optimizableOnly?: boolean;
}
//# sourceMappingURL=types.d.ts.map