#!/usr/bin/env php $name, 'version' => $version]; } $pluginRootDir = getPluginRootDir($argv[1] ?? null); checkRequiredFiles($pluginRootDir); $pluginInfo = getPluginInfo($pluginRootDir); $pluginName = $pluginInfo['name']; $pluginVersion = $pluginInfo['version']; // Custom: Add version to zip name $zipName = sprintf('%s-%s.zip', $pluginName, $pluginVersion); // Create the zip in the plugin root directory logic // If structure matches UBNT repo (src separate), put it one level up. // But commonly specific plugins are just the root. // The original script checks for README.md in parent and src dir to decide if it's in a mono-repo. // We will simplify and default to current dir, but keep the check just in case. if (file_exists(sprintf('%s/../README.md', $pluginRootDir)) && is_dir(sprintf('%s/../src', $pluginRootDir))) { $zipPath = sprintf('%s/../%s', $pluginRootDir, $zipName); } else { $zipPath = sprintf('%s/%s', $pluginRootDir, $zipName); } // Delete old ZIP archive. if (file_exists($zipPath)) { unlink($zipPath); } // Install composer dependencies. echo 'Installing composer dependencies...' . PHP_EOL; shell_exec('composer install --classmap-authoritative --no-dev --no-interaction --quiet'); // Create the ZIP archive. $zip = new ZipArchive(); if ($zip->open($zipPath, ZipArchive::CREATE) !== true) { echo 'Can\'t open zip file.' . PHP_EOL; exit(1); } $files = new CallbackFilterIterator( new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator($pluginRootDir, \RecursiveDirectoryIterator::SKIP_DOTS) ), function (SplFileInfo $fileInfo) { return $fileInfo->isFile(); } ); $ignoredFiles = [ 'ucrm.json', '.ucrm-plugin-running', '.ucrm-plugin-execution-requested', $zipName, '.DS_Store', // Added DS_Store ]; // Add wildcard support for ignored files if needed, but for now simple check $ignoredDirectories = [ '.git/', '.idea/', 'vendor/bin/', // Don't include binaries in the zip if not needed, or at least this script 'bin/', // Don't include this script itself if we don't want to distributed it (optional) ]; // We probably want to include vendor/bin/pack-plugin (original) if it was there, // but we definitely want to exclude .git. /** @var SplFileInfo $fileInfo */ foreach ($files as $fileInfo) { // Get relative path $filename = substr($fileInfo->getPathname(), strlen($pluginRootDir) + 1); // Fix slashes for zip $filename = str_replace('\\', '/', $filename); if (in_array(basename($filename), $ignoredFiles, true)) { // Simple check for filename continue; } // Check ignored files by full relative path if (in_array($filename, $ignoredFiles, true)) { continue; } foreach ($ignoredDirectories as $ignoredDirectory) { if (strpos($filename, $ignoredDirectory) === 0) { continue 2; } } // Exclude the script itself if it's inside the root if (realpath($fileInfo->getPathname()) === realpath(__FILE__)) { continue; } if (! $zip->addFile($fileInfo->getPathname(), $filename)) { echo sprintf('Unable to add file "%s".', $filename) . PHP_EOL; exit(1); } } $zip->close(); echo sprintf('Created plugin ZIP archive: "%s"', realpath($zipPath)) . PHP_EOL;