flatmap works
This commit is contained in:
+95
-3
@@ -7,8 +7,7 @@ import { AdminBase } from 'frontblock-generic/Admin';
|
||||
import { FrontblockApi } from 'frontblock-generic/Api';
|
||||
import { Plugin } from 'frontblock-generic/Plugin';
|
||||
import { socketioRPC } from 'frontblock-generic/RPC';
|
||||
import { GitUpdater } from './GitUpdater';
|
||||
import { UpdateManager } from './UpdateManger';
|
||||
import { GitUpdater, RepoFolderStatus } from './GitUpdater';
|
||||
|
||||
Logger.configure({
|
||||
appenders:
|
||||
@@ -28,9 +27,10 @@ export type AdminConf = { httpPort: number}
|
||||
|
||||
export class FrontblockAdmin extends AdminBase<AdminConf>{
|
||||
|
||||
private pluginUpdaters:{[name in string]:GitUpdater} = {}
|
||||
|
||||
constructor(runningPlugins: Plugin[] = []){
|
||||
super(runningPlugins)
|
||||
this.addPlugin(new UpdateManager(this))
|
||||
}
|
||||
|
||||
getDefaultConfig(): { apiConf: FrontblockApiConf; } & AdminConf & { dbConf:Knex.Config; } {
|
||||
@@ -66,6 +66,31 @@ export class FrontblockAdmin extends AdminBase<AdminConf>{
|
||||
return [
|
||||
...super.exportRPCs(),
|
||||
{
|
||||
name: 'installPlugin',
|
||||
func: async (name:string, force = false) => {return await this.installPlugin(name, force)},
|
||||
type: 'call',
|
||||
visibility: 'private'
|
||||
},{
|
||||
name: 'startPlugin',
|
||||
func: async (name:string) => {return await this.startPlugin(name)},
|
||||
type: 'call',
|
||||
visibility: 'private'
|
||||
},{
|
||||
name: 'updatePlugin',
|
||||
func: async (name) => {return await this.updatePlugin(name)},
|
||||
type: 'call',
|
||||
visibility: 'private'
|
||||
},{
|
||||
name: 'setPluginVersion',
|
||||
func: async (name, tag) => {return await this.setPluginVersion(name, tag)},
|
||||
type: 'call',
|
||||
visibility: 'private'
|
||||
},{
|
||||
name: 'getLoadedPluginNames',
|
||||
func: async () => {return await this.getPlugins().map(p => p.name)},
|
||||
type: 'call',
|
||||
visibility: 'private'
|
||||
},{
|
||||
name: 'selfUpdate',
|
||||
type:'call',
|
||||
func: async (force: boolean) => {return await this.selfUpdate(force)},
|
||||
@@ -87,6 +112,73 @@ export class FrontblockAdmin extends AdminBase<AdminConf>{
|
||||
}
|
||||
return status
|
||||
}
|
||||
|
||||
async installPlugin(name: string, force:boolean = false):Promise<RepoFolderStatus>{
|
||||
logger.warn("Cloning fb-dist/"+name+".git into ./plugins/"+name+" ..."+(force?" USING FORCE!":""))
|
||||
this.pluginUpdaters[name] = new GitUpdater("./plugins/"+name)
|
||||
const status = await this.pluginUpdaters[name].cloneRepo("https://gitea.frontblock.me/fb-dist/"+name.toLowerCase()+".git", force)
|
||||
return status
|
||||
}
|
||||
|
||||
async startPlugin(name:string):Promise<boolean>{
|
||||
if(!this.pluginUpdaters[name]) return false
|
||||
const status = await this.pluginUpdaters[name].getStatus()
|
||||
if(!status.exists || status.empty || !status.tags || status.tags.length === 0){
|
||||
if(status.currentTag && !status.latestTag){
|
||||
//git glitches sometimes if you check immediately after clone
|
||||
logger.warn("re-fetching tag for "+name+"...")
|
||||
return await this.startPlugin(name)
|
||||
}
|
||||
logger.error("Bad repo status", name, status)
|
||||
return false
|
||||
}
|
||||
|
||||
/* if(this.loadedPlugins[name]){
|
||||
logger.error("Plugin", name, "is already started")
|
||||
return false
|
||||
}
|
||||
*/
|
||||
|
||||
let str = "../plugins/"+name+"/Plugin"
|
||||
const pluginClass = await eval('require')(str)
|
||||
const pluginObj = new pluginClass.default()
|
||||
await pluginObj.start()
|
||||
this.addPlugin(pluginObj)
|
||||
return true
|
||||
}
|
||||
|
||||
async updatePlugin(name:string):Promise<boolean>{
|
||||
if(!this.pluginUpdaters[name]) return false
|
||||
const status = await this.pluginUpdaters[name].getStatus()
|
||||
if(!status.exists || status.empty || !status.tags || status.tags.length === 0){
|
||||
logger.error("Bad repo status", name, status)
|
||||
return false
|
||||
}
|
||||
if(status.currentTag == status.latestTag){
|
||||
logger.warn(name, "already at latest tag")
|
||||
return false
|
||||
}
|
||||
|
||||
/*
|
||||
if(this.loadedPlugins[name]){
|
||||
logger.error("Plugin", name, "is running. Stop it first")
|
||||
return false
|
||||
}
|
||||
*/
|
||||
|
||||
this.pluginUpdaters[name].checkoutTag(status.latestTag!)
|
||||
return true
|
||||
}
|
||||
|
||||
async setPluginVersion(pluginName:string, tag:string):Promise<RepoFolderStatus>{
|
||||
const status = await this.pluginUpdaters[pluginName].getStatus()
|
||||
if(!status.exists || !status.tags || status.tags.length === 0 || !status.tags.includes(tag)){
|
||||
logger.error("Bad repo status", pluginName, status)
|
||||
return status
|
||||
}
|
||||
|
||||
return await this.pluginUpdaters[pluginName].checkoutTag(tag)
|
||||
}
|
||||
}
|
||||
|
||||
process.on( 'SIGINT', function() {
|
||||
|
||||
Reference in New Issue
Block a user