()
| 72 | } |
| 73 | |
| 74 | function analyzeBuildOutput() { |
| 75 | logSection('Analyzing Build Output'); |
| 76 | |
| 77 | const storybookStaticDir = path.join(process.cwd(), 'storybook-static'); |
| 78 | |
| 79 | if (!fs.existsSync(storybookStaticDir)) { |
| 80 | log('✗ Build output not found', colors.red); |
| 81 | return; |
| 82 | } |
| 83 | |
| 84 | // Get all files |
| 85 | const files = []; |
| 86 | function walkDir(dir) { |
| 87 | const items = fs.readdirSync(dir); |
| 88 | items.forEach(item => { |
| 89 | const fullPath = path.join(dir, item); |
| 90 | const stat = fs.statSync(fullPath); |
| 91 | if (stat.isDirectory()) { |
| 92 | walkDir(fullPath); |
| 93 | } else { |
| 94 | files.push({ |
| 95 | path: fullPath.replace(storybookStaticDir + '/', ''), |
| 96 | size: stat.size, |
| 97 | }); |
| 98 | } |
| 99 | }); |
| 100 | } |
| 101 | walkDir(storybookStaticDir); |
| 102 | |
| 103 | // Calculate total size |
| 104 | const totalSize = files.reduce((sum, file) => sum + file.size, 0); |
| 105 | |
| 106 | // Find largest files |
| 107 | const largestFiles = files |
| 108 | .sort((a, b) => b.size - a.size) |
| 109 | .slice(0, 10); |
| 110 | |
| 111 | log(`Total files: ${files.length}`, colors.blue); |
| 112 | log(`Total size: ${(totalSize / 1024 / 1024).toFixed(2)} MB`, colors.blue); |
| 113 | |
| 114 | log('\nLargest files:', colors.yellow); |
| 115 | largestFiles.forEach((file, index) => { |
| 116 | const sizeKB = (file.size / 1024).toFixed(2); |
| 117 | log(` ${index + 1}. ${file.path} - ${sizeKB} KB`); |
| 118 | }); |
| 119 | |
| 120 | // Analyze chunk files |
| 121 | const chunkFiles = files.filter(f => f.path.includes('.iframe.bundle.js')); |
| 122 | if (chunkFiles.length > 0) { |
| 123 | log(`\nChunk files: ${chunkFiles.length}`, colors.blue); |
| 124 | const totalChunkSize = chunkFiles.reduce((sum, file) => sum + file.size, 0); |
| 125 | log(`Total chunk size: ${(totalChunkSize / 1024 / 1024).toFixed(2)} MB`, colors.blue); |
| 126 | } |
| 127 | |
| 128 | return { |
| 129 | totalFiles: files.length, |
| 130 | totalSize, |
| 131 | largestFiles, |
no test coverage detected