Browse Source

Merge branch 'master' of ssh://gitea.frontblock.me:2222/fb-vendor/admin

master
peter 2 years ago
parent
commit
9fbfca3ddb

+ 1
- 3
.drone.yml View File

@@ -37,15 +37,13 @@ steps:
37 37
   commands:
38 38
     - echo ${DRONE_BUILD_CREATED}
39 39
 
40
-- name: deploy static files
40
+- name: deploy Update
41 41
   image: node:12
42 42
   commands:
43 43
   - git config --global user.email "${DRONE_COMMIT_AUTHOR_EMAIL}"
44 44
   - git config --global user.name "${DRONE_COMMIT_AUTHOR}"
45 45
   - git clone https://gitea.frontblock.me/fb-dist/${DRONE_REPO_NAME}.git
46
-  - mv ./${DRONE_REPO_NAME}/.git ./bak
47 46
   - rm -rf ./${DRONE_REPO_NAME}/*
48
-  - mv ./bak ./${DRONE_REPO_NAME}/.git 
49 47
   - cp -r ./dist/* ./${DRONE_REPO_NAME}
50 48
   - cp -r ./static ./${DRONE_REPO_NAME}
51 49
   - ls ./${DRONE_REPO_NAME}

src/backend/FrontblockAdmin.ts → src/backend/Admin.ts View File

@@ -9,10 +9,11 @@ import http = require('http');
9 9
 import bsock = require('bsock');
10 10
 import { promises as fs } from "fs"
11 11
 import * as path from "path"
12
-import { UpdateManager } from './UpdateManger';
12
+import { install } from './Installer';
13 13
 import { FrontblockApi } from 'frontblock-generic/Api';
14 14
 import { Plugin } from 'frontblock-generic/Plugin';
15 15
 import { socketioRPC } from 'frontblock-generic/RPC';
16
+import { GitUpdater } from './GitUpdater';
16 17
 var exec = require('child-process-promise').exec;
17 18
 
18 19
 Logger.configure({
@@ -31,21 +32,12 @@ const logger = Logger.getLogger("admin")
31 32
 
32 33
 export type AdminConf = { httpPort: number}
33 34
 
34
-/**
35
- * FrontblockAdmin
36
- * 
37
- * The customer-facing dynamic component of the customer backend
38
- * Supports (un)loading plugins which will be communicated to its library component (See FrontblockLib.ts and the info() RPC)
39
- * 
40
- * The list of available plugins is published via the frontblock API and downloaded via gitea-releases
41
- */
42 35
 export class FrontblockAdmin extends AdminBase<AdminConf>{
43 36
    
44 37
     private express
45 38
     private httpServer
46 39
     private io = bsock.createServer()
47 40
     private wsServer = http.createServer()
48
-    private updateManager:UpdateManager = new UpdateManager(this)
49 41
 
50 42
     constructor(runningPlugins: Plugin[] = []){
51 43
         super(runningPlugins)
@@ -81,23 +73,39 @@ export class FrontblockAdmin extends AdminBase<AdminConf>{
81 73
         return this.apiClient    
82 74
     }
83 75
 
84
-    private async initialize(){
85
-        this.addPlugin(this.updateManager)
86
-        await this.updateManager.updateAdmin()
87
-        await this.updateManager.updateDashboard()
88
-        await this.updateManager.updateFrontblockLib()
76
+    private initialize(){
77
+        this.startWebserver()
78
+        this.startWebsocket()
79
+    }
89 80
 
81
+    private destroy(){
90 82
         this.startWebsocket()
91
-        this.startWebserver()
83
+        this.stopWebserver()
92 84
     }
93 85
 
94 86
     exportRPCs():socketioRPC[]{
95 87
         return [
96
-            ...[/* more RPC here */],
97
-            ...super.exportRPCs()
88
+            ...super.exportRPCs(),
89
+            {
90
+                name: 'selfUpdate',
91
+                type:'call',
92
+                func: async (force: boolean) => {return this.selfUpdate(force)},
93
+                visibility: 'private'
94
+            },
98 95
         ]
99 96
     }
100 97
 
98
+    private async selfUpdate(force:boolean = false){
99
+        const updater = new GitUpdater("./dist")
100
+        let status = await updater.getStatus()
101
+        if(force || !status.remote || !status.remote.includes("fb-dist/admin") || !status.exists || status.empty || !status.currentTag){
102
+            logger.warn("Cloning fb-dist/admin into ./dist ..."+(force?" USING FORCE!":""))
103
+            status = await updater.cloneRepo("https://gitea.frontblock.me/fb-dist/admin.git", force)
104
+            // TODO install()
105
+        }
106
+        return status
107
+    }
108
+
101 109
     private startWebserver(){
102 110
         if(this.httpServer != null || this.express != null){
103 111
             logger.warn("Webserver is already running")

+ 34
- 0
src/backend/Installer.ts View File

@@ -0,0 +1,34 @@
1
+import * as Logger from 'log4js'
2
+
3
+var exec = require('child-process-promise').exec;
4
+
5
+Logger.configure({
6
+    appenders: 
7
+    {
8
+    "installer": { type: 'stdout' },
9
+    //app: { type: 'file', filename: 'application.log' }
10
+    },
11
+    categories: 
12
+    {
13
+    default: { appenders: [ 'installer' ], level: 'debug' }
14
+    }
15
+})
16
+const logger = Logger.getLogger("installer") 
17
+
18
+export type NPMPkgName = string
19
+export type NPMVersion = string
20
+
21
+export const install = (plugins: Plugin[] = [], npmPkgs: [NPMPkgName, NPMVersion][] = []) => {
22
+    
23
+    logger.info("Checking npm dependencies...")
24
+    const deps = npmPkgs.map((pkg) => {return pkg[0] + '@' + pkg[1]} )
25
+    exec("npm i --prefix ./plugins " + deps.join(' ')).then(process => {
26
+    
27
+        logger.debug(process.stdout)    
28
+        const Admin = require("./Admin").FrontblockAdmin
29
+        new Admin(plugins)
30
+    })
31
+
32
+}
33
+
34
+install([], [['sqlite3', '4.1.0'], ['knex', '0.19.2']])

+ 0
- 25
src/backend/Main.ts View File

@@ -1,25 +0,0 @@
1
-import * as Logger from 'log4js'
2
-
3
-var exec = require('child-process-promise').exec;
4
-
5
-Logger.configure({
6
-    appenders: 
7
-    {
8
-    "main": { type: 'stdout' },
9
-    //app: { type: 'file', filename: 'application.log' }
10
-    },
11
-    categories: 
12
-    {
13
-    default: { appenders: [ 'main' ], level: 'debug' }
14
-    }
15
-})
16
-const logger = Logger.getLogger("main") 
17
-
18
-
19
-logger.info("Checking npm dependencies...")
20
-exec("npm i --prefix ./plugins knex@0.19.2 sqlite3@4.1.0").then(process => {
21
-    logger.debug(process.stdout)    
22
-    const Admin = require("./FrontblockAdmin").FrontblockAdmin
23
-    new Admin()
24
-})
25
-

+ 1
- 33
src/backend/UpdateManger.ts View File

@@ -3,7 +3,7 @@ import { socketioRPC } from "frontblock-generic/RPC";
3 3
 import { GitUpdater, RepoFolderStatus } from "./GitUpdater";
4 4
 import { FrontblockCherryPicker } from "git-cherrypicker";
5 5
 import * as Logger from 'log4js'
6
-import { FrontblockAdmin } from "./FrontblockAdmin";
6
+import { FrontblockAdmin } from "./Admin";
7 7
 import { TableDefiniton } from "frontblock-generic/Admin";
8 8
 
9 9
 Logger.configure({
@@ -55,11 +55,6 @@ export class UpdateManager extends Plugin{
55 55
             func: async (name, tag) => {return await this.setPluginVersion(name, tag)},
56 56
             type: 'call',
57 57
             visibility: 'private'
58
-        },{
59
-            name: 'updateDashboard',
60
-            func: async () => {return await this.updateDashboard()},
61
-            type: 'call',
62
-            visibility: 'private'
63 58
         },{
64 59
             name: 'getLoadedPluginNames',
65 60
             func: async () => {return await this.getLoadedPluginNames()},
@@ -79,33 +74,6 @@ export class UpdateManager extends Plugin{
79 74
         return status
80 75
     }
81 76
 
82
-
83
-    async updateAdmin(force:boolean = false){
84
-        this.adminUpdater = new GitUpdater("./dist")
85
-        let status = await this.adminUpdater.getStatus()
86
-        if(force || !status.remote || !status.remote.includes("fb-dist/admin") || !status.exists || status.empty || !status.currentTag){
87
-            logger.warn("Cloning fb-dist/admin into ./dist ..."+(force?" USING FORCE!":""))
88
-            status = await this.adminUpdater.cloneRepo("https://gitea.frontblock.me/fb-dist/admin.git", force)
89
-        }
90
-        return status
91
-    }
92
-
93
-    async updateFrontblockLib(){
94
-        logger.warn("Picking FrontblockLib...")
95
-        await (new FrontblockCherryPicker("fb-dist/admin", "master", "FrontblockLib.js")).write("./static/FrontblockLib.js")
96
-    }
97
-
98
-    async updateDashboard(force:boolean = false):Promise<RepoFolderStatus>{
99
-        this.dashboardUpdater = new GitUpdater("./static")
100
-        let status = await this.dashboardUpdater.getStatus()
101
-        if(force || !status.exists || status.empty || !status.currentTag){
102
-            logger.warn("Cloning fb-dist/dashboard into ./static ..."+(force?" USING FORCE!":""))
103
-            status = await this.dashboardUpdater.cloneRepo("https://gitea.frontblock.me/fb-dist/dashboard.git", force)
104
-        }
105
-        return status
106
-    }
107
-
108
-
109 77
     async startPlugin(name:string):Promise<boolean>{
110 78
         if(!this.pluginUpdaters[name]) return false
111 79
         const status = await this.pluginUpdaters[name].getStatus()

+ 1
- 1
src/backend/webpack.prod.js View File

@@ -38,7 +38,7 @@ module.exports = [{
38 38
   optimization: {
39 39
     minimize: false
40 40
   },
41
-  entry: path.resolve(__dirname, 'Main.ts'),
41
+  entry: path.resolve(__dirname, 'Installer.ts'),
42 42
   output: {
43 43
       path: path.resolve(__dirname, '../../dist'),
44 44
       filename: 'FrontblockAdmin.js',

+ 0
- 2685
testrepo/testfolder/package-lock.json
File diff suppressed because it is too large
View File


Loading…
Cancel
Save