forked from phpmetrics/PhpMetrics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.php
59 lines (47 loc) · 1.57 KB
/
build.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
<?php
chdir(__DIR__);
if (!file_exists('vendor/autoload.php')) {
echo '[ERROR] It\'s required to run "composer install" before building PhpMetrics!' . PHP_EOL;
exit(1);
}
$filename = 'build/phpmetrics.phar';
if (file_exists($filename)) {
unlink($filename);
}
$phar = new \Phar($filename, 0, 'phpmetrics.phar');
$phar->setSignatureAlgorithm(\Phar::SHA1);
$phar->startBuffering();
$files = array_merge(rglob('*.php'), rglob('*.twig'), rglob('*.json'), rglob('*.pp'));
$exclude = '!(.git)|(.svn)|(bin)|(tests)|(Tests)|(phpmetrics)!';
foreach($files as $file) {
if(preg_match($exclude, $file)) continue;
$path = str_replace(__DIR__.'/', '', $file);
$phar->addFromString($path, file_get_contents($file));
}
$phar->setStub(<<<STUB
#!/usr/bin/env php
<?php
/*
* This file is part of the PhpMetrics
*
* (c) Jean-François Lépine
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
Phar::mapPhar('phpmetrics.phar');
require_once 'phar://phpmetrics.phar/vendor/autoload.php';
\$app = new Hal\Application\Console\PhpMetricsApplication('PhpMetrics, by Jean-François Lépine (https://twitter.com/Halleck45)', '<VERSION>'); // version will be inserted by build.
\$app->run();
__HALT_COMPILER();
STUB
);
$phar->stopBuffering();
chmod($filename, 0755);
function rglob($pattern='*', $flags = 0, $path='')
{
$paths=glob($path.'*', GLOB_MARK|GLOB_ONLYDIR|GLOB_NOSORT);
$files=glob($path.$pattern, $flags);
foreach ($paths as $path) { $files=array_merge($files,rglob($pattern, $flags, $path)); }
return $files;
}