-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.php
More file actions
119 lines (91 loc) · 3.52 KB
/
build.php
File metadata and controls
119 lines (91 loc) · 3.52 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
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
<?php
// php -d phar.readonly=0 build.php
$pharFile = "YOUR_PLUGIN_NAME.phar";
$finalPharFile = __DIR__ . "/" . $pharFile;
$startTime = microtime(true);
if (file_exists($finalPharFile)) {
@unlink($finalPharFile);
clearstatcache();
}
try {
$phar = new Phar($finalPharFile);
$phar->setStub('<?php __HALT_COMPILER();');
$phar->startBuffering();
$pluginYmlPath = __DIR__ . '/plugin.yml';
if (file_exists($pluginYmlPath)) {
$phar->addFromString('plugin.yml', file_get_contents($pluginYmlPath));
echo "Added plugin.yml\n";
} else {
echo "Warning: plugin.yml not found!\n";
}
$composerJsonPath = __DIR__ . '/composer.json';
if (file_exists($composerJsonPath)) {
$phar->addFromString('composer.json', file_get_contents($composerJsonPath));
echo "Added composer.json\n";
} else {
echo "Warning: composer.json not found!\n";
}
$composerLockPath = __DIR__ . '/composer.lock';
if (file_exists($composerLockPath)) {
$phar->addFromString('composer.lock', file_get_contents($composerLockPath));
echo "Added composer.lock\n";
}
$srcDir = __DIR__ . '/src';
if (is_dir($srcDir)) {
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($srcDir, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::LEAVES_ONLY
);
$fileCount = 0;
foreach ($iterator as $file) {
if ($file->isFile() && $file->getExtension() === 'php') {
$realPath = $file->getRealPath();
$relativePath = 'src/' . substr($realPath, strlen($srcDir) + 1);
$relativePath = str_replace('\\', '/', $relativePath);
$phar->addFromString($relativePath, file_get_contents($realPath));
echo "Added: $relativePath\n";
$fileCount++;
}
}
echo "Added $fileCount PHP files from src/\n";
}
$resourcesDir = __DIR__ . '/resources';
if (is_dir($resourcesDir)) {
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($resourcesDir, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::SELF_FIRST
);
$resourceCount = 0;
foreach ($iterator as $file) {
if ($file->isFile()) {
$realPath = $file->getRealPath();
$relativePath = 'resources/' . substr($realPath, strlen($resourcesDir) + 1);
$relativePath = str_replace('\\', '/', $relativePath);
$phar->addFromString($relativePath, file_get_contents($realPath));
echo "Added resource: $relativePath\n";
$resourceCount++;
}
}
echo "Added $resourceCount resource files from resources/\n";
} else {
echo "No resources/ folder found. Skipping.\n";
}
$phar->stopBuffering();
echo "\nBuilt " . $pharFile . " successfully!\n\nTotal time: " . (microtime(true) - $startTime) . " seconds\n\n";
$verify = new Phar($finalPharFile);
$totalCount = 0;
echo "Files in PHAR:\n";
foreach (new RecursiveIteratorIterator($verify) as $file) {
if ($totalCount++ < 15) {
echo " " . $file->getFileName() . "\n";
}
}
if ($totalCount > 15) {
echo " ... and " . ($totalCount - 15) . " more files\n";
}
echo "\nTotal files in PHAR: $totalCount\n";
} catch (Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
exit(1);
}
?>