Skip to content

Commit

Permalink
Add plugins JSON schema and VSCode configuration to use it (#284)
Browse files Browse the repository at this point in the history
* Add plugins JSON schema and VSCode configuration to use it

* Add VSCode YAML extension to workspace recommendations

* Fix formatting issues

* Update VSCode settings to use Prettier for JSON and YAML formatting
  • Loading branch information
puc9 authored Jun 1, 2024
1 parent bdf1f04 commit a0d3bac
Show file tree
Hide file tree
Showing 3 changed files with 358 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["redhat.vscode-yaml", "esbenp.prettier-vscode"]
}
22 changes: 22 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"yaml.validate": true,
"yaml.disableAdditionalProperties": true,
"yaml.completion": true,
"yaml.extension.recommendations": true,
"yaml.hover": true,
"yaml.format.singleQuote": false,
"yaml.format.printWidth": 120,
"yaml.format.proseWrap": "always",
"yaml.schemas": {
"schema/plugin.schema.json": ["/plugins/**", "/themes/**"]
},
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[yaml]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
333 changes: 333 additions & 0 deletions schema/plugin.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,333 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "plugin",
"title": "Stash Plugin",
"description": "A stash plugin config",
"type": "object",
"additionalProperties": false,
"required": ["name"],
"properties": {
"name": {
"title": "Plugin name",
"description": "The name of the plugin.",
"type": "string"
},
"description": {
"title": "Plugin description",
"description": "Short description of the plugin.",
"type": ["string", "null"]
},
"version": {
"title": "Plugin version",
"description": "Format: x.y.z where x y and z are integers.",
"type": ["string", "integer", "number"],
"pattern": "^\\d+(\\.\\d+)?(\\.\\d+)?$"
},
"url": {
"title": "Url",
"description": "Optional url",
"type": ["string", "null"]
},
"ui": {
"title": "Plugin UI",
"description": "Optional files needed to render plugin specific UI",
"$ref": "#/definitions/UIConfig"
},
"exec": {
"title": "Command to run the plugin",
"description": "For external plugin tasks, the exec field is a list with the first element being the binary that will be executed, and the subsequent elements are the arguments passed. The execution process will search the path for the binary, then will attempt to find the program in the same directory as the plugin configuration file. The exe extension is not necessary on Windows systems.\n\nFor embedded plugins, the exec field is a list with the first element being the path to the Javascript file that will be executed. It is expected that the path to the Javascript file is relative to the directory of the plugin configuration file.",
"type": "array",
"items": {
"type": "string"
}
},
"interface": {
"title": "Plugin interface",
"description": "For external plugin tasks, the interface field must be set to one of the following values: rpc, raw\n\nFor embedded plugins, the interface field must be set to one of the following values: js\n\nThe interface field defaults to raw if not provided.",
"type": "string",
"enum": ["js", "raw", "rpc"],
"default": "raw"
},
"hooks": {
"title": "Hooks configuration",
"description": "Array of individual hook configurations.",
"type": "array",
"items": {
"$ref": "#/definitions/HookConfig"
}
},
"tasks": {
"title": "Tasks configuration",
"description": "Array of individual tasks configurations.",
"type": "array",
"items": {
"$ref": "#/definitions/TaskConfig"
}
},
"settings": {
"title": "Plugin settings",
"description": "The settings defined for this plugin.",
"$ref": "#/definitions/SettingConfig"
}
},
//
//
"definitions": {
"UIConfig": {
"type": "object",
"additionalProperties": false,
"anyOf": [
{
"required": ["css"]
},
{
"required": ["javascript"]
}
],
"properties": {
// # optional list of css files to include in the UI
// css:
// - <path to css file>
"css": {
"title": "CSS files",
"description": "Optional list of CSS files to include in the UI",
"items": {
"description": "Path to CSS file"
},
"$ref": "#/definitions/StringList"
},
// # optional list of js files to include in the UI
// javascript:
// - <path to javascript file>
"javascript": {
"title": "Javascript files",
"description": "Optional list of Javascript files to include in the UI",
"items": {
"description": "Path to Javascript file"
},
"$ref": "#/definitions/StringList"
},
// # optional list of plugin IDs to load prior to this plugin
// requires:
// - <plugin ID>
"requires": {
"title": "Required plugins",
"description": "Optional list of plugin IDs to load prior to this plugin.",
"items": {
"description": "Required plugin ID"
},
"$ref": "#/definitions/StringList"
},
// # optional list of assets
// assets:
// urlPrefix: fsLocation
// ...
"assets": {
"title": "Assets",
"description": "Optional map of assets.",
"type": "object",
"patternProperties": {
"": {
"type": "string",
"title": "Asset location",
"description": "Asset location on the file system as pair of values urlPrefix: fsLocation."
}
}
},
// # content-security policy overrides
// csp:
// script-src:
// - http://alloweddomain.com
// style-src:
// - http://alloweddomain.com
// connect-src:
// - http://alloweddomain.com
"csp": {
"title": "Content-security policy overrides",
"description": "Optional map of policy directives",
"type": "object",
"additionalProperties": true,
"properties": {
"script-src": {
"$ref": "#/definitions/CspDirective"
},
"style-src": {
"$ref": "#/definitions/CspDirective"
},
"connect-src": {
"$ref": "#/definitions/CspDirective"
}
},
"patternProperties": {
"": {
"$ref": "#/definitions/CspDirective"
}
}
},
// # map of setting names to be displayed in the plugins page in the UI
// settings:
// # internal name
// foo:
// # name to display in the UI
// displayName: Foo
// # type of the attribute to show in the UI
// # can be BOOLEAN, NUMBER, or STRING
// type: BOOLEAN
"settings": {
"title": "UI plugin settings",
"description": "Map of setting names to be displayed in the plugins page in the UI.",
"$ref": "#/definitions/SettingConfig"
}
}
},
"HookConfig": {
"type": "object",
"required": ["name", "triggeredBy"],
"properties": {
"name": {
"type": "string",
"description": "Hook name"
},
"description": {
"type": ["string", "null"],
"description": "Optional description for this hook"
},
"triggeredBy": {
"type": "array",
"items": {
"$ref": "#/definitions/TriggerType"
}
},
"defaultArgs": {
"description": "Default arguments",
"type": "object",
"items": {
"type": "string"
}
}
}
},
"TriggerType": {
"type": "string",
"pattern": "^(Scene|SceneMarker|Image|Gallery|GalleryChapter|Movie|Performer|Studio|Tag)\\.(Create|Update|Destroy|Merge)\\.Post$",
"enum": [
"Scene.Create.Post",
"Scene.Update.Post",
"Scene.Destroy.Post",
"Scene.Merge.Post",
//
"SceneMarker.Create.Post",
"SceneMarker.Update.Post",
"SceneMarker.Destroy.Post",
"SceneMarker.Merge.Post",
//
"Image.Create.Post",
"Image.Update.Post",
"Image.Destroy.Post",
"Image.Merge.Post",
//
"Gallery.Create.Post",
"Gallery.Update.Post",
"Gallery.Destroy.Post",
"Gallery.Merge.Post",
//
"GalleryChapter.Create.Post",
"GalleryChapter.Update.Post",
"GalleryChapter.Destroy.Post",
//
"Movie.Create.Post",
"Movie.Update.Post",
"Movie.Destroy.Post",
"Movie.Merge.Post",
//
"Performer.Create.Post",
"Performer.Update.Post",
"Performer.Destroy.Post",
"Performer.Merge.Post",
//
"Studio.Create.Post",
"Studio.Update.Post",
"Studio.Destroy.Post",
"Studio.Merge.Post",
//
"Tag.Create.Post",
"Tag.Update.Post",
"Tag.Destroy.Post",
"Tag.Merge.Post"
]
},
"TaskConfig": {
"type": "object",
"required": ["name"],
"properties": {
"name": {
"type": "string",
"description": "Task name"
},
"description": {
"type": "string",
"description": "Optional description for this task"
},
"defaultArgs": {
"description": "Default arguments",
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"execArgs": {
"description": "Default arguments",
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
},
"SettingConfig": {
"type": "object",
"patternProperties": {
"": {
"type": "object",
"description": "Internal name",
"required": ["displayName", "type"],
"properties": {
"displayName": {
"type": "string",
"description": "Name to display in the UI"
},
"description": {
"type": ["string", "null"],
"description": "Optional description for this setting"
},
"type": {
"type": "string",
"description": "Type of the attribute to show in the UI. It can be one of BOOLEAN, NUMBER, STRING",
"enum": ["BOOLEAN", "NUMBER", "STRING"]
}
}
}
}
},
"StringList": {
"type": ["array", "null"],
"items": {
"type": "string"
}
},
"CspDirective": {
"description": "Policy directive",
"type": ["array", "null"],
"items": {
"type": "string",
"description": "Allowed domain",
"examples": [
"self",
"http://alloweddomain.com",
"example.com",
"*.example.com"
]
}
}
}
}

0 comments on commit a0d3bac

Please sign in to comment.