-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.php
52 lines (41 loc) · 1.26 KB
/
build.php
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
<?php
$dir = explode('/', __DIR__);
$plugin_name = end($dir);
$file_phar = '/home/appgallery/pmmp/plugins/' . $plugin_name . '.phar';
if (file_exists($file_phar)) {
echo "Phar file already exists!";
echo PHP_EOL;
echo "overwriting...";
try{
Phar::unlinkArchive($file_phar);
} catch(PharException $e){
echo "couldn't overwriting phar file, reason: " . $e->getMessage();
return;
}
}
$files = [];
$dir = getcwd() . DIRECTORY_SEPARATOR;
$exclusions = [".idea", ".gitignore", "assets", "composer.json", "composer.lock", "build.php", ".git", "vendor", "composer.phar", "updateAndStart.sh"];
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir)) as $path => $file) {
$bool = true;
foreach ($exclusions as $exclusion) {
if (str_contains($path, $exclusion)) {
$bool = false;
}
}
if (!$bool) {
continue;
}
if ($file->isFile() === false) {
continue;
}
$files[str_replace($dir, "", $path)] = $path;
}
echo "Compressing..." . PHP_EOL;
$phar = new Phar($file_phar);
$phar->startBuffering();
$phar->setSignatureAlgorithm(Phar::SHA1);
$phar->buildFromIterator(new ArrayIterator($files));
$phar->compressFiles(Phar::GZ);
$phar->stopBuffering();
echo "end." . PHP_EOL;