where to call install with what
This commit is contained in:
@@ -9,10 +9,11 @@ import http = require('http');
|
|||||||
import bsock = require('bsock');
|
import bsock = require('bsock');
|
||||||
import { promises as fs } from "fs"
|
import { promises as fs } from "fs"
|
||||||
import * as path from "path"
|
import * as path from "path"
|
||||||
import { UpdateManager } from './UpdateManger';
|
import { install } from './Installer';
|
||||||
import { FrontblockApi } from 'frontblock-generic/Api';
|
import { FrontblockApi } from 'frontblock-generic/Api';
|
||||||
import { Plugin } from 'frontblock-generic/Plugin';
|
import { Plugin } from 'frontblock-generic/Plugin';
|
||||||
import { socketioRPC } from 'frontblock-generic/RPC';
|
import { socketioRPC } from 'frontblock-generic/RPC';
|
||||||
|
import { GitUpdater } from './GitUpdater';
|
||||||
var exec = require('child-process-promise').exec;
|
var exec = require('child-process-promise').exec;
|
||||||
|
|
||||||
Logger.configure({
|
Logger.configure({
|
||||||
@@ -31,21 +32,12 @@ const logger = Logger.getLogger("admin")
|
|||||||
|
|
||||||
export type AdminConf = { httpPort: number}
|
export type AdminConf = { httpPort: number}
|
||||||
|
|
||||||
/**
|
|
||||||
* FrontblockAdmin
|
|
||||||
*
|
|
||||||
* The customer-facing dynamic component of the customer backend
|
|
||||||
* Supports (un)loading plugins which will be communicated to its library component (See FrontblockLib.ts and the info() RPC)
|
|
||||||
*
|
|
||||||
* The list of available plugins is published via the frontblock API and downloaded via gitea-releases
|
|
||||||
*/
|
|
||||||
export class FrontblockAdmin extends AdminBase<AdminConf>{
|
export class FrontblockAdmin extends AdminBase<AdminConf>{
|
||||||
|
|
||||||
private express
|
private express
|
||||||
private httpServer
|
private httpServer
|
||||||
private io = bsock.createServer()
|
private io = bsock.createServer()
|
||||||
private wsServer = http.createServer()
|
private wsServer = http.createServer()
|
||||||
private updateManager:UpdateManager = new UpdateManager(this)
|
|
||||||
|
|
||||||
constructor(runningPlugins: Plugin[] = []){
|
constructor(runningPlugins: Plugin[] = []){
|
||||||
super(runningPlugins)
|
super(runningPlugins)
|
||||||
@@ -81,23 +73,39 @@ export class FrontblockAdmin extends AdminBase<AdminConf>{
|
|||||||
return this.apiClient
|
return this.apiClient
|
||||||
}
|
}
|
||||||
|
|
||||||
private async initialize(){
|
private initialize(){
|
||||||
this.addPlugin(this.updateManager)
|
|
||||||
await this.updateManager.updateAdmin()
|
|
||||||
await this.updateManager.updateDashboard()
|
|
||||||
await this.updateManager.updateFrontblockLib()
|
|
||||||
|
|
||||||
this.startWebsocket()
|
|
||||||
this.startWebserver()
|
this.startWebserver()
|
||||||
|
this.startWebsocket()
|
||||||
|
}
|
||||||
|
|
||||||
|
private destroy(){
|
||||||
|
this.startWebsocket()
|
||||||
|
this.stopWebserver()
|
||||||
}
|
}
|
||||||
|
|
||||||
exportRPCs():socketioRPC[]{
|
exportRPCs():socketioRPC[]{
|
||||||
return [
|
return [
|
||||||
...[/* more RPC here */],
|
...super.exportRPCs(),
|
||||||
...super.exportRPCs()
|
{
|
||||||
|
name: 'selfUpdate',
|
||||||
|
type:'call',
|
||||||
|
func: async (force: boolean) => {return this.selfUpdate(force)},
|
||||||
|
visibility: 'private'
|
||||||
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async selfUpdate(force:boolean = false){
|
||||||
|
const updater = new GitUpdater("./dist")
|
||||||
|
let status = await updater.getStatus()
|
||||||
|
if(force || !status.remote || !status.remote.includes("fb-dist/admin") || !status.exists || status.empty || !status.currentTag){
|
||||||
|
logger.warn("Cloning fb-dist/admin into ./dist ..."+(force?" USING FORCE!":""))
|
||||||
|
status = await updater.cloneRepo("https://gitea.frontblock.me/fb-dist/admin.git", force)
|
||||||
|
// TODO install()
|
||||||
|
}
|
||||||
|
return status
|
||||||
|
}
|
||||||
|
|
||||||
private startWebserver(){
|
private startWebserver(){
|
||||||
if(this.httpServer != null || this.express != null){
|
if(this.httpServer != null || this.express != null){
|
||||||
logger.warn("Webserver is already running")
|
logger.warn("Webserver is already running")
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import * as Logger from 'log4js'
|
||||||
|
|
||||||
|
var exec = require('child-process-promise').exec;
|
||||||
|
|
||||||
|
Logger.configure({
|
||||||
|
appenders:
|
||||||
|
{
|
||||||
|
"installer": { type: 'stdout' },
|
||||||
|
//app: { type: 'file', filename: 'application.log' }
|
||||||
|
},
|
||||||
|
categories:
|
||||||
|
{
|
||||||
|
default: { appenders: [ 'installer' ], level: 'debug' }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
const logger = Logger.getLogger("installer")
|
||||||
|
|
||||||
|
export type NPMPkgName = string
|
||||||
|
export type NPMVersion = string
|
||||||
|
|
||||||
|
export const install = (plugins: Plugin[] = [], npmPkgs: [NPMPkgName, NPMVersion][] = []) => {
|
||||||
|
|
||||||
|
logger.info("Checking npm dependencies...")
|
||||||
|
const deps = npmPkgs.map((pkg) => {return pkg[0] + '@' + pkg[1]} )
|
||||||
|
exec("npm i --prefix ./plugins " + deps.join(' ')).then(process => {
|
||||||
|
|
||||||
|
logger.debug(process.stdout)
|
||||||
|
const Admin = require("./Admin").FrontblockAdmin
|
||||||
|
new Admin(plugins)
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
install([], [['sqlite3', '4.1.0'], ['knex', '0.19.2']])
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
import * as Logger from 'log4js'
|
|
||||||
|
|
||||||
var exec = require('child-process-promise').exec;
|
|
||||||
|
|
||||||
Logger.configure({
|
|
||||||
appenders:
|
|
||||||
{
|
|
||||||
"main": { type: 'stdout' },
|
|
||||||
//app: { type: 'file', filename: 'application.log' }
|
|
||||||
},
|
|
||||||
categories:
|
|
||||||
{
|
|
||||||
default: { appenders: [ 'main' ], level: 'debug' }
|
|
||||||
}
|
|
||||||
})
|
|
||||||
const logger = Logger.getLogger("main")
|
|
||||||
|
|
||||||
|
|
||||||
logger.info("Checking npm dependencies...")
|
|
||||||
exec("npm i --prefix ./plugins knex@0.19.2 sqlite3@4.1.0").then(process => {
|
|
||||||
logger.debug(process.stdout)
|
|
||||||
const Admin = require("./FrontblockAdmin").FrontblockAdmin
|
|
||||||
new Admin()
|
|
||||||
})
|
|
||||||
|
|
||||||
@@ -3,7 +3,7 @@ import { socketioRPC } from "frontblock-generic/RPC";
|
|||||||
import { GitUpdater, RepoFolderStatus } from "./GitUpdater";
|
import { GitUpdater, RepoFolderStatus } from "./GitUpdater";
|
||||||
import { FrontblockCherryPicker } from "git-cherrypicker";
|
import { FrontblockCherryPicker } from "git-cherrypicker";
|
||||||
import * as Logger from 'log4js'
|
import * as Logger from 'log4js'
|
||||||
import { FrontblockAdmin } from "./FrontblockAdmin";
|
import { FrontblockAdmin } from "./Admin";
|
||||||
import { TableDefiniton } from "frontblock-generic/Admin";
|
import { TableDefiniton } from "frontblock-generic/Admin";
|
||||||
|
|
||||||
Logger.configure({
|
Logger.configure({
|
||||||
@@ -55,11 +55,6 @@ export class UpdateManager extends Plugin{
|
|||||||
func: async (name, tag) => {return await this.setPluginVersion(name, tag)},
|
func: async (name, tag) => {return await this.setPluginVersion(name, tag)},
|
||||||
type: 'call',
|
type: 'call',
|
||||||
visibility: 'private'
|
visibility: 'private'
|
||||||
},{
|
|
||||||
name: 'updateDashboard',
|
|
||||||
func: async () => {return await this.updateDashboard()},
|
|
||||||
type: 'call',
|
|
||||||
visibility: 'private'
|
|
||||||
},{
|
},{
|
||||||
name: 'getLoadedPluginNames',
|
name: 'getLoadedPluginNames',
|
||||||
func: async () => {return await this.getLoadedPluginNames()},
|
func: async () => {return await this.getLoadedPluginNames()},
|
||||||
@@ -79,33 +74,6 @@ export class UpdateManager extends Plugin{
|
|||||||
return status
|
return status
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async updateAdmin(force:boolean = false){
|
|
||||||
this.adminUpdater = new GitUpdater("./dist")
|
|
||||||
let status = await this.adminUpdater.getStatus()
|
|
||||||
if(force || !status.remote || !status.remote.includes("fb-dist/admin") || !status.exists || status.empty || !status.currentTag){
|
|
||||||
logger.warn("Cloning fb-dist/admin into ./dist ..."+(force?" USING FORCE!":""))
|
|
||||||
status = await this.adminUpdater.cloneRepo("https://gitea.frontblock.me/fb-dist/admin.git", force)
|
|
||||||
}
|
|
||||||
return status
|
|
||||||
}
|
|
||||||
|
|
||||||
async updateFrontblockLib(){
|
|
||||||
logger.warn("Picking FrontblockLib...")
|
|
||||||
await (new FrontblockCherryPicker("fb-dist/admin", "master", "FrontblockLib.js")).write("./static/FrontblockLib.js")
|
|
||||||
}
|
|
||||||
|
|
||||||
async updateDashboard(force:boolean = false):Promise<RepoFolderStatus>{
|
|
||||||
this.dashboardUpdater = new GitUpdater("./static")
|
|
||||||
let status = await this.dashboardUpdater.getStatus()
|
|
||||||
if(force || !status.exists || status.empty || !status.currentTag){
|
|
||||||
logger.warn("Cloning fb-dist/dashboard into ./static ..."+(force?" USING FORCE!":""))
|
|
||||||
status = await this.dashboardUpdater.cloneRepo("https://gitea.frontblock.me/fb-dist/dashboard.git", force)
|
|
||||||
}
|
|
||||||
return status
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async startPlugin(name:string):Promise<boolean>{
|
async startPlugin(name:string):Promise<boolean>{
|
||||||
if(!this.pluginUpdaters[name]) return false
|
if(!this.pluginUpdaters[name]) return false
|
||||||
const status = await this.pluginUpdaters[name].getStatus()
|
const status = await this.pluginUpdaters[name].getStatus()
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ module.exports = [{
|
|||||||
optimization: {
|
optimization: {
|
||||||
minimize: false
|
minimize: false
|
||||||
},
|
},
|
||||||
entry: path.resolve(__dirname, 'Main.ts'),
|
entry: path.resolve(__dirname, 'Installer.ts'),
|
||||||
output: {
|
output: {
|
||||||
path: path.resolve(__dirname, '../../dist'),
|
path: path.resolve(__dirname, '../../dist'),
|
||||||
filename: 'FrontblockAdmin.js',
|
filename: 'FrontblockAdmin.js',
|
||||||
|
|||||||
Generated
-2685
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user