deployer/build

66 lines
1.5 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env php
<?php
2015-01-28 16:24:56 +03:00
require __DIR__ . '/vendor/autoload.php';
2015-02-05 17:25:17 +03:00
$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");
}
}
2014-08-13 13:47:18 +04:00
$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')
->exclude('phpunit')
->exclude('Tests')
->exclude('test')
->exclude('tests')
->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
2015-01-28 16:24:56 +03:00
$depContent = file_get_contents(__DIR__ . '/bin/dep');
$depContent = str_replace("#!/usr/bin/env php\n", '', $depContent);
2015-02-05 17:25:17 +03:00
$depContent = str_replace("'master'", "'$version'", $depContent);
$phar->addFromString('bin/dep', $depContent);
2014-07-08 17:23:25 +04:00
$stub = <<<STUB
#!/usr/bin/env php
<?php
2014-07-08 17:16:31 +04:00
Phar::mapPhar('{$pharName}');
require 'phar://{$pharName}/bin/dep';
__HALT_COMPILER();
2014-07-08 17:23:25 +04:00
STUB;
$phar->setStub($stub);
2015-02-24 15:38:55 +03:00
$phar->compressFiles(Phar::GZ);
$phar->stopBuffering();
unset($phar);
2014-07-08 17:00:17 +04:00
echo "$pharName created successful.\n";