argument('key'); if (! preg_match('/^[a-z0-9][a-z0-9-]{0,40}$/', $key)) { $this->error('The key may only hold lowercase letters, numbers and dashes.'); return self::FAILURE; } $raw = [ 'label' => $this->option('label') ?: ucfirst($key), 'scheme' => $this->option('light') ? 'light' : 'dark', 'name' => $this->option('name'), 'logo' => $this->option('logo'), 'font' => $this->option('font'), 'font_display' => $this->option('font-display'), 'radius' => $this->option('radius'), 'colors' => array_filter([ 'brand' => $this->option('brand'), 'brand_alt' => $this->option('brand-alt'), 'ink' => $this->option('ink'), 'panel' => $this->option('panel'), 'text' => $this->option('text'), ]), ]; // What the manager would accept: tell what was thrown away instead of silently writing a different theme. $clean = $themes->sanitize($key, $raw); $rejected = []; foreach ($raw['colors'] as $name => $value) { ($clean['colors'][$name] ?? null) === $value || $rejected[] = $name.' ('.$value.')'; } foreach (['radius', 'font', 'font_display', 'logo'] as $option) { $raw[$option] !== null && ($clean[$option] ?? null) !== $raw[$option] && $rejected[] = $option.' ('.$raw[$option].')'; } if ($rejected !== []) { $this->error('Not accepted: '.implode(', ', $rejected).'. Colours are #rgb or #rrggbb; no quotes or semicolons in fonts.'); return self::FAILURE; } $folder = $this->option('path') ?: (config('manager.themes_path') ?: resource_path('manager-themes')); $file = rtrim($folder, '/')."/{$key}.json"; if (file_exists($file) && ! $this->option('force')) { $this->error("{$file} exists. Use --force to overwrite it."); return self::FAILURE; } is_dir($folder) || mkdir($folder, 0775, true); $out = array_filter(['label' => $clean['label'], 'scheme' => $clean['scheme'], 'name' => $clean['name'], 'logo' => $clean['logo'], 'font' => $clean['font'], 'font_display' => $clean['font_display'], 'radius' => $clean['radius'], 'colors' => $clean['colors']], fn ($value) => $value !== null); file_put_contents($file, json_encode($out, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)."\n"); $this->info("Wrote {$file}. Everyone sees it with MANAGER_THEME={$key}; each account can pick it in its profile."); return self::SUCCESS; } }