deployer/bin/build

73 lines
2.0 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env php
<?php
2017-03-20 00:08:34 +07:00
/* (c) Anton Medvedev <anton@medv.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
2016-11-15 15:02:14 +07:00
*/
2020-10-10 17:10:24 +02:00
define('__ROOT__', realpath(__DIR__ . '/..'));
chdir(__ROOT__);
2020-10-10 17:10:24 +02:00
$opt = getopt('', ['nozip']);
2015-02-05 17:25:17 +03:00
2020-10-10 17:10:24 +02:00
`composer install --no-dev`;
2017-03-20 00:08:34 +07:00
2014-08-13 13:47:18 +04:00
$pharName = "deployer.phar";
2020-10-10 17:10:24 +02:00
$pharFile = __ROOT__ . '/' . $pharName;
if (file_exists($pharFile)) {
unlink($pharFile);
}
2021-10-13 20:05:19 +02:00
$ignore = [
'.anton',
'.git',
'Tests',
'tests',
'deploy.php',
];
$phar = new \Phar($pharFile, 0, $pharName);
$phar->setSignatureAlgorithm(\Phar::SHA1);
$phar->startBuffering();
2020-10-10 17:10:24 +02:00
$iterator = new RecursiveDirectoryIterator(__ROOT__, FilesystemIterator::SKIP_DOTS);
2021-10-13 20:05:19 +02:00
$iterator = new RecursiveCallbackFilterIterator($iterator, function (SplFileInfo $fileInfo) use ($ignore) {
return !in_array($fileInfo->getBasename(), $ignore, true);
2018-04-20 19:23:19 +07:00
});
$iterator = new RecursiveIteratorIterator($iterator);
$iterator = new CallbackFilterIterator($iterator, function (SplFileInfo $fileInfo) {
return in_array($fileInfo->getExtension(), ['php', 'exe'], true);
2018-04-20 19:23:19 +07:00
});
foreach ($iterator as $fileInfo) {
2020-10-10 17:10:24 +02:00
$file = str_replace(__ROOT__, '', $fileInfo->getRealPath());
echo "Add file: " . $file . "\n";
$phar->addFile($fileInfo->getRealPath(), $file);
if (!array_key_exists('nozip', $opt)) {
$phar[$file]->compress(Phar::GZ);
2021-10-13 20:05:19 +02:00
if (!$phar[$file]->isCompressed()) {
echo "Could not compress File: {$file}\n";
}
}
}
// Add bin/dep file
2020-10-10 17:10:24 +02:00
$depContent = file_get_contents(__ROOT__ . '/bin/dep');
$depContent = str_replace("#!/usr/bin/env php\n", '', $depContent);
2015-05-26 18:33:07 +07:00
$depContent = str_replace('__FILE__', 'str_replace("phar://", "", Phar::running())', $depContent);
$phar->addFromString('bin/dep', $depContent);
2020-10-10 17:10:24 +02:00
$phar->setStub(<<<STUB
#!/usr/bin/env php
<?php
2014-07-08 17:16:31 +04:00
Phar::mapPhar('{$pharName}');
require 'phar://{$pharName}/bin/dep';
__HALT_COMPILER();
2021-10-13 20:05:19 +02:00
STUB
);
$phar->stopBuffering();
unset($phar);
2015-05-19 12:28:14 +02:00
echo "$pharName was created successfully.\n";