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