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;
/**
* Wrapper for the string type that indicates the text will be parsed as Markdown later
*/
type TMarkdown = string;
export interface PluginInfo {
prettyName: string;
description?: string;
description?: TMarkdown;
usageGuide?: TMarkdown;
configurationGuide?: TMarkdown;
}
export interface CommandInfo {
description?: string;
basicUsage?: string;
description?: TMarkdown;
basicUsage?: TMarkdown;
parameterDescriptions?: {
[key: string]: string;
[key: string]: TMarkdown;
};
}
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> {