no idea
This commit is contained in:
+1
-1
@@ -9,7 +9,7 @@
|
|||||||
"build-frontend": "npm run build-dashboard; npm run build-widget",
|
"build-frontend": "npm run build-dashboard; npm run build-widget",
|
||||||
"build-dashboard": "cd src/frontend/dashboard; npm i; npm run build; cp -r dist ../../../static",
|
"build-dashboard": "cd src/frontend/dashboard; npm i; npm run build; cp -r dist ../../../static",
|
||||||
"build-widget": "rollup -c src/frontend/widget/rollup.config.js",
|
"build-widget": "rollup -c src/frontend/widget/rollup.config.js",
|
||||||
"clean": "rm -rf lib static dist plugins widget .rpt2_cache *.js *.ts; rm -rf src/frontend/dashboard/dist",
|
"clean": "rm -rf lib static dist widget .rpt2_cache *.js *.ts; rm -rf src/frontend/dashboard/dist",
|
||||||
"update-frontblock": "rm -rf node_modules/frontblock*; npm install"
|
"update-frontblock": "rm -rf node_modules/frontblock*; npm install"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
@@ -16,13 +16,13 @@ Logger.configure({
|
|||||||
const logger = Logger.getLogger("PluginManager/Plugin")
|
const logger = Logger.getLogger("PluginManager/Plugin")
|
||||||
|
|
||||||
|
|
||||||
export class PluginManagerPlugin extends PluginManager implements Plugin{
|
export default class PluginManagerPlugin extends PluginManager implements Plugin{
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
constructor(){
|
constructor(){
|
||||||
super()
|
super()
|
||||||
|
|
||||||
this.loadedPlugins[this.name] = {backend:this, frontend: this.loadFrontend(this.name)}
|
this.installPlugin(this.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
exportRPCs(): import("frontblock-generic/Plugin").socketioRPC[] {
|
exportRPCs(): import("frontblock-generic/Plugin").socketioRPC[] {
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ export default class PluginManager extends ConfigLoader<PluginManagerConfig&Plug
|
|||||||
this.cacheDir = path.join(this.conf.installDir, '.cache')
|
this.cacheDir = path.join(this.conf.installDir, '.cache')
|
||||||
this.initialize()
|
this.initialize()
|
||||||
|
|
||||||
this.installPlugin("ApiClient")
|
//this.installPlugin("ApiClient")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,9 +59,9 @@ export default class PluginManager extends ConfigLoader<PluginManagerConfig&Plug
|
|||||||
logger.info('Initializing manager')
|
logger.info('Initializing manager')
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fs.access(this.cacheDir, async err => {
|
fs.access(this.cacheDir, err => {
|
||||||
if (err && err.code === 'ENOENT') {
|
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)
|
logger.info('Manager installed to ' + this.conf.installDir)
|
||||||
} else {
|
} else {
|
||||||
logger.info('Manager already installed at ' + this.conf.installDir)
|
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) {
|
private async downloadPlugin(pluginName: string) {
|
||||||
try {
|
try {
|
||||||
logger.info("Downloading Plugin")
|
logger.info("Downloading Plugin", pluginName)
|
||||||
|
if(pluginName === this.name) pluginName = "admin"
|
||||||
logger.error(this.conf.resourceLocation + pluginName + '/releases')
|
logger.error(this.conf.resourceLocation + pluginName + '/releases')
|
||||||
const response = await fetch(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()
|
const releases = await response.json()
|
||||||
if (!releases || !releases.length) throw new Error('Empty response')
|
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){
|
private async extractPlugin(pluginName: string){
|
||||||
fs
|
if(pluginName === this.name) pluginName = "admin"
|
||||||
.createReadStream(path.join(this.cacheDir, pluginName, "plugin.zip"))
|
const archivePath = path.join(this.cacheDir, pluginName, "plugin.zip")
|
||||||
.pipe(unzip.Extract({ path: path.join(this.conf.installDir,pluginName) }));
|
const outputPath = path.join(this.conf.installDir,pluginName)
|
||||||
|
await fs.createReadStream(archivePath).pipe(unzip.Extract({ path: outputPath }));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async installPlugin(pluginName: string) {
|
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()
|
return this.loadedPlugins[pluginName].frontend.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,7 +175,8 @@ export default class PluginManager extends ConfigLoader<PluginManagerConfig&Plug
|
|||||||
|
|
||||||
|
|
||||||
public async loadPlugin(pluginName:string) {
|
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")
|
logger.info("Loading plugin from fs", pth+"/Plugin")
|
||||||
const clazz = await import(pth+"/Plugin")
|
const clazz = await import(pth+"/Plugin")
|
||||||
let obj:Plugin = new clazz.default()
|
let obj:Plugin = new clazz.default()
|
||||||
@@ -183,7 +185,7 @@ export default class PluginManager extends ConfigLoader<PluginManagerConfig&Plug
|
|||||||
}
|
}
|
||||||
|
|
||||||
public loadFrontend(pluginName:string){
|
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"))
|
logger.info("Loading frontend plugin from fs", path.join(__dirname,pth,"FrontendPlugin.js"))
|
||||||
return fs.readFileSync(path.join(__dirname, pth,"FrontendPlugin.js"))
|
return fs.readFileSync(path.join(__dirname, pth,"FrontendPlugin.js"))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ const path = require('path');
|
|||||||
|
|
||||||
const FrontblockLib = {
|
const FrontblockLib = {
|
||||||
mode: 'production',
|
mode: 'production',
|
||||||
entry: path.resolve(__dirname, '../../../lib/FrontblockLib.js'),
|
entry: path.resolve(__dirname, '../../lib/FrontblockLib.js'),
|
||||||
output: {
|
output: {
|
||||||
path: path.resolve(__dirname, '../../../static'),
|
path: path.resolve(__dirname, '../../../static'),
|
||||||
filename: 'FrontblockLib.js',
|
filename: 'FrontblockLib.js',
|
||||||
|
|||||||
Reference in New Issue
Block a user