UNPKG

2.72 kBPlain TextView Raw
1import { Monitor } from '@neo-one/monitor';
2import { ResourceType } from './ResourceType';
3import { TaskList } from './TaskList';
4import { CLIArgs, CLIHook, CreateHook, InteractiveCommand, PluginManager } from './types';
5
6export interface PluginOptions {
7 readonly monitor: Monitor;
8}
9
10export interface CLIHookConfig {
11 readonly name: string;
12 readonly hook: CLIHook;
13}
14
15export interface CreateHookConfig {
16 readonly plugin: string;
17 readonly resourceType: string;
18 readonly hook: CreateHook;
19}
20
21export class Plugin {
22 public readonly monitor: Monitor;
23
24 public constructor({ monitor }: PluginOptions) {
25 this.monitor = monitor;
26 }
27
28 // Called when the user requests a full reset of neo-one
29 public async reset(): Promise<void> {
30 // do nothing
31 }
32
33 // Plugin name, should match the module name, e.g.
34 // `@neo-one/server-plugin-network`
35 public get name(): string {
36 throw new Error('Not Implemented');
37 }
38
39 // Names used for display.
40 public get names(): {
41 readonly capital: string;
42 readonly capitalPlural: string;
43 readonly lower: string;
44 readonly lowerPlural: string;
45 } {
46 throw new Error('Not Implemented');
47 }
48
49 public get resourceTypes(): ReadonlyArray<ResourceType> {
50 return [];
51 }
52
53 public get resourceTypeByName(): { readonly [resourceType: string]: ResourceType } {
54 return this.resourceTypes.reduce<{ readonly [resourceType: string]: ResourceType }>(
55 (acc, resourceType) => ({
56 ...acc,
57 [resourceType.name]: resourceType,
58 }),
59 {},
60 );
61 }
62
63 // Names of plugins this module depends on, e.g.
64 // ['@neo-one/server-plugin-network']
65 public get dependencies(): ReadonlyArray<string> {
66 return [];
67 }
68
69 // Add additional commands.
70 public get commands(): ReadonlyArray<(cliArgs: CLIArgs) => void> {
71 return [];
72 }
73
74 // Add additional interactive commands
75 public get interactive(): ReadonlyArray<InteractiveCommand> {
76 return [];
77 }
78
79 // Hook into other plugin's create resource lifecycle
80 public get createHooks(): ReadonlyArray<CreateHookConfig> {
81 return [];
82 }
83
84 // Hook into other plugin's command lifecycle
85 public get cliPreHooks(): ReadonlyArray<CLIHookConfig> {
86 return [];
87 }
88
89 // Hook into other plugin's command lifecycle
90 public get cliPostHooks(): ReadonlyArray<CLIHookConfig> {
91 return [];
92 }
93
94 public executeTaskList(_pluginManager: PluginManager, _options: string): TaskList {
95 throw new Error('Plugin does not define a way to execute task lists.');
96 }
97
98 // tslint:disable-next-line no-any
99 public async request(_pluginManager: PluginManager, _options: string): Promise<any> {
100 throw new Error('Plugin does not define a way to handle requests.');
101 }
102}