-
Notifications
You must be signed in to change notification settings - Fork 11
/
compile.php
67 lines (50 loc) · 1.83 KB
/
compile.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
#!/usr/bin/env php
<?php
// Embed commit hash to altax source.
$containerSourcePath = __DIR__."/src/Altax/Foundation/Container.php";
$containerSourceBackupPath = __DIR__."/Container.bak.php";
copy($containerSourcePath, $containerSourceBackupPath);
$contents = file_get_contents($containerSourcePath);
$hash = exec("git log --pretty=format:'%H' -n 1");
$contents = str_replace("%commit%", $hash, $contents);
file_put_contents($containerSourcePath, $contents);
// Chenge vendor for production environment.
system("rm -rf ".__DIR__."/vendor/");
system("composer install --no-dev --no-interaction");
require_once __DIR__ . '/vendor/autoload.php';
use Symfony\Component\Finder\Finder;
$pharFile = __DIR__."/altax.phar";
if (file_exists($pharFile)) {
unlink($pharFile);
}
echo "Starting compiling $pharFile\n";
$phar = new \Phar($pharFile, 0);
$phar->setSignatureAlgorithm(\Phar::SHA1);
$phar->startBuffering();
$finder = new Finder();
$files = iterator_to_array($finder->files()->exclude(array("tests", "Tests"))->in(array('vendor', 'src')));
foreach ($files as $file) {
echo "Processing: ".$file->getPathName()."\n";
$phar->addFromString($file->getPathName(), file_get_contents($file));
}
echo "Packaging ".count($files)." files.\n";
$content = file_get_contents(__DIR__."/bin/altax");
$content = preg_replace('{^#!/usr/bin/env php\s*}', '', $content);
$phar->addFromString('altax', $content);
$stub = <<<EOL
#!/usr/bin/env php
<?php
Phar::mapPhar('altax.phar');
require 'phar://altax.phar/altax';
__HALT_COMPILER();
EOL;
$phar->setStub($stub);
$phar->stopBuffering();
echo "Generated $pharFile \n";
unset($phar);
chmod($pharFile, 0755);
echo "File size is ".round(filesize($pharFile) / 1024 / 1024, 2)." MB.\n";
echo "Complete!\n";
// Revert to altax source.
copy($containerSourceBackupPath, $containerSourcePath);
unlink($containerSourceBackupPath);