46 lines
1.8 KiB
PHP
46 lines
1.8 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
use function App\Support\base_path;
|
|
|
|
require dirname(__DIR__) . '/bootstrap/autoload.php';
|
|
|
|
if (!class_exists(ZipArchive::class)) {
|
|
throw new RuntimeException('PHP zip is needed only to build the archive.');
|
|
}
|
|
if (!is_dir(base_path('dist'))) {
|
|
mkdir(base_path('dist'), 0755);
|
|
}
|
|
$files = [
|
|
'README.md', 'FEATURES.md', 'BRANDING.md', 'composer.json',
|
|
'config/app.php', 'config/local.example.php',
|
|
'storage/secrets/.gitkeep', 'storage/sessions/.gitkeep', 'storage/cache/.gitkeep',
|
|
];
|
|
// Only code, templates and public assets are collected recursively.
|
|
// config/ and storage/ use the explicit non-secret allowlist above.
|
|
foreach (['bootstrap', 'app', 'resources/views', 'public'] as $directory) {
|
|
$iterator = new RecursiveIteratorIterator(
|
|
new RecursiveDirectoryIterator(base_path($directory), FilesystemIterator::SKIP_DOTS),
|
|
);
|
|
foreach ($iterator as $entry) {
|
|
if ($entry->isLink() || !in_array($entry->getExtension(), ['php', 'js', 'css', 'ttf', 'svg', 'png', 'ico', 'webmanifest', 'html'], true)) {
|
|
throw new RuntimeException('Unexpected deployment file: ' . $entry->getFilename());
|
|
}
|
|
$files[] = substr($entry->getPathname(), strlen(base_path()) + 1);
|
|
}
|
|
}
|
|
sort($files, SORT_STRING);
|
|
$zip = new ZipArchive();
|
|
if ($zip->open(base_path('dist/madar-cpanel.zip'), ZipArchive::CREATE | ZipArchive::OVERWRITE) !== true) {
|
|
throw new RuntimeException('Could not create archive.');
|
|
}
|
|
foreach ($files as $file) {
|
|
if (!$zip->addFile(base_path($file), $file)) {
|
|
throw new RuntimeException('Could not package: ' . $file);
|
|
}
|
|
}
|
|
if (!$zip->close()) {
|
|
throw new RuntimeException('Could not finalize archive.');
|
|
}
|
|
echo "Created dist/madar-cpanel.zip — set the document root to public/. No credentials included.\n";
|