This repository has been archived by the owner on Feb 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.php
123 lines (93 loc) · 4.06 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
if (!is_dir("build/")) {
mkdir("build/", 0755, true);
}
$pharName = "e621BRS";
$srcRoot = realpath("src");
$buildRoot = realpath("build");
$buildFile = 'build/e621_Batch_Reverse_Search.zip';
$ignoredFiles = ['.', '..', '.gitkeep', 'images', 'logs', 'config.cfg', 'debug_error.txt', 'build.zip', 'e621_Batch_Reverse_Search.zip', '.updatecheck'];
if (ini_get("phar.readonly") == 0) {
echo "Building...\n";
if (file_exists($buildRoot . '/' . $pharName . '.phar')) {
unlink($buildRoot . '/' . $pharName . '.phar');
}
$phar = new Phar($buildRoot . "/" . $pharName . ".phar", FilesystemIterator::CURRENT_AS_FILEINFO, $pharName . ".phar");
echo " Building phar...\n";
$phar->buildFromDirectory($srcRoot, '/.php$/');
$phar->setStub($phar->createDefaultStub("run.php"));
echo " Copying additional files...\n";
if (file_exists($srcRoot . "/config.cfg.example")) {
copy($srcRoot . "/config.cfg.example", $buildRoot . "/config.cfg.example");
}
if (file_exists($srcRoot . "/run.bat")) {
copy($srcRoot . "/run.bat", $buildRoot . "/run.bat");
}
if (file_exists($srcRoot . "/run.sh")) {
copy($srcRoot . "/run.sh", $buildRoot . "/run.sh");
}
if (file_exists(__DIR__ . '/vendor/erusev/parsedown/Parsedown.php')) {
echo " Converting markdown files into HTML...\n";
require __DIR__ . '/vendor/erusev/parsedown/Parsedown.php';
$Parsedown = new Parsedown();
$license = $Parsedown->text(file_get_contents(__DIR__ . '/LICENSE'));
$readme = $Parsedown->text(file_get_contents(__DIR__ . '/README.md'));
$contributing = $Parsedown->text(file_get_contents(__DIR__ . '/CONTRIBUTING.md'));
$readme = str_replace("https://github.com/jacklul/e621-Batch-Reverse-Search/blob/master/CONTRIBUTING.md", "CONTRIBUTING.html", $readme);
$readme = str_replace("https://github.com/jacklul/e621-Batch-Reverse-Search/blob/master/LICENSE", "LICENSE.html", $readme);
$contributing = str_replace("https://github.com/jacklul/e621-Batch-Reverse-Search/blob/master/README.md", "README.html", $contributing);
file_put_contents($buildRoot . "/README.html", $readme);
file_put_contents($buildRoot . "/LICENSE.html", $license);
file_put_contents($buildRoot . "/CONTRIBUTING.html", $contributing);
} else {
echo("! Can't parse markdown files into HTML, dependencies not installed - do 'composer install'!\n");
}
echo "Done!\n\n";
} else {
echo "! Can't build - 'phar.readonly' is 'On', check php.ini!\n\n";
}
if (class_exists('ZipArchive')) {
if (is_dir($buildRoot)) {
echo "Packing...\n";
if (file_exists($buildFile)) {
unlink($buildFile);
}
$dirName = basename($buildRoot);
$zip = new ZipArchive();
$zip->open($buildFile, ZipArchive::CREATE);
if (substr($dirName, -1) != '/') {
$dirName .= '/';
}
$dirStack = array($dirName);
$cutFrom = strrpos($dirName, '/') + 1;
while (!empty($dirStack)) {
$currentDir = array_pop($dirStack);
$filesToAdd = array();
$dir = dir($currentDir);
while (false !== ($node = $dir->read())) {
if (in_array($node, $ignoredFiles)) {
continue;
}
if (is_dir($currentDir . $node)) {
array_push($dirStack, $currentDir . $node . '/');
}
if (is_file($currentDir . $node)) {
$filesToAdd[] = $node;
}
}
$localDir = substr($currentDir, $cutFrom);
$zip->addEmptyDir($localDir);
foreach ($filesToAdd as $file) {
echo " '$currentDir$file'...\n";
$zip->addFile($currentDir . $file, $localDir . $file);
}
}
$zip->close();
echo "Done!\n\n";
} else {
echo "! Build directory does not exist!\n\n";
}
} else {
echo "! Can't pack build, 'php-zip' package not found!\n\n";
}
echo "Finished!\n\n";