-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.php
More file actions
50 lines (37 loc) · 1.42 KB
/
build.php
File metadata and controls
50 lines (37 loc) · 1.42 KB
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
<?php
$pharPath = __DIR__ . '/bin/deploy.phar';
$binPath = __DIR__ . '/bin/deploy';
@unlink($pharPath);
@unlink($binPath);
$phar = new Phar($pharPath);
$phar->startBuffering();
function addDirectoryToPhar(Phar $phar, string $sourceDir, string $relativeBase)
{
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($sourceDir, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($iterator as $file) {
if ($file->isFile()) {
$localPath = $relativeBase . '/' . substr($file->getRealPath(), strlen(realpath($sourceDir)) + 1);
$phar->addFile($file->getRealPath(), $localPath);
}
}
}
addDirectoryToPhar($phar, __DIR__ . '/src', 'src');
addDirectoryToPhar($phar, __DIR__ . '/vendor', 'vendor');
$phar->addFile(__DIR__ . '/composer.json', 'composer.json');
$phar->addFile(__DIR__ . '/composer.lock', 'composer.lock');
$phar->addFile(__DIR__ . '/version.txt', 'version.txt');
$stub = "#!/usr/bin/env php\n" . $phar->createDefaultStub('src/Standalone.php');
$phar->setStub($stub);
$phar->setSignatureAlgorithm(Phar::SHA256);
$phar->stopBuffering();
$phar->compressFiles(Phar::GZ);
rename($pharPath, $binPath);
@chmod($binPath, 0755);
$hash = hash_file('sha256', $binPath);
file_put_contents(__DIR__ . '/build_hash.txt', $hash);
echo "PHAR created successfully.\n";
echo "Location: $binPath\n";
echo "Hash SHA-256: $hash";