mirror of
https://github.com/pelican-dev/panel.git
synced 2025-11-08 10:39:27 +01:00
change format of plugin.json
This commit is contained in:
parent
2d26d2e15b
commit
4df52c21fa
@ -49,11 +49,11 @@ class CreatePluginCommand extends Command
|
||||
|
||||
$description = $this->option('description') ?? $this->ask('Description');
|
||||
$url = $this->option('url') ?? $this->ask('URL', 'https://github.com/' . $author . '/' . $id);
|
||||
$panels = $this->option('panels') ?? implode(',', $this->choice('Panels', [
|
||||
$panels = $this->option('panels') ?? $this->choice('Panels', [
|
||||
'admin' => 'Admin Area',
|
||||
'server' => 'Client Area',
|
||||
'app' => 'Server List',
|
||||
], 'admin,server', multiple: true));
|
||||
], 'admin,server', multiple: true);
|
||||
$category = $this->option('category') ?? $this->choice('Category', [
|
||||
'plugin' => 'Plugin',
|
||||
'theme' => 'Theme',
|
||||
@ -65,6 +65,11 @@ class CreatePluginCommand extends Command
|
||||
|
||||
// Write plugin.json
|
||||
$this->filesystem->put(plugin_path($id, 'plugin.json'), json_encode([
|
||||
'meta' => [
|
||||
'status' => PluginStatus::Enabled,
|
||||
'status_message' => null,
|
||||
'load_order' => 0,
|
||||
],
|
||||
'id' => $id,
|
||||
'name' => $name,
|
||||
'author' => $author,
|
||||
@ -73,12 +78,9 @@ class CreatePluginCommand extends Command
|
||||
'url' => $url,
|
||||
'namespace' => $namespace,
|
||||
'class' => $class,
|
||||
'status' => PluginStatus::Enabled,
|
||||
'status_message' => null,
|
||||
'panels' => $panels,
|
||||
'panels' => !is_array($panels) ? explode(',', $panels) : $panels,
|
||||
'panel_version' => config('app.version') === 'canary' ? null : config('app.version'),
|
||||
'category' => $category,
|
||||
'load_order' => 0,
|
||||
'update_url' => null,
|
||||
], JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||
|
||||
|
||||
@ -18,13 +18,13 @@ use Sushi\Sushi;
|
||||
* @property string|null $url
|
||||
* @property string $namespace
|
||||
* @property string $class
|
||||
* @property PluginStatus $status
|
||||
* @property string|null $status_message
|
||||
* @property string|null $panels
|
||||
* @property string|null $panel_version
|
||||
* @property string $category
|
||||
* @property int $load_order
|
||||
* @property string|null $update_url
|
||||
* @property PluginStatus $status
|
||||
* @property string|null $status_message
|
||||
* @property int $load_order
|
||||
*/
|
||||
class Plugin extends Model implements HasPluginSettings
|
||||
{
|
||||
@ -50,13 +50,13 @@ class Plugin extends Model implements HasPluginSettings
|
||||
'url' => 'string',
|
||||
'namespace' => 'string',
|
||||
'class' => 'string',
|
||||
'status' => 'string',
|
||||
'status_message' => 'string',
|
||||
'panels' => 'string',
|
||||
'panel_version' => 'string',
|
||||
'category' => 'string',
|
||||
'load_order' => 'integer',
|
||||
'update_url' => 'string',
|
||||
'status' => 'string',
|
||||
'status_message' => 'string',
|
||||
'load_order' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
@ -70,13 +70,13 @@ class Plugin extends Model implements HasPluginSettings
|
||||
* url: string,
|
||||
* namespace: string,
|
||||
* class: string,
|
||||
* status: string,
|
||||
* status_message: string,
|
||||
* panels: string,
|
||||
* panel_version: string,
|
||||
* category: string,
|
||||
* load_order: int
|
||||
* update_url: string,
|
||||
* status: string,
|
||||
* status_message: string,
|
||||
* load_order: int
|
||||
* }>
|
||||
*/
|
||||
public function getRows(): array
|
||||
@ -92,7 +92,16 @@ class Plugin extends Model implements HasPluginSettings
|
||||
continue;
|
||||
}
|
||||
|
||||
$plugins[] = File::json($path, JSON_THROW_ON_ERROR);
|
||||
$data = File::json($path, JSON_THROW_ON_ERROR);
|
||||
|
||||
$data = array_merge($data, $data['meta']);
|
||||
unset($data['meta']);
|
||||
|
||||
if (is_array($data['panels'])) {
|
||||
$data['panels'] = implode(',', $data['panels']);
|
||||
}
|
||||
|
||||
$plugins[] = $data;
|
||||
}
|
||||
|
||||
return $plugins;
|
||||
|
||||
@ -161,28 +161,22 @@ class PluginService
|
||||
$this->setStatus($plugin, PluginStatus::Disabled);
|
||||
}
|
||||
|
||||
public function getStatus(string|Plugin $plugin): PluginStatus
|
||||
{
|
||||
$plugin = $plugin instanceof Plugin ? $plugin->id : $plugin;
|
||||
$data = File::json(plugin_path($plugin, 'plugin.json'), JSON_THROW_ON_ERROR);
|
||||
|
||||
return $data['status'] ?? PluginStatus::Errored;
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $data */
|
||||
private function setData(string|Plugin $plugin, array $data): void
|
||||
private function setMetaData(string|Plugin $plugin, array $data): void
|
||||
{
|
||||
$plugin = $plugin instanceof Plugin ? $plugin->id : $plugin;
|
||||
$path = plugin_path($plugin, 'plugin.json');
|
||||
|
||||
$data = array_merge(File::json($path, JSON_THROW_ON_ERROR), $data);
|
||||
$pluginData = File::json($path, JSON_THROW_ON_ERROR);
|
||||
$metaData = array_merge($pluginData['meta'], $data);
|
||||
$pluginData['meta'] = $metaData;
|
||||
|
||||
File::put($path, json_encode($data, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||
File::put($path, json_encode($pluginData, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||
}
|
||||
|
||||
private function setStatus(string|Plugin $plugin, PluginStatus $status, ?string $message = null): void
|
||||
{
|
||||
$this->setData($plugin, [
|
||||
$this->setMetaData($plugin, [
|
||||
'status' => $status,
|
||||
'status_message' => $message,
|
||||
]);
|
||||
@ -192,7 +186,7 @@ class PluginService
|
||||
public function updateLoadOrder(array $order): void
|
||||
{
|
||||
foreach ($order as $i => $plugin) {
|
||||
$this->setData($plugin, [
|
||||
$this->setMetaData($plugin, [
|
||||
'load_order' => $i,
|
||||
]);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user