-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbundle.php
39 lines (32 loc) · 1.01 KB
/
bundle.php
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
<?php
declare(strict_types=1);
use PhpCodeMinifier\MinifierFactory;
require __DIR__ . '/vendor/autoload.php';
function getFiles(string $directory): array
{
$results = [];
foreach (array_diff(scandir($directory), ['.', '..']) as $value) {
$path = realpath($directory . '/' . $value);
if (is_dir($path)) {
$results = array_merge($results, getFiles($path));
} else {
$results[] = $path;
}
}
return $results;
}
$minifier = MinifierFactory::create();
$minified = '';
foreach (getFiles(__DIR__ . '/src') as $file) {
$minified .= substr(
preg_replace(
'/declare\s*\(\s*strict_types\s*=\s*\d+\s*\)\s*;?/',
'',
$minifier->minifyFile($file),
),
6,
);
}
$minified = preg_replace('/namespace\s*(.*?)\s*;(.*?)(?=namespace|$)/s', 'namespace $1{$2}', $minified);
mkdir(__DIR__ . '/dist', recursive: true);
file_put_contents(__DIR__ . '/dist/AWDY.php', '<?php /** @noinspection ALL */ ' . $minified);