![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/syn.corals.io/Corals/core/Theme/Commands/ |
<?php namespace Corals\Theme\Commands; use Corals\Theme\ThemeManifest; class createPackage extends baseCommand { protected $signature = 'theme:package {themeName?}'; protected $description = 'Create a theme package'; public function handle() { $themeName = $this->argument('themeName'); if ($themeName == "") { $themes = array_map(function ($theme) { return $theme->name; }, \Theme::all()); $themeName = $this->choice('Select a theme to create a distributable package:', $themes); } $theme = \Theme::find($themeName); $viewsPath = themes_path($theme->viewsPath); $assetPath = public_path($theme->assetPath); // Packages storage path $packagesPath = $this->packages_path(); if (!$this->files->exists($packagesPath)) mkdir($packagesPath); // Sanitize target filename $packageFileName = $theme->name; $packageFileName = mb_ereg_replace("([^\w\s\d\-_~,;\[\]\(\).])", '', $packageFileName); $packageFileName = mb_ereg_replace("([\.]{2,})", '', $packageFileName); $packageFileName = $this->packages_path("{$packageFileName}.theme.tar.gz"); // Create Temp Folder $this->createTempFolder(); // Copy Views+Assets to Temp Folder system("cp -r $viewsPath {$this->tempPath}/views"); system("cp -r $assetPath {$this->tempPath}/asset"); // Add viewsPath into theme.json file $themeJson = new ThemeManifest(); $themeJson->loadFromFile("{$this->tempPath}/views/theme.json"); $themeJson->set('viewsPath', $theme->viewsPath); $themeJson->saveToFile("{$this->tempPath}/views/theme.json"); // Tar Temp Folder contents system("cd {$this->tempPath} && tar -cvzf $packageFileName ."); // Del Temp Folder $this->clearTempFolder(); $this->info("Package created at [$packageFileName]"); } }