|
| 1 | +/** |
| 2 | + * This file describes the code-server plugin API for adding new applications. |
| 3 | + */ |
| 4 | +import { Logger } from "@coder/logger" |
| 5 | +import * as express from "express" |
| 6 | + |
| 7 | +/** |
| 8 | + * Overlay |
| 9 | + * |
| 10 | + * The homepage of code-server will launch into VS Code. However, there will be an overlay |
| 11 | + * button that when clicked, will show all available applications with their names, |
| 12 | + * icons and provider plugins. When one clicks on an app's icon, they will be directed |
| 13 | + * to <code-server-root>/<plugin-name>/<app-name> to access the application. |
| 14 | + */ |
| 15 | + |
| 16 | +/** |
| 17 | + * Plugins |
| 18 | + * |
| 19 | + * Plugins are just node modules. |
| 20 | + * |
| 21 | + * code-server uses $CS_PLUGIN_PATH to find plugins. Each subdirectory in |
| 22 | + * $CS_PLUGIN_PATH with a package.json where the engine is code-server is |
| 23 | + * a valid plugin. |
| 24 | + * |
| 25 | + * e.g. CS_PLUGIN_PATH=/tmp/nhooyr:/tmp/ash will cause code-server to search |
| 26 | + * /tmp/nhooyr and then /tmp/ash for plugins. |
| 27 | + * |
| 28 | + * CS_PLUGIN_PATH defaults to |
| 29 | + * ~/.local/share/code-server/plugins:/usr/share/code-server/plugins |
| 30 | + * if unset. |
| 31 | + * |
| 32 | + * code-server also uses $CS_PLUGIN to find plugins. |
| 33 | + * |
| 34 | + * e.g. CS_PLUGIN=/tmp/will:/tmp/teffen will cause code-server to load |
| 35 | + * /tmp/will and /tmp/teffen as plugins. |
| 36 | + * |
| 37 | + * Built in plugins are also loaded from __dirname/../plugins |
| 38 | + * |
| 39 | + * Priority is $CS_PLUGIN, $CS_PLUGIN_PATH and then the builtin plugins. |
| 40 | + * After the search is complete, plugins will be required in first found order and |
| 41 | + * initialized. See the Plugin interface for details. |
| 42 | + * |
| 43 | + * There is also a /api/applications endpoint to allow programmatic access to all |
| 44 | + * available applications. It could be used to create a custom application dashboard |
| 45 | + * for example. |
| 46 | + */ |
| 47 | + |
| 48 | +/** |
| 49 | + * Your plugin module must implement this interface. |
| 50 | + * |
| 51 | + * The plugin's name, description and version are fetched from its module's package.json |
| 52 | + * |
| 53 | + * The plugin's router will be mounted at <code-sever-root>/<plugin-name> |
| 54 | + * |
| 55 | + * If two plugins are found with the exact same name, then code-server will |
| 56 | + * use the last one and emit a warning. |
| 57 | + */ |
| 58 | +export interface Plugin { |
| 59 | + /** |
| 60 | + * init is called so that the plugin may initialize itself with the config. |
| 61 | + */ |
| 62 | + init(config: PluginConfig): void |
| 63 | + |
| 64 | + /** |
| 65 | + * Returns the plugin's router. |
| 66 | + */ |
| 67 | + router(): express.Router |
| 68 | + |
| 69 | + /** |
| 70 | + * code-server uses this to collect the list of applications that |
| 71 | + * the plugin can currently provide. |
| 72 | + * It is called when /api/applications is hit or the overlay needs to |
| 73 | + * refresh the list of applications |
| 74 | + * |
| 75 | + * Ensure this is as fast as possible. |
| 76 | + */ |
| 77 | + applications(): Application[] | Promise<Application[]> |
| 78 | +} |
| 79 | + |
| 80 | +/** |
| 81 | + * PluginConfig contains the configuration required for initializing |
| 82 | + * a plugin. |
| 83 | + */ |
| 84 | +export interface PluginConfig { |
| 85 | + /** |
| 86 | + * All plugin logs should be logged via this logger. |
| 87 | + */ |
| 88 | + readonly logger: Logger |
| 89 | +} |
| 90 | + |
| 91 | +/** |
| 92 | + * Application represents a user accessible application. |
| 93 | + * |
| 94 | + * When the user clicks on the icon in the overlay, they will be |
| 95 | + * redirected to <code-server-root>/<plugin-name>/<app-name> |
| 96 | + * where the application should be accessible. |
| 97 | + * |
| 98 | + * If the app's name is the same as the plugin's name then |
| 99 | + * <code-server-root>/<plugin-name> will be used instead. |
| 100 | + */ |
| 101 | +export interface Application { |
| 102 | + readonly name: string |
| 103 | + readonly version: string |
| 104 | + |
| 105 | + /** |
| 106 | + * The path at which the icon for this application can be accessed. |
| 107 | + * <code-server-root>/<plugin-name>/<app-name>/<icon-path> |
| 108 | + */ |
| 109 | + readonly iconPath: string |
| 110 | +} |
0 commit comments