-
Notifications
You must be signed in to change notification settings - Fork 50
/
build-phar.php
89 lines (80 loc) · 2.53 KB
/
build-phar.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
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
@unlink('cloud-clipboard.phar');
@unlink('cloud-clipboard-gz.phar');
@unlink('cloud-clipboard-bz2.phar');
$phar = new Phar('cloud-clipboard.phar');
foreach ([
'server/App',
'server/vendor',
'server/static',
'server/main.php',
] as $path) {
if (is_file($path)) {
$files = [$path];
} else {
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS)
);
}
foreach ($files as $file) {
$file = str_replace('\\', '/', $file);
if (is_dir($file)) continue;
$excluded = false;
foreach ([
'.git',
'.gitignore',
'.codeclimate.yml',
'.travis.yml',
'phpunit.xml',
'doc',
'docs',
'test',
'test_old',
'tests',
'example',
'examples',
'sample',
'samples',
'vendor-bin',
'ide-helper',
] as $keyword) {
if (in_array($keyword, explode('/', $file))) {
$excluded = true;
break;
}
}
if ($excluded) continue;
$localname = preg_replace('/^(server\/)/', '', $file);
$minify = false;
if (pathinfo($file, PATHINFO_EXTENSION) === 'php' || pathinfo($file, PATHINFO_EXTENSION) === 'php4') {
$minify = true;
$minified = php_strip_whitespace($file);
} else if (pathinfo($file, PATHINFO_EXTENSION) === 'json') {
$minify = true;
$minified = json_encode(json_decode(file_get_contents($file), true), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}
if ($minify) {
$phar->addFromString($localname, $minified);
} else {
$phar->addFile($file, $localname);
}
echo $file . ($minify ? " (minified)\n" : "\n");
}
}
file_put_contents('.stub', $phar->createDefaultStub('main.php'));
$phar->setStub(php_strip_whitespace('.stub'));
$phar->stopBuffering();
unlink('.stub');
// $phar->extractTo('extract');
if (extension_loaded('zlib')) {
copy('cloud-clipboard.phar', 'cloud-clipboard-gz.phar');
(new Phar('cloud-clipboard-gz.phar'))->compressFiles(Phar::GZ);
} else {
echo "GZ compression is not enabled.\n";
}
if (extension_loaded('bz2')) {
copy('cloud-clipboard.phar', 'cloud-clipboard-bz2.phar');
(new Phar('cloud-clipboard-bz2.phar'))->compressFiles(Phar::BZ2);
} else {
echo "BZ2 compression is not enabled.\n";
}