From 1602bdd72eddbb84817b9148f8ef57675cf700c1 Mon Sep 17 00:00:00 2001 From: Mark Gregory Date: Wed, 16 Sep 2026 17:10:47 +0100 Subject: [PATCH] new source export command --- app/Console/Commands/ExportSource.php | 100 ++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 app/Console/Commands/ExportSource.php diff --git a/app/Console/Commands/ExportSource.php b/app/Console/Commands/ExportSource.php new file mode 100644 index 00000000..fbc11c91 --- /dev/null +++ b/app/Console/Commands/ExportSource.php @@ -0,0 +1,100 @@ +format('Ymd-His'); + $downloads = rtrim((string) getenv('HOME'), '/').'/Downloads'; + $archive = "{$downloads}/{$project}-source-{$timestamp}.zip"; + + $this->info("Exporting {$project}..."); + + /* + * Fast export of all Git-tracked source. + */ + $result = Process::path(base_path()) + ->timeout(60) + ->run([ + 'git', + 'archive', + '--format=zip', + "--output={$archive}", + 'HEAD', + ]); + + if ($result->failed()) { + $this->error($result->errorOutput()); + + return self::FAILURE; + } + + $zip = new ZipArchive(); + + if ($zip->open($archive) !== true) { + $this->error('Could not open ZIP.'); + + return self::FAILURE; + } + + /* + * Remove ONLY: + * + * node_modules + * vendor + * Provision + * .scannerwork + * contents of storage/framework + * contents of storage/logs + */ + $removeDirectories = [ + 'node_modules/', + 'vendor/', + 'Provision/', + 'provision/', + '.scannerwork/', + 'storage/framework/', + 'storage/logs/', + ]; + + for ($i = $zip->numFiles - 1; $i >= 0; $i--) { + $name = $zip->getNameIndex($i); + + foreach ($removeDirectories as $directory) { + if (str_starts_with($name, $directory)) { + $zip->deleteIndex($i); + break; + } + } + } + + /* + * Restore the storage directory structure EMPTY. + */ + $zip->addEmptyDir('storage/framework'); + $zip->addEmptyDir('storage/framework/cache'); + $zip->addEmptyDir('storage/framework/cache/data'); + $zip->addEmptyDir('storage/framework/sessions'); + $zip->addEmptyDir('storage/framework/testing'); + $zip->addEmptyDir('storage/framework/views'); + $zip->addEmptyDir('storage/logs'); + + $zip->close(); + + $this->info('Done.'); + $this->line($archive); + + return self::SUCCESS; + } +}