-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathbuild.php
More file actions
64 lines (47 loc) · 1.83 KB
/
Copy pathbuild.php
File metadata and controls
64 lines (47 loc) · 1.83 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
<?php
/**
* Consent Manager Build Script
* Minifies JavaScript files for production use.
*/
echo "Consent Manager Build Script\n";
echo "===========================\n\n";
// Files to minify
$files = [
'consent_manager_frontend.js' => 'consent_manager_frontend.min.js',
'google_consent_mode_v2.js' => 'google_consent_mode_v2.min.js',
];
$addonPath = __DIR__ . '/assets/';
foreach ($files as $source => $target) {
$sourcePath = $addonPath . $source;
$targetPath = $addonPath . $target;
if (!file_exists($sourcePath)) {
echo "❌ Source file not found: $source\n";
continue;
}
echo "📄 Processing $source...\n";
// Read source file
$content = (string) file_get_contents($sourcePath);
// Basic minification (remove comments, extra whitespace)
$minified = $content;
// Remove single-line comments (but keep important ones)
$minified = preg_replace('/\/\/.*$/m', '', $minified);
// Remove multi-line comments
$minified = preg_replace('/\/\*.*?\*\//s', '', $minified);
// Remove extra whitespace and newlines
$minified = preg_replace('/\s+/', ' ', $minified);
$minified = preg_replace('/\s*([{}();,])\s*/', '$1', $minified);
// Remove trailing/leading whitespace
$minified = trim($minified);
// Write minified file
if (false !== file_put_contents($targetPath, $minified)) {
$originalSize = (int) filesize($sourcePath);
$minifiedSize = (int) filesize($targetPath);
$reduction = round((1 - $minifiedSize / $originalSize) * 100, 1);
echo "✅ Created $target ({$minifiedSize} bytes, {$reduction}% reduction)\n";
} else {
echo "❌ Failed to create $target\n";
}
echo "\n";
}
echo "Build completed!\n";
echo "Note: This is basic minification. For better compression, use a proper minifier like Terser.\n";