forked from deployphp/deployer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build
executable file
·74 lines (59 loc) · 1.77 KB
/
build
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
#!/usr/bin/env php
<?php
/* __ ___ __
* | \ |__ |__)
* |__/ |___ |
*/
require __DIR__ . '/vendor/autoload.php';
$opt = getopt('v::');
$version = 'dev-master';
if (array_key_exists('v', $opt)) {
$version = $opt['v'];
if (!preg_match('/^\d+\.\d+\.\d+(-[\d\w\.]+)?$/i', $version)) {
die("Version number must follow semantic versioning.\n");
}
}
$pharName = "deployer.phar";
$pharFile = __DIR__ . '/' . $pharName;
if (file_exists($pharFile)) {
unlink($pharFile);
}
$phar = new \Phar($pharFile, 0, $pharName);
$phar->setSignatureAlgorithm(\Phar::SHA1);
$phar->startBuffering();
$finder = new Symfony\Component\Finder\Finder();
$finder->files()
->ignoreVCS(true)
->name('*.php')
->name('*.json')
->name('*.exe')
->exclude('phpunit')
->exclude('Tests')
->exclude('test')
->exclude('tests')
->exclude('phpspec')
->in(__DIR__);
foreach ($finder as $fileInfo) {
$file = str_replace(__DIR__, '', $fileInfo->getRealPath());
echo "Add file: " . $file . "\n";
$phar->addFile($fileInfo->getRealPath(), $file);
}
// Add bin/dep file
$depContent = file_get_contents(__DIR__ . '/bin/dep');
$depContent = str_replace("#!/usr/bin/env php\n", '', $depContent);
$depContent = str_replace("'master'", "'$version'", $depContent);
$depContent = str_replace('__FILE__', 'str_replace("phar://", "", Phar::running())', $depContent);
$phar->addFromString('bin/dep', $depContent);
$stub = <<<STUB
#!/usr/bin/env php
<?php
Phar::mapPhar('{$pharName}');
require 'phar://{$pharName}/bin/dep';
__HALT_COMPILER();
STUB;
$phar->setStub($stub);
// Bug #53467. Phar cannot compress large archives. https://bugs.php.net/bug.php?id=53467
// $phar->compressFiles(Phar::GZ);
$phar->stopBuffering();
unset($phar);
echo "$pharName was created successfully.\n";