UNPKG

3.88 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 flags: {
107 [name: string]: Command.Flag;
108 };
109 args: {
110 name: string;
111 description?: string | undefined;
112 required?: boolean | undefined;
113 hidden?: boolean | undefined;
114 default?: string | undefined;
115 options?: string[] | undefined;
116 }[];
117 }[];
118 readonly commandIDs: string[];
119 findCommand(id: string, opts: {
120 must: true;
121 }): Command.Plugin;
122 findCommand(id: string, opts?: {
123 must: boolean;
124 }): Command.Plugin | undefined;
125 findTopic(id: string, opts: {
126 must: true;
127 }): Topic;
128 findTopic(id: string, opts?: {
129 must: boolean;
130 }): Topic | undefined;
131 runHook<T extends Hooks, K extends keyof T>(event: K, opts: T[K]): Promise<void>;
132 protected readonly _commandIDs: string[];
133 protected _findCommand(id: string, opts: {
134 must: true;
135 }): Command.Class;
136 protected _findCommand(id: string, opts?: {
137 must: boolean;
138 }): Command.Class | undefined;
139 protected _manifest(ignoreManifest: boolean): Manifest;
140 protected loadPlugins(root: string, plugins: (string | PJSON.Plugin)[]): (string | PJSON.Plugin)[] | undefined;
141 protected warn(err: any, scope?: string): void;
142}