3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-15 05:41:51 +00:00

Add usageGuide/configurationGuide to PluginInfo, make trimPluginDescription dynamic

Previously trimPluginDescription was hardcoded to trim 6 spaces from
the beginning of every line. Now the function looks at the last non-
empty line and uses its indentation to determine how many spaces to
trim from the other lines.
This commit is contained in:
Dragory 2019-09-29 15:55:17 +03:00
parent 86b1df0a6a
commit a905e82492

View file

@ -23,21 +23,31 @@ import { mergeConfig } from "knub/dist/configUtils";
const SLOW_RESOLVE_THRESHOLD = 1500; const SLOW_RESOLVE_THRESHOLD = 1500;
/**
* Wrapper for the string type that indicates the text will be parsed as Markdown later
*/
type TMarkdown = string;
export interface PluginInfo { export interface PluginInfo {
prettyName: string; prettyName: string;
description?: string; description?: TMarkdown;
usageGuide?: TMarkdown;
configurationGuide?: TMarkdown;
} }
export interface CommandInfo { export interface CommandInfo {
description?: string; description?: TMarkdown;
basicUsage?: string; basicUsage?: TMarkdown;
parameterDescriptions?: { parameterDescriptions?: {
[key: string]: string; [key: string]: TMarkdown;
}; };
} }
export function trimPluginDescription(str) { export function trimPluginDescription(str) {
return trimIndents(trimEmptyStartEndLines(str), 6); const emptyLinesTrimmed = trimEmptyStartEndLines(str);
const lines = emptyLinesTrimmed.split("\n");
const lastLineIndentation = (lines[lines.length - 1].match(/^ +/g) || [""])[0].length;
return trimIndents(emptyLinesTrimmed, lastLineIndentation);
} }
export class ZeppelinPlugin<TConfig extends {} = IBasePluginConfig> extends Plugin<TConfig> { export class ZeppelinPlugin<TConfig extends {} = IBasePluginConfig> extends Plugin<TConfig> {