stuff
This commit is contained in:
+117
-12
@@ -3,8 +3,11 @@ import { socketioRPC } from "frontblock-generic/RPC";
|
||||
import { GitUpdater, RepoFolderStatus } from "./GitUpdater";
|
||||
import { FrontblockCherryPicker } from "git-cherrypicker";
|
||||
import * as Logger from 'log4js'
|
||||
import { mkdirSync } from "fs";
|
||||
import * as path from "path";
|
||||
import { FrontblockAdmin } from "./FrontblockAdmin";
|
||||
import { TableDefiniton } from "frontblock-generic/Admin";
|
||||
import { promises as fs, mkdirSync } from "fs"
|
||||
|
||||
var exec = require('child-process-promise').exec;
|
||||
|
||||
Logger.configure({
|
||||
@@ -20,10 +23,106 @@ Logger.configure({
|
||||
})
|
||||
const logger = Logger.getLogger("admin/updatemanager")
|
||||
|
||||
abstract class Extension{
|
||||
constructor(
|
||||
public name: string,
|
||||
public version: string,
|
||||
){}
|
||||
|
||||
export class UpdateManager extends Plugin<void>{
|
||||
name: string = "UpdateManager"
|
||||
private loadedPlugins:{[name in string]:Plugin<any>} = {}
|
||||
abstract install():Promise<boolean>
|
||||
abstract uninstall():Promise<boolean>
|
||||
abstract update():Promise<boolean>
|
||||
abstract isOutdated():Promise<boolean>
|
||||
}
|
||||
|
||||
export class NPMExtension extends Extension{
|
||||
constructor(
|
||||
name,
|
||||
version = "latest",
|
||||
public localPrefix,
|
||||
){
|
||||
super(name, version)
|
||||
}
|
||||
|
||||
public async install(): Promise<boolean> {
|
||||
logger.info("npm install", this.name, 'to', path.resolve(this.localPrefix, this.name))
|
||||
await fs.mkdir(this.localPrefix, {recursive: true})
|
||||
const { error, stdout, stderr } = await exec('npm install --prefix '+ this.localPrefix + ' ' + this.name+"@"+this.version)
|
||||
if (error !== null) {
|
||||
logger.warn('npm install', this.name, 'from prefix', this.localPrefix, 'stderr:', stderr)
|
||||
return false
|
||||
} else {
|
||||
logger.info('npm install', this.name, 'from prefix', this.localPrefix, 'stdout:', stdout)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
public async uninstall(): Promise<boolean> {
|
||||
logger.info("npm uninstall", this.name, 'from', path.resolve(this.localPrefix, this.name))
|
||||
const { error, stdout, stderr } = await exec('npm uninstall --prefix '+ this.localPrefix + ' ' + this.name)
|
||||
if (error !== null) {
|
||||
logger.warn('npm uninstall', this.name, 'from prefix', this.localPrefix, 'stderr:', stderr)
|
||||
return false
|
||||
} else {
|
||||
logger.info('npm uninstall', this.name, 'from prefix', this.localPrefix, 'stdout:', stdout)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
public async update(): Promise<boolean> {
|
||||
logger.info("npm update", path.resolve(this.localPrefix, this.name))
|
||||
const { error, stdout, stderr } = await exec('npm update --prefix '+ this.localPrefix + ' ' + this.name)
|
||||
if (error !== null) {
|
||||
logger.warn('npm update', this.name, 'from prefix', this.localPrefix, 'stderr:', stderr)
|
||||
return false
|
||||
} else {
|
||||
logger.info('npm update', this.name, 'from prefix', this.localPrefix, 'stdout:', stdout)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
public async isOutdated(): Promise<boolean> {
|
||||
logger.info("npm outdated", path.resolve(this.localPrefix, this.name))
|
||||
const { error, stdout, stderr } = await exec('npm list --prefix '+ this.localPrefix + ' --depth=0 | grep ' + this.name)
|
||||
if (error !== null) {
|
||||
logger.warn('npm outdated', this.name, 'from prefix', this.localPrefix, 'stderr:', stderr)
|
||||
return false
|
||||
} else {
|
||||
logger.info('npm outdated', this.name, 'from prefix', this.localPrefix, 'stdout:', stdout)
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class GitExtension extends Extension{
|
||||
constructor(
|
||||
name:string,
|
||||
version = "latest",
|
||||
public localPrefix:string,
|
||||
){
|
||||
super(name, version)
|
||||
}
|
||||
|
||||
public async install(): Promise<boolean> {
|
||||
|
||||
}
|
||||
|
||||
public async uninstall(): Promise<boolean> {
|
||||
|
||||
}
|
||||
|
||||
public async update(): Promise<boolean> {
|
||||
|
||||
}
|
||||
|
||||
public async isOutdated(): Promise<boolean> {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
export class UpdateManager extends Plugin{
|
||||
|
||||
private loadedPlugins:{[name in string]:Plugin} = {}
|
||||
private dashboardUpdater:GitUpdater
|
||||
private adminUpdater:GitUpdater
|
||||
private pluginUpdaters:{[name in string]:GitUpdater} = {}
|
||||
@@ -32,8 +131,8 @@ export class UpdateManager extends Plugin<void>{
|
||||
super(admin, "UpdateManager")
|
||||
}
|
||||
|
||||
getDefaultConfig(): void {
|
||||
return
|
||||
getDefaultConfig(): {} {
|
||||
return {}
|
||||
}
|
||||
|
||||
exportRPCs(): socketioRPC[] {
|
||||
@@ -70,13 +169,23 @@ export class UpdateManager extends Plugin<void>{
|
||||
}]
|
||||
}
|
||||
|
||||
getTableDefinitions(): TableDefiniton[] {
|
||||
return []
|
||||
}
|
||||
|
||||
async updatePlatformDependencies(){
|
||||
|
||||
logger.info("installing npm stuff")
|
||||
|
||||
/*
|
||||
const res = await exec('npm install --prefix ./plugins knex sqlite3')
|
||||
logger.warn(res.stderr)
|
||||
logger.info(res.stdout)
|
||||
|
||||
*/
|
||||
await Promise.all([
|
||||
new NPMExtension("knex", "./plugins", "0.19.2").install(),
|
||||
new NPMExtension("sqlite3", "./plugins", "4.1.0").install()
|
||||
])
|
||||
}
|
||||
|
||||
async updateAdmin(force:boolean = false){
|
||||
@@ -104,11 +213,6 @@ export class UpdateManager extends Plugin<void>{
|
||||
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)
|
||||
return await this.pluginUpdaters[name].cloneRepo("https://gitea.frontblock.me/fb-dist/"+name.toLowerCase()+".git", force)
|
||||
}
|
||||
|
||||
async startPlugin(name:string):Promise<boolean>{
|
||||
if(!this.pluginUpdaters[name]) return false
|
||||
@@ -133,6 +237,7 @@ export class UpdateManager extends Plugin<void>{
|
||||
const pluginClass = await eval('require')(str)
|
||||
const pluginObj = new pluginClass.default()
|
||||
await pluginObj.start()
|
||||
this.admin.addPlugin(pluginObj)
|
||||
this.loadedPlugins[name] = pluginObj
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user