plugin: Plugin modules now export a single top level identifier
Makes typing much easier. Addresse's Will's last comment.
This commit is contained in:
parent
8a8159c683
commit
14f408a837
|
@ -189,11 +189,16 @@ export class PluginAPI {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const pluginModule = require(dir)
|
||||||
|
if (!pluginModule.plugin) {
|
||||||
|
throw new Error("plugin module does not export a plugin")
|
||||||
|
}
|
||||||
|
|
||||||
const p = {
|
const p = {
|
||||||
name: packageJSON.name,
|
name: packageJSON.name,
|
||||||
version: packageJSON.version,
|
version: packageJSON.version,
|
||||||
modulePath: dir,
|
modulePath: dir,
|
||||||
...require(dir),
|
...pluginModule.plugin,
|
||||||
} as Plugin
|
} as Plugin
|
||||||
|
|
||||||
if (!p.displayName) {
|
if (!p.displayName) {
|
||||||
|
|
|
@ -2,24 +2,25 @@ import * as express from "express"
|
||||||
import * as fspath from "path"
|
import * as fspath from "path"
|
||||||
import * as pluginapi from "../../../typings/pluginapi"
|
import * as pluginapi from "../../../typings/pluginapi"
|
||||||
|
|
||||||
export const displayName = "Test Plugin"
|
export const plugin: pluginapi.Plugin = {
|
||||||
export const routerPath = "/test-plugin"
|
displayName: "Test Plugin",
|
||||||
export const homepageURL = "https://example.com"
|
routerPath: "/test-plugin",
|
||||||
export const description = "Plugin used in code-server tests."
|
homepageURL: "https://example.com",
|
||||||
|
description: "Plugin used in code-server tests.",
|
||||||
|
|
||||||
export function init(config: pluginapi.PluginConfig) {
|
init: (config) => {
|
||||||
config.logger.debug("test-plugin loaded!")
|
config.logger.debug("test-plugin loaded!")
|
||||||
}
|
},
|
||||||
|
|
||||||
export function router(): express.Router {
|
router: () => {
|
||||||
const r = express.Router()
|
const r = express.Router()
|
||||||
r.get("/goland/icon.svg", (req, res) => {
|
r.get("/goland/icon.svg", (req, res) => {
|
||||||
res.sendFile(fspath.resolve(__dirname, "../public/icon.svg"))
|
res.sendFile(fspath.resolve(__dirname, "../public/icon.svg"))
|
||||||
})
|
})
|
||||||
return r
|
return r
|
||||||
}
|
},
|
||||||
|
|
||||||
export function applications(): pluginapi.Application[] {
|
applications: () => {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
name: "Test App",
|
name: "Test App",
|
||||||
|
@ -31,4 +32,5 @@ export function applications(): pluginapi.Application[] {
|
||||||
homepageURL: "https://example.com",
|
homepageURL: "https://example.com",
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,8 @@ import * as express from "express"
|
||||||
/**
|
/**
|
||||||
* Plugins
|
* Plugins
|
||||||
*
|
*
|
||||||
* Plugins are just node modules.
|
* Plugins are just node modules that contain a top level export "plugin" that implements
|
||||||
|
* the Plugin interface.
|
||||||
*
|
*
|
||||||
* 1. code-server uses $CS_PLUGIN to find plugins.
|
* 1. code-server uses $CS_PLUGIN to find plugins.
|
||||||
*
|
*
|
||||||
|
@ -78,7 +79,7 @@ import * as express from "express"
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Your plugin module must implement this interface.
|
* Your plugin module must have a top level export "plugin" that implements this interface.
|
||||||
*
|
*
|
||||||
* The plugin's router will be mounted at <code-sever-root>/<plugin-path>
|
* The plugin's router will be mounted at <code-sever-root>/<plugin-path>
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue