/
PluginController.ts
72 lines (59 loc) · 1.89 KB
/
PluginController.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { PluginDrawer } from "./PluginDrawer";
import { Options } from "../app/Options";
import { PluginManager } from "./PluginManager";
import { CLI } from "../app/CLI";
/**
* Plugin controller
*
* @author Thiago Delgado Pinto
*/
export class PluginController {
private readonly _drawer: PluginDrawer;
constructor( cli: CLI ) {
this._drawer = new PluginDrawer( cli );
}
public process = async ( options: Options ): Promise< boolean > => {
const pm = new PluginManager( options.pluginDir );
if ( options.pluginList ) {
try {
this._drawer.drawPluginList( await pm.findAll() );
return true;
} catch ( e ) {
this._drawer.showError( e );
return false;
}
}
// empty plugin name?
if ( ! options.plugin || options.plugin.trim().length < 1 ) {
this._drawer.showError( new Error( 'Empty plugin name.' ) );
return false;
}
const pluginData = await pm.pluginWithName( options.plugin );
// plugin name not available?
if ( ! pluginData ) {
this._drawer.showMessageOnNoPluginFound( options.plugin );
return false;
}
if ( options.pluginAbout ) {
this._drawer.drawSinglePlugin( pluginData );
return true;
}
if ( options.pluginInstall ) {
try {
await pm.install( pluginData, this._drawer );
} catch ( e ) {
this._drawer.showError( e );
}
return true;
}
if ( options.pluginUninstall ) {
try {
await pm.uninstall( pluginData, this._drawer );
} catch ( e ) {
this._drawer.showError( e );
}
return true;
}
return true;
};
}