This repository has been archived by the owner on Sep 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build
executable file
·65 lines (49 loc) · 1.69 KB
/
build
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
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env php
<?php
require __DIR__ . '/vendor/autoload.php';
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
$finder = new Finder();
$finder->directories()
->ignoreVCS(true)
->notPath('vendor')
->notPath('zip')
->depth('<= 1')
->in(__DIR__);
/** @var $dir SplFileInfo */
foreach ($finder as $dir) {
echo 'Creating package "' . ($name = $dir->getBasename()) . "\"\n";
createZip($name, $dir);
}
function createZip($name, SplFileInfo $dir, $showAdded = false)
{
static $common = null;
if ($common === null) {
$common = file_get_contents(__DIR__ . '/common.php');
$common = str_replace("<?php\n", '', $common);
}
if (!is_writable($zipDir = __DIR__ . '/zip/')) mkdir($zipDir);
$zipFile = $zipDir . $name . '.zip';
if (file_exists($zipFile)) {
unlink($zipFile);
}
$zip = new ZipArchive();
if ($zip->open($zipFile, ZipArchive::CREATE) !== true) {
die("Can not open zip archive\n");
}
$finder = new Finder();
$finder->files()->in($dir->getPathname());
/** @var $file SplFileInfo */
foreach ($finder as $file) {
if ($file->getExtension() === 'php') {
$content = file_get_contents($file->getRealPath());
$content = str_replace('#COMMON', $common, $content);
$zip->addFromString($file->getRelativePathname(), $content);
if ($showAdded) echo "Add PHP file: " . $file->getRelativePathname() . "\n";
} else {
$zip->addFile($file->getRealPath(), $file->getRelativePathname());
if ($showAdded) echo "Add file: " . $file->getRelativePathname() . "\n";
}
}
$zip->close();
}