-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-simple.js
More file actions
71 lines (56 loc) · 1.85 KB
/
Copy pathtest-simple.js
File metadata and controls
71 lines (56 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const fs = require('fs');
const path = require('path');
const zlib = require('zlib');
const distPath = path.resolve(__dirname, 'dist');
console.log('Testing bundle size scan...');
console.log('Scanning:', distPath);
console.log('');
function scanDir(dir) {
const files = [];
function walk(currentPath) {
const entries = fs.readdirSync(currentPath, { withFileTypes: true });
for (const entry of entries) {
const fullPath = path.join(currentPath, entry.name);
if (entry.isDirectory()) {
walk(fullPath);
} else if (entry.isFile() && /\.(js|css|cjs|mjs)$/i.test(entry.name)) {
const content = fs.readFileSync(fullPath);
const gzipped = zlib.gzipSync(content);
const brotli = zlib.brotliCompressSync(content);
files.push({
path: path.relative(distPath, fullPath),
size: content.length,
gzip: gzipped.length,
brotli: brotli.length,
});
}
}
}
walk(dir);
return files;
}
try {
const files = scanDir(distPath);
console.log(`Found ${files.length} bundle files:\n`);
let totalSize = 0;
let totalGzip = 0;
let totalBrotli = 0;
files.forEach((f) => {
totalSize += f.size;
totalGzip += f.gzip;
totalBrotli += f.brotli;
console.log(`${f.path}`);
console.log(` Size: ${(f.size / 1024).toFixed(2)} KB`);
console.log(` Gzip: ${(f.gzip / 1024).toFixed(2)} KB`);
console.log(` Brotli: ${(f.brotli / 1024).toFixed(2)} KB`);
console.log('');
});
console.log('TOTALS:');
console.log(` Size: ${(totalSize / 1024).toFixed(2)} KB`);
console.log(` Gzip: ${(totalGzip / 1024).toFixed(2)} KB`);
console.log(` Brotli: ${(totalBrotli / 1024).toFixed(2)} KB`);
console.log('\nTest passed! Action logic works correctly.');
} catch (err) {
console.error('Error:', err.message);
process.exit(1);
}