Browse Source

flatmap works

master
peter 2 years ago
parent
commit
844b1939dc

+ 95
- 3
src/backend/Admin.ts View File

@@ -7,8 +7,7 @@ import { AdminBase } from 'frontblock-generic/Admin';
7 7
 import { FrontblockApi } from 'frontblock-generic/Api';
8 8
 import { Plugin } from 'frontblock-generic/Plugin';
9 9
 import { socketioRPC } from 'frontblock-generic/RPC';
10
-import { GitUpdater } from './GitUpdater';
11
-import { UpdateManager } from './UpdateManger';
10
+import { GitUpdater, RepoFolderStatus } from './GitUpdater';
12 11
 
13 12
 Logger.configure({
14 13
     appenders: 
@@ -28,9 +27,10 @@ export type AdminConf = { httpPort: number}
28 27
 
29 28
 export class FrontblockAdmin extends AdminBase<AdminConf>{
30 29
    
30
+    private pluginUpdaters:{[name in string]:GitUpdater} = {}
31
+    
31 32
     constructor(runningPlugins: Plugin[] = []){
32 33
         super(runningPlugins)
33
-        this.addPlugin(new UpdateManager(this))
34 34
     }
35 35
 
36 36
     getDefaultConfig(): { apiConf: FrontblockApiConf; } & AdminConf & { dbConf:Knex.Config; } {
@@ -66,6 +66,31 @@ export class FrontblockAdmin extends AdminBase<AdminConf>{
66 66
         return [
67 67
             ...super.exportRPCs(),
68 68
             {
69
+                name: 'installPlugin',
70
+                func: async (name:string, force = false) => {return await this.installPlugin(name, force)},
71
+                type: 'call',
72
+                visibility: 'private'
73
+            },{
74
+                name: 'startPlugin',
75
+                func: async (name:string) => {return await this.startPlugin(name)},
76
+                type: 'call',
77
+                visibility: 'private'
78
+            },{
79
+                name: 'updatePlugin',
80
+                func: async (name) => {return await this.updatePlugin(name)},
81
+                type: 'call',
82
+                visibility: 'private'
83
+            },{
84
+                name: 'setPluginVersion',
85
+                func: async (name, tag) => {return await this.setPluginVersion(name, tag)},
86
+                type: 'call',
87
+                visibility: 'private'
88
+            },{
89
+                name: 'getLoadedPluginNames',
90
+                func: async () => {return await this.getPlugins().map(p => p.name)},
91
+                type: 'call',
92
+                visibility: 'private'
93
+            },{
69 94
                 name: 'selfUpdate',
70 95
                 type:'call',
71 96
                 func: async (force: boolean) => {return await this.selfUpdate(force)},
@@ -87,6 +112,73 @@ export class FrontblockAdmin extends AdminBase<AdminConf>{
87 112
         }
88 113
         return status
89 114
     }
115
+
116
+    async installPlugin(name: string, force:boolean = false):Promise<RepoFolderStatus>{
117
+        logger.warn("Cloning fb-dist/"+name+".git into ./plugins/"+name+" ..."+(force?" USING FORCE!":""))
118
+        this.pluginUpdaters[name] = new GitUpdater("./plugins/"+name)
119
+        const status = await this.pluginUpdaters[name].cloneRepo("https://gitea.frontblock.me/fb-dist/"+name.toLowerCase()+".git", force)
120
+        return status
121
+    }
122
+
123
+    async startPlugin(name:string):Promise<boolean>{
124
+        if(!this.pluginUpdaters[name]) return false
125
+        const status = await this.pluginUpdaters[name].getStatus()
126
+        if(!status.exists || status.empty || !status.tags || status.tags.length === 0){
127
+            if(status.currentTag && !status.latestTag){
128
+                //git glitches sometimes if you check immediately after clone
129
+                logger.warn("re-fetching tag for "+name+"...")
130
+                return await this.startPlugin(name)
131
+            }
132
+            logger.error("Bad repo status", name, status)
133
+            return false
134
+        }
135
+
136
+/*        if(this.loadedPlugins[name]){
137
+            logger.error("Plugin", name, "is already started")
138
+            return false
139
+        }
140
+*/
141
+
142
+        let str = "../plugins/"+name+"/Plugin"
143
+        const pluginClass = await eval('require')(str)
144
+        const pluginObj = new pluginClass.default()
145
+        await pluginObj.start()
146
+        this.addPlugin(pluginObj)
147
+        return true
148
+    }
149
+
150
+    async updatePlugin(name:string):Promise<boolean>{
151
+        if(!this.pluginUpdaters[name]) return false
152
+        const status = await this.pluginUpdaters[name].getStatus()
153
+        if(!status.exists || status.empty || !status.tags || status.tags.length === 0){
154
+            logger.error("Bad repo status", name, status)
155
+            return false
156
+        }
157
+        if(status.currentTag == status.latestTag){
158
+            logger.warn(name, "already at latest tag")
159
+            return false
160
+        }
161
+
162
+        /*
163
+        if(this.loadedPlugins[name]){
164
+            logger.error("Plugin", name, "is running. Stop it first")
165
+            return false
166
+        }
167
+        */
168
+
169
+        this.pluginUpdaters[name].checkoutTag(status.latestTag!)
170
+        return true
171
+    }
172
+
173
+    async setPluginVersion(pluginName:string, tag:string):Promise<RepoFolderStatus>{
174
+        const status = await this.pluginUpdaters[pluginName].getStatus()
175
+        if(!status.exists || !status.tags || status.tags.length === 0 || !status.tags.includes(tag)){
176
+            logger.error("Bad repo status", pluginName, status)
177
+            return status
178
+        }
179
+
180
+        return await this.pluginUpdaters[pluginName].checkoutTag(tag)
181
+    }
90 182
 }
91 183
 
92 184
 process.on( 'SIGINT', function() {

+ 9
- 9
src/backend/FrontblockLib.ts View File

@@ -89,20 +89,20 @@ export class FrontblockConfigLib{
89 89
 }
90 90
 
91 91
 window['fb'] = new FrontblockConfigLib()
92
-declare const fb:{UpdateManager:any}
92
+declare const fb:{Admin:any}
93 93
 window['setup'] = async() => {
94 94
     const i = await Promise.all([
95
-        fb.UpdateManager.installPlugin("ApiClient"),
96
-        fb.UpdateManager.installPlugin("HtmlSupplier"),
97
-        fb.UpdateManager.installPlugin("PaymentManager"),
98
-        fb.UpdateManager.installPlugin("Wallet"),
95
+        fb.Admin.installPlugin("ApiClient"),
96
+        fb.Admin.installPlugin("HtmlSupplier"),
97
+        fb.Admin.installPlugin("PaymentManager"),
98
+        fb.Admin.installPlugin("Wallet"),
99 99
     ])
100 100
     console.log(i)
101 101
     const s = await Promise.all([
102
-        fb.UpdateManager.startPlugin("ApiClient"),
103
-        fb.UpdateManager.startPlugin("HtmlSupplier"),
104
-        fb.UpdateManager.startPlugin("PaymentManager"),
105
-        fb.UpdateManager.startPlugin("Wallet"),
102
+        fb.Admin.startPlugin("ApiClient"),
103
+        fb.Admin.startPlugin("HtmlSupplier"),
104
+        fb.Admin.startPlugin("PaymentManager"),
105
+        fb.Admin.startPlugin("Wallet"),
106 106
     ])
107 107
     if(s.reduce((p,c) => p && c), true)
108 108
         location.reload();

+ 0
- 143
src/backend/UpdateManger.ts View File

@@ -1,143 +0,0 @@
1
-import { Plugin } from "frontblock-generic/Plugin";
2
-import { socketioRPC } from "frontblock-generic/RPC";
3
-import { GitUpdater, RepoFolderStatus } from "./GitUpdater";
4
-import { FrontblockCherryPicker } from "git-cherrypicker";
5
-import * as Logger from 'log4js'
6
-import { FrontblockAdmin } from "./Admin";
7
-import { TableDefiniton } from "frontblock-generic/Admin";
8
-
9
-Logger.configure({
10
-    appenders: 
11
-    {
12
-    "admin/updatemanager": { type: 'stdout' },
13
-    //app: { type: 'file', filename: 'application.log' }
14
-    },
15
-    categories: 
16
-    {
17
-    default: { appenders: [ 'admin/updatemanager' ], level: 'debug' }
18
-    }
19
-})
20
-const logger = Logger.getLogger("admin/updatemanager") 
21
-
22
-export class UpdateManager extends Plugin{
23
-    
24
-    private loadedPlugins:{[name in string]:Plugin} = {}
25
-    private dashboardUpdater:GitUpdater
26
-    private adminUpdater:GitUpdater
27
-    private pluginUpdaters:{[name in string]:GitUpdater} = {}
28
-
29
-    constructor(admin:FrontblockAdmin){
30
-        super(admin, "UpdateManager")
31
-    }
32
-
33
-    getDefaultConfig(): {} {
34
-        return {}
35
-    }
36
-
37
-    exportRPCs(): socketioRPC[] {
38
-        return [{
39
-            name: 'installPlugin',
40
-            func: async (name:string, force = false) => {return await this.installPlugin(name, force)},
41
-            type: 'call',
42
-            visibility: 'private'
43
-        },{
44
-            name: 'startPlugin',
45
-            func: async (name:string) => {return await this.startPlugin(name)},
46
-            type: 'call',
47
-            visibility: 'private'
48
-        },{
49
-            name: 'updatePlugin',
50
-            func: async (name) => {return await this.updatePlugin(name)},
51
-            type: 'call',
52
-            visibility: 'private'
53
-        },{
54
-            name: 'setPluginVersion',
55
-            func: async (name, tag) => {return await this.setPluginVersion(name, tag)},
56
-            type: 'call',
57
-            visibility: 'private'
58
-        },{
59
-            name: 'getLoadedPluginNames',
60
-            func: async () => {return await this.getLoadedPluginNames()},
61
-            type: 'call',
62
-            visibility: 'private'
63
-        }]
64
-    }
65
-
66
-    getTableDefinitions(): TableDefiniton[] {
67
-        return []
68
-    }
69
- 
70
-    async installPlugin(name: string, force:boolean = false):Promise<RepoFolderStatus>{
71
-        logger.warn("Cloning fb-dist/"+name+".git into ./plugins/"+name+" ..."+(force?" USING FORCE!":""))
72
-        this.pluginUpdaters[name] = new GitUpdater("./plugins/"+name)
73
-        const status = await this.pluginUpdaters[name].cloneRepo("https://gitea.frontblock.me/fb-dist/"+name.toLowerCase()+".git", force)
74
-        return status
75
-    }
76
-
77
-    async startPlugin(name:string):Promise<boolean>{
78
-        if(!this.pluginUpdaters[name]) return false
79
-        const status = await this.pluginUpdaters[name].getStatus()
80
-        if(!status.exists || status.empty || !status.tags || status.tags.length === 0){
81
-            if(status.currentTag && !status.latestTag){
82
-                //git glitches sometimes if you check immediately after clone
83
-                logger.warn("re-fetching tag for "+name+"...")
84
-                return await this.startPlugin(name)
85
-            }
86
-            logger.error("Bad repo status", name, status)
87
-            return false
88
-        }
89
-
90
-        if(this.loadedPlugins[name]){
91
-            logger.error("Plugin", name, "is already started")
92
-            return false
93
-        }
94
-
95
-
96
-        let str = "../plugins/"+name+"/Plugin"
97
-        const pluginClass = await eval('require')(str)
98
-        const pluginObj = new pluginClass.default()
99
-        await pluginObj.start()
100
-        this.admin.addPlugin(pluginObj)
101
-        this.loadedPlugins[name] = pluginObj
102
-        return true
103
-    }
104
-
105
-    async updatePlugin(name:string):Promise<boolean>{
106
-        if(!this.pluginUpdaters[name]) return false
107
-        const status = await this.pluginUpdaters[name].getStatus()
108
-        if(!status.exists || status.empty || !status.tags || status.tags.length === 0){
109
-            logger.error("Bad repo status", name, status)
110
-            return false
111
-        }
112
-        if(status.currentTag == status.latestTag){
113
-            logger.warn(name, "already at latest tag")
114
-            return false
115
-        }
116
-
117
-        if(this.loadedPlugins[name]){
118
-            logger.error("Plugin", name, "is running. Stop it first")
119
-            return false
120
-        }
121
-
122
-        this.pluginUpdaters[name].checkoutTag(status.latestTag!)
123
-        return true
124
-    }
125
-
126
-    async setPluginVersion(pluginName:string, tag:string):Promise<RepoFolderStatus>{
127
-        const status = await this.pluginUpdaters[pluginName].getStatus()
128
-        if(!status.exists || !status.tags || status.tags.length === 0 || !status.tags.includes(tag)){
129
-            logger.error("Bad repo status", pluginName, status)
130
-            return status
131
-        }
132
-
133
-        return await this.pluginUpdaters[pluginName].checkoutTag(tag)
134
-    }
135
-
136
-    getLoadedPlugins():Plugin<any>[]{
137
-        return Object.values(this.loadedPlugins)
138
-    }
139
-
140
-    getLoadedPluginNames():string[]{
141
-        return Object.keys(this.loadedPlugins)
142
-    }
143
-}

+ 3
- 3
src/frontend/src/app/dynamic-loader/dynamic-loader.component.ts View File

@@ -52,7 +52,7 @@ import { FrontendPlugin, SidebarEntries, SidebarEntry } from "frontblock-generic
52 52
 import { environment } from "../../environments/environment"
53 53
 
54 54
 const fb = environment.production ? window["fb"] : {
55
-  UpdateManager: {
55
+  Admin: {
56 56
     getLoadedPluginNames: () => ["ApiClient", "Wallet"]
57 57
   }
58 58
 }
@@ -78,10 +78,10 @@ export class DynamicLoaderComponent implements AfterViewInit {
78 78
   }
79 79
 
80 80
   private async loadWidgets() {
81
-    while (!fb.UpdateManager) {
81
+    while (!fb.Admin) {
82 82
       await new Promise((resolve) => setTimeout(resolve, 50))
83 83
     }
84
-    const pluginNames = await fb.UpdateManager.getLoadedPluginNames()
84
+    const pluginNames = await fb.Admin.getLoadedPluginNames()
85 85
     pluginNames.forEach(element => this.installWidget(element));
86 86
   }
87 87
 

Loading…
Cancel
Save