UNPKG

3.74 kBTypeScriptView Raw
1import { Command } from './command';
2import { Hooks } from './hooks';
3import { Manifest } from './manifest';
4import { PJSON } from './pjson';
5import { Topic } from './topic';
6export interface Options {
7 root: string;
8 name?: string;
9 type?: string;
10 tag?: string;
11 ignoreManifest?: boolean;
12}
13export interface IPlugin {
14 /**
15 * @anycli/config version
16 */
17 _base: string;
18 /**
19 * name from package.json
20 */
21 name: string;
22 /**
23 * version from package.json
24 *
25 * example: 1.2.3
26 */
27 version: string;
28 /**
29 * full package.json
30 *
31 * parsed with read-pkg
32 */
33 pjson: PJSON.Plugin | PJSON.CLI;
34 /**
35 * used to tell the user how the plugin was installed
36 * examples: core, link, user, dev
37 */
38 type: string;
39 /**
40 * base path of plugin
41 */
42 root: string;
43 /**
44 * npm dist-tag of plugin
45 * only used for user plugins
46 */
47 tag?: string;
48 /**
49 * subplugins of this plugin
50 */
51 plugins: IPlugin[];
52 /**
53 * if it appears to be an npm package but does not look like it's really a CLI plugin, this is set to false
54 */
55 valid: boolean;
56 readonly commands: Command.Plugin[];
57 readonly commandIDs: string[];
58 readonly topics: Topic[];
59 findCommand(id: string, opts: {
60 must: true;
61 }): Command.Plugin;
62 findCommand(id: string, opts?: {
63 must: boolean;
64 }): Command.Plugin | undefined;
65 findTopic(id: string, opts: {
66 must: true;
67 }): Topic;
68 findTopic(id: string, opts?: {
69 must: boolean;
70 }): Topic | undefined;
71 runHook<T extends Hooks, K extends keyof T>(event: K, opts: T[K]): Promise<void>;
72}
73export declare class Plugin implements IPlugin {
74 static loadedPlugins: {
75 [name: string]: Plugin;
76 };
77 _base: string;
78 name: string;
79 version: string;
80 pjson: PJSON.Plugin;
81 type: string;
82 root: string;
83 tag?: string;
84 manifest: Manifest;
85 _topics: Topic[];
86 plugins: IPlugin[];
87 hooks: {
88 [k: string]: string[];
89 };
90 valid: boolean;
91 alreadyLoaded: boolean;
92 protected warned: boolean;
93 constructor(opts: Options);
94 readonly commandsDir: string | undefined;
95 readonly topics: Topic[];
96 readonly commands: {
97 load: () => Command.Class;
98 id: string;
99 hidden: boolean;
100 aliases: string[];
101 description?: string | undefined;
102 usage?: string | string[] | undefined;
103 examples?: string[] | undefined;
104 type?: string | undefined;
105 pluginName?: string | undefined;
106 pluginType?: string | undefined;
107 flags: {
108 [name: string]: Command.Flag;
109 };
110 args: Command.Arg[];
111 }[];
112 readonly commandIDs: string[];
113 findCommand(id: string, opts: {
114 must: true;
115 }): Command.Plugin;
116 findCommand(id: string, opts?: {
117 must: boolean;
118 }): Command.Plugin | undefined;
119 findTopic(id: string, opts: {
120 must: true;
121 }): Topic;
122 findTopic(id: string, opts?: {
123 must: boolean;
124 }): Topic | undefined;
125 runHook<T extends Hooks, K extends keyof T>(event: K, opts: T[K]): Promise<void>;
126 protected readonly _commandIDs: string[];
127 protected _findCommand(id: string, opts: {
128 must: true;
129 }): Command.Class;
130 protected _findCommand(id: string, opts?: {
131 must: boolean;
132 }): Command.Class | undefined;
133 protected _manifest(ignoreManifest: boolean): Manifest;
134 protected loadPlugins(root: string, type: string, plugins: (string | PJSON.Plugin)[]): (string | PJSON.Plugin)[] | undefined;
135 protected warn(err: any, scope?: string): void;
136 protected addMissingTopics(): void;
137}