2014-07-07 08:38:35 +04:00
|
|
|
#!/usr/bin/env php
|
|
|
|
<?php
|
|
|
|
require __DIR__ . '/vendor/autoload.php';
|
|
|
|
|
2014-07-07 16:35:41 +04:00
|
|
|
$version = '1.0.1';
|
2014-07-07 08:38:35 +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);
|
|
|
|
}
|
|
|
|
|
2014-07-07 11:08:04 +04:00
|
|
|
// Add bin/dep file
|
|
|
|
$depContent = file_get_contents(__DIR__ . '/bin/dep');
|
|
|
|
$depContent = str_replace("#!/usr/bin/env php\n", '', $depContent);
|
2014-07-07 16:47:28 +04:00
|
|
|
$depContent = str_replace('__VERSION__', $version, $depContent);
|
2014-07-07 11:08:04 +04:00
|
|
|
$phar->addFromString('bin/dep', $depContent);
|
|
|
|
|
2014-07-07 08:38:35 +04:00
|
|
|
$stub = <<<'STUB'
|
|
|
|
#!/usr/bin/env php
|
|
|
|
<?php
|
|
|
|
Phar::mapPhar('deployer.phar');
|
|
|
|
require 'phar://deployer.phar/bin/dep';
|
|
|
|
__HALT_COMPILER();
|
|
|
|
STUB;
|
|
|
|
|
|
|
|
$phar->setStub($stub);
|
|
|
|
$phar->stopBuffering();
|
2014-07-07 09:23:33 +04:00
|
|
|
unset($phar);
|
2014-07-07 08:38:35 +04:00
|
|
|
|
2014-07-07 09:23:33 +04:00
|
|
|
echo "deployer.phar created successful.\n";
|
|
|
|
|
|
|
|
// Generate sha1 sum and put it to manifest.json
|
|
|
|
$newPharManifest = [
|
|
|
|
'name' => $pharName,
|
|
|
|
'sha1' => sha1_file($pharFile),
|
|
|
|
'url' => 'http://deployer.in/deployer.phar',
|
|
|
|
'version' => $version,
|
|
|
|
];
|
|
|
|
|
|
|
|
$manifest = json_decode(file_get_contents(__DIR__ . '/manifest.json'), true);
|
|
|
|
|
|
|
|
$alreadyExistVersion = null;
|
|
|
|
foreach ($manifest as $i => $old) {
|
|
|
|
if ($old['version'] === $version) {
|
|
|
|
$alreadyExistVersion = $i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (null === $alreadyExistVersion) {
|
|
|
|
$manifest[] = $newPharManifest;
|
|
|
|
} else {
|
|
|
|
$manifest[$alreadyExistVersion] = $newPharManifest;
|
|
|
|
}
|
|
|
|
|
|
|
|
file_put_contents(__DIR__ . '/manifest.json', json_encode($manifest, JSON_PRETTY_PRINT));
|