6
6
IPluginHandler ,
7
7
IPluginHandlerOptions ,
8
8
Undefinable ,
9
- IPicGo
9
+ IPicGo ,
10
+ IPluginHandlerResult
10
11
} from '../types'
11
12
import { IBuildInEvent } from '../utils/enum'
12
13
import { getProcessPluginName , getNormalPluginName } from '../utils/common'
@@ -18,7 +19,7 @@ class PluginHandler implements IPluginHandler {
18
19
this . ctx = ctx
19
20
}
20
21
21
- async install ( plugins : string [ ] , options : IPluginHandlerOptions = { } , env ?: IProcessEnv ) : Promise < void > {
22
+ async install ( plugins : string [ ] , options : IPluginHandlerOptions = { } , env ?: IProcessEnv ) : Promise < IPluginHandlerResult < boolean > > {
22
23
const installedPlugins : string [ ] = [ ]
23
24
const processPlugins = plugins
24
25
. map ( ( item : string ) => handlePluginNameProcess ( this . ctx , item ) )
@@ -52,13 +53,23 @@ class PluginHandler implements IPluginHandler {
52
53
title : '插件安装成功' ,
53
54
body : [ ...pkgNameList , ...installedPlugins ]
54
55
} )
56
+ const res : IPluginHandlerResult < true > = {
57
+ success : true ,
58
+ body : [ ...pkgNameList , ...installedPlugins ]
59
+ }
60
+ return res
55
61
} else {
56
62
const err = `插件安装失败,失败码为${ result . code } ,错误日志为${ result . data } `
57
63
this . ctx . log . error ( err )
58
64
this . ctx . emit ( 'installFailed' , {
59
65
title : '插件安装失败' ,
60
66
body : err
61
67
} )
68
+ const res : IPluginHandlerResult < false > = {
69
+ success : false ,
70
+ body : err
71
+ }
72
+ return res
62
73
}
63
74
} else if ( installedPlugins . length === 0 ) {
64
75
const err = '插件安装失败,请输入合法插件名或合法安装路径'
@@ -67,16 +78,26 @@ class PluginHandler implements IPluginHandler {
67
78
title : '插件安装失败' ,
68
79
body : err
69
80
} )
81
+ const res : IPluginHandlerResult < false > = {
82
+ success : false ,
83
+ body : err
84
+ }
85
+ return res
70
86
} else {
71
87
this . ctx . log . success ( '插件安装成功' )
72
88
this . ctx . emit ( 'installSuccess' , {
73
89
title : '插件安装成功' ,
74
90
body : [ ...pkgNameList , ...installedPlugins ]
75
91
} )
92
+ const res : IPluginHandlerResult < true > = {
93
+ success : true ,
94
+ body : [ ...pkgNameList , ...installedPlugins ]
95
+ }
96
+ return res
76
97
}
77
98
}
78
99
79
- async uninstall ( plugins : string [ ] ) : Promise < void > {
100
+ async uninstall ( plugins : string [ ] ) : Promise < IPluginHandlerResult < boolean > > {
80
101
const processPlugins = plugins . map ( ( item : string ) => handlePluginNameProcess ( this . ctx , item ) ) . filter ( item => item . success )
81
102
const pkgNameList = processPlugins . map ( item => item . pkgName )
82
103
if ( pkgNameList . length > 0 ) {
@@ -92,13 +113,23 @@ class PluginHandler implements IPluginHandler {
92
113
title : '插件卸载成功' ,
93
114
body : pkgNameList
94
115
} )
116
+ const res : IPluginHandlerResult < true > = {
117
+ success : true ,
118
+ body : pkgNameList
119
+ }
120
+ return res
95
121
} else {
96
122
const err = `插件卸载失败,失败码为${ result . code } ,错误日志为${ result . data } `
97
123
this . ctx . log . error ( err )
98
124
this . ctx . emit ( 'uninstallFailed' , {
99
125
title : '插件卸载失败' ,
100
126
body : err
101
127
} )
128
+ const res : IPluginHandlerResult < false > = {
129
+ success : false ,
130
+ body : err
131
+ }
132
+ return res
102
133
}
103
134
} else {
104
135
const err = '插件卸载失败,请输入合法插件名'
@@ -107,10 +138,15 @@ class PluginHandler implements IPluginHandler {
107
138
title : '插件卸载失败' ,
108
139
body : err
109
140
} )
141
+ const res : IPluginHandlerResult < false > = {
142
+ success : false ,
143
+ body : err
144
+ }
145
+ return res
110
146
}
111
147
}
112
148
113
- async update ( plugins : string [ ] , options : IPluginHandlerOptions = { } , env ?: IProcessEnv ) : Promise < void > {
149
+ async update ( plugins : string [ ] , options : IPluginHandlerOptions = { } , env ?: IProcessEnv ) : Promise < IPluginHandlerResult < boolean > > {
114
150
const processPlugins = plugins . map ( ( item : string ) => handlePluginNameProcess ( this . ctx , item ) ) . filter ( item => item . success )
115
151
const pkgNameList = processPlugins . map ( item => item . pkgName )
116
152
if ( pkgNameList . length > 0 ) {
@@ -123,13 +159,23 @@ class PluginHandler implements IPluginHandler {
123
159
title : '插件更新成功' ,
124
160
body : pkgNameList
125
161
} )
162
+ const res : IPluginHandlerResult < true > = {
163
+ success : true ,
164
+ body : pkgNameList
165
+ }
166
+ return res
126
167
} else {
127
168
const err = `插件更新失败,失败码为${ result . code } ,错误日志为 \n ${ result . data } `
128
169
this . ctx . log . error ( err )
129
170
this . ctx . emit ( 'updateFailed' , {
130
171
title : '插件更新失败' ,
131
172
body : err
132
173
} )
174
+ const res : IPluginHandlerResult < false > = {
175
+ success : false ,
176
+ body : err
177
+ }
178
+ return res
133
179
}
134
180
} else {
135
181
const err = '插件更新失败,请输入合法插件名'
@@ -138,6 +184,11 @@ class PluginHandler implements IPluginHandler {
138
184
title : '插件更新失败' ,
139
185
body : err
140
186
} )
187
+ const res : IPluginHandlerResult < false > = {
188
+ success : false ,
189
+ body : err
190
+ }
191
+ return res
141
192
}
142
193
}
143
194
0 commit comments