Add inline manifest documentation (#503)
parent
75bdd6390b
commit
447dd2fed1
|
@ -8,6 +8,13 @@ import { CodeWidgetT } from "../web/hooks/code_widget.ts";
|
||||||
import { MQHookT } from "../plugos/hooks/mq.ts";
|
import { MQHookT } from "../plugos/hooks/mq.ts";
|
||||||
import { EndpointHookT } from "../plugos/hooks/endpoint.ts";
|
import { EndpointHookT } from "../plugos/hooks/endpoint.ts";
|
||||||
|
|
||||||
|
/** Silverbullet hooks give plugs access to silverbullet core systems.
|
||||||
|
*
|
||||||
|
* Hooks are associated with typescript functions through a manifest file.
|
||||||
|
* On various triggers (user enters a slash command, an HTTP endpoint is hit, user clicks, etc) the typescript function is called.
|
||||||
|
*
|
||||||
|
* related: plugos/type.ts#FunctionDef
|
||||||
|
*/
|
||||||
export type SilverBulletHooks =
|
export type SilverBulletHooks =
|
||||||
& CommandHookT
|
& CommandHookT
|
||||||
& SlashCommandHookT
|
& SlashCommandHookT
|
||||||
|
@ -18,15 +25,40 @@ export type SilverBulletHooks =
|
||||||
& EndpointHookT
|
& EndpointHookT
|
||||||
& PlugNamespaceHookT;
|
& PlugNamespaceHookT;
|
||||||
|
|
||||||
|
/** Syntax extension allow plugs to declaratively add new *inline* parse tree nodes to the markdown parser. */
|
||||||
export type SyntaxExtensions = {
|
export type SyntaxExtensions = {
|
||||||
|
/** A map of node **name** (also called "type"), to parsing and highlighting instructions. Each entry defines a new node. By convention node names (types) are UpperCamelCase (PascalCase).
|
||||||
|
*
|
||||||
|
* see: plug-api/lib/tree.ts#ParseTree
|
||||||
|
*/
|
||||||
syntax?: { [key: string]: NodeDef };
|
syntax?: { [key: string]: NodeDef };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Parsing and highlighting instructions for SyntaxExtension */
|
||||||
export type NodeDef = {
|
export type NodeDef = {
|
||||||
|
/** An array of possible first characters to begin matching on.
|
||||||
|
*
|
||||||
|
* **Example**: If this node has the regex '[abc][123]', NodeDef.firstCharacters should be ["a", "b", "c"].
|
||||||
|
*/
|
||||||
firstCharacters: string[];
|
firstCharacters: string[];
|
||||||
|
|
||||||
|
/** A regular expression that matches the *entire* syntax, including the first character. */
|
||||||
regex: string;
|
regex: string;
|
||||||
|
|
||||||
|
/** CSS styles to apply to the matched text.
|
||||||
|
*
|
||||||
|
* Key-value pair of CSS key to value:
|
||||||
|
*
|
||||||
|
* **Example**: `backgroundColor: "rgba(22,22,22,0.07)"`
|
||||||
|
*/
|
||||||
styles: { [key: string]: string };
|
styles: { [key: string]: string };
|
||||||
|
|
||||||
|
/** CSS class name to apply to the matched text */
|
||||||
className?: string;
|
className?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** A plug manifest configures hooks, declares syntax extensions, and describes plug metadata.
|
||||||
|
*
|
||||||
|
* Typically the manifest file is in a plug's root directory, named `${plugName}.plug.yaml`.
|
||||||
|
*/
|
||||||
export type Manifest = plugos.Manifest<SilverBulletHooks> & SyntaxExtensions;
|
export type Manifest = plugos.Manifest<SilverBulletHooks> & SyntaxExtensions;
|
||||||
|
|
|
@ -1,22 +1,52 @@
|
||||||
import { System } from "./system.ts";
|
import { System } from "./system.ts";
|
||||||
import { AssetJson } from "./asset_bundle/bundle.ts";
|
import { AssetJson } from "./asset_bundle/bundle.ts";
|
||||||
|
|
||||||
|
/** The generic top level of a plug manifest file.
|
||||||
|
* Defines plug metadata and functions.
|
||||||
|
*/
|
||||||
export interface Manifest<HookT> {
|
export interface Manifest<HookT> {
|
||||||
|
/** The plug's name. Typically this is the name of the manifest file, without the file extension. */
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
|
/** A list of syscall permissions required for this plug to function.
|
||||||
|
*
|
||||||
|
* Possible values:
|
||||||
|
* - `fetch`: enables `fetch` function. (see: plug-api/plugos-syscall/fetch.ts, and plug-api/lib/fetch.ts)
|
||||||
|
* - `shell`: enables the `shell.run` syscall. (see: plug-api/plugos-syscall/shell.ts)
|
||||||
|
*/
|
||||||
requiredPermissions?: string[];
|
requiredPermissions?: string[];
|
||||||
|
|
||||||
|
/** A list of files or glob patterns that should be bundled with the plug.
|
||||||
|
*
|
||||||
|
* These files will be accessible through the `asset.readAsset` function.
|
||||||
|
*
|
||||||
|
* see: plug-api/plugos-syscall/asset.ts#readAsset
|
||||||
|
*/
|
||||||
assets?: string[] | AssetJson;
|
assets?: string[] | AssetJson;
|
||||||
|
|
||||||
|
/** A map of function names to definitions. Declared functions are public, and may be associated with various hooks
|
||||||
|
*
|
||||||
|
* see: common/manifest.ts#SilverBulletHooks
|
||||||
|
*/
|
||||||
functions: {
|
functions: {
|
||||||
[key: string]: FunctionDef<HookT>;
|
[key: string]: FunctionDef<HookT>;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Associates hooks with a function. This is the generic base structure, that identifies the function. Hooks are defined by the type parameter. */
|
||||||
export type FunctionDef<HookT> = {
|
export type FunctionDef<HookT> = {
|
||||||
// Read the function from this path and inline it
|
/** A function path, in the form `${relativeFilename}:${functionName}`.
|
||||||
// Format: filename:functionName
|
*
|
||||||
|
* During compilation (see `../build_plugs.ts`) the function is read from the file and inlined into the plug bundle.
|
||||||
|
*
|
||||||
|
* This field and `FunctionDef.redirect` are mutually exclusive.
|
||||||
|
*/
|
||||||
path?: string;
|
path?: string;
|
||||||
// Reuse an
|
|
||||||
// Format: plugName.functionName
|
/** A function from another plug, in the form `${plugName}.${functionName}` that will be attached to the given hooks. */
|
||||||
redirect?: string;
|
redirect?: string;
|
||||||
|
|
||||||
|
/** Environments where this plug is allowed to run, current may be one of "cli", "server", or "client". */
|
||||||
env?: string;
|
env?: string;
|
||||||
} & HookT;
|
} & HookT;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue