This commit is contained in:
peter
2019-08-03 21:28:52 +02:00
parent dc4764ade9
commit 494fab5324
4 changed files with 19 additions and 17 deletions
+2 -2
View File
@@ -16,13 +16,13 @@ Logger.configure({
const logger = Logger.getLogger("PluginManager/Plugin")
export class PluginManagerPlugin extends PluginManager implements Plugin{
export default class PluginManagerPlugin extends PluginManager implements Plugin{
name: string;
constructor(){
super()
this.loadedPlugins[this.name] = {backend:this, frontend: this.loadFrontend(this.name)}
this.installPlugin(this.name)
}
exportRPCs(): import("frontblock-generic/Plugin").socketioRPC[] {
+15 -13
View File
@@ -46,7 +46,7 @@ export default class PluginManager extends ConfigLoader<PluginManagerConfig&Plug
this.cacheDir = path.join(this.conf.installDir, '.cache')
this.initialize()
this.installPlugin("ApiClient")
//this.installPlugin("ApiClient")
}
@@ -59,9 +59,9 @@ export default class PluginManager extends ConfigLoader<PluginManagerConfig&Plug
logger.info('Initializing manager')
try {
fs.access(this.cacheDir, async err => {
fs.access(this.cacheDir, err => {
if (err && err.code === 'ENOENT') {
await fs.promises.mkdir(this.cacheDir, {recursive: true})
fs.mkdirSync(this.cacheDir, {recursive: true})
logger.info('Manager installed to ' + this.conf.installDir)
} else {
logger.info('Manager already installed at ' + this.conf.installDir)
@@ -117,11 +117,11 @@ export default class PluginManager extends ConfigLoader<PluginManagerConfig&Plug
private async downloadPlugin(pluginName: string) {
try {
logger.info("Downloading Plugin")
logger.info("Downloading Plugin", pluginName)
if(pluginName === this.name) pluginName = "admin"
logger.error(this.conf.resourceLocation + pluginName + '/releases')
const response = await fetch(this.conf.resourceLocation + pluginName + '/releases')
if (!response.ok) throw new Error(response.statusText)
if (!response.ok) throw new Error(pluginName+": "+response.statusText)
const releases = await response.json()
if (!releases || !releases.length) throw new Error('Empty response')
@@ -146,10 +146,11 @@ export default class PluginManager extends ConfigLoader<PluginManagerConfig&Plug
}
}
private extractPlugin(pluginName: string){
fs
.createReadStream(path.join(this.cacheDir, pluginName, "plugin.zip"))
.pipe(unzip.Extract({ path: path.join(this.conf.installDir,pluginName) }));
private async extractPlugin(pluginName: string){
if(pluginName === this.name) pluginName = "admin"
const archivePath = path.join(this.cacheDir, pluginName, "plugin.zip")
const outputPath = path.join(this.conf.installDir,pluginName)
await fs.createReadStream(archivePath).pipe(unzip.Extract({ path: outputPath }));
}
public async installPlugin(pluginName: string) {
@@ -162,7 +163,7 @@ export default class PluginManager extends ConfigLoader<PluginManagerConfig&Plug
}
}
public getFrontend(pluginName: string){
public getFrontend(pluginName: string):string{
return this.loadedPlugins[pluginName].frontend.toString()
}
@@ -174,7 +175,8 @@ export default class PluginManager extends ConfigLoader<PluginManagerConfig&Plug
public async loadPlugin(pluginName:string) {
const pth = path.join("..", "..", this.conf.installDir, pluginName, "static")
if(pluginName === this.name) pluginName = "admin"
const pth = path.join("..", "..", this.conf.installDir, pluginName)
logger.info("Loading plugin from fs", pth+"/Plugin")
const clazz = await import(pth+"/Plugin")
let obj:Plugin = new clazz.default()
@@ -183,7 +185,7 @@ export default class PluginManager extends ConfigLoader<PluginManagerConfig&Plug
}
public loadFrontend(pluginName:string){
const pth = path.join("..", "..", this.conf.installDir, pluginName, "static")
const pth = path.join("..", "..", this.conf.installDir, pluginName)
logger.info("Loading frontend plugin from fs", path.join(__dirname,pth,"FrontendPlugin.js"))
return fs.readFileSync(path.join(__dirname, pth,"FrontendPlugin.js"))
}
+1 -1
View File
@@ -5,7 +5,7 @@ const path = require('path');
const FrontblockLib = {
mode: 'production',
entry: path.resolve(__dirname, '../../../lib/FrontblockLib.js'),
entry: path.resolve(__dirname, '../../lib/FrontblockLib.js'),
output: {
path: path.resolve(__dirname, '../../../static'),
filename: 'FrontblockLib.js',