Browse Source

install() -> installAdmin()

master
Daniel Huebleitner 2 years ago
parent
commit
26a8400ab1
3 changed files with 30 additions and 13 deletions
  1. 1
    1
      src/backend/Admin.ts
  2. 27
    10
      src/backend/Installer.ts
  3. 2
    2
      src/backend/Launcher.ts

+ 1
- 1
src/backend/Admin.ts View File

@@ -107,7 +107,7 @@ export class FrontblockAdmin extends AdminBase<AdminConf>{
107 107
             status = await updater.cloneRepo("https://gitea.frontblock.me/fb-dist/admin.git", force)
108 108
 
109 109
             this.destroy()
110
-            const installer = require("./Installer").install
110
+            const installer = require("./Installer").installAdmin
111 111
             installer(this.getPlugins())
112 112
         }
113 113
         return status

+ 27
- 10
src/backend/Installer.ts View File

@@ -19,17 +19,34 @@ const logger = Logger.getLogger("installer")
19 19
 export type NPMPkgName = string
20 20
 export type NPMVersion = string
21 21
 
22
-export const install = (plugins: Plugin[] = []) => {
23
-    
24
-    const npmPkgs:[NPMPkgName, NPMVersion][] = [['sqlite3', '4.1.0'], ['knex', '0.19.2']]
22
+export const defaultNodePkgs = ():[NPMPkgName, NPMVersion][] => {
23
+    return [
24
+        ['sqlite3', '4.1.0'], 
25
+        ['knex', '0.19.2']
26
+    ]
27
+}
28
+
29
+export const npmInstall = (prefix: string = './plugins') => async (npmPkgs: [NPMPkgName, NPMVersion][]) => {
25 30
     const deps = npmPkgs.map(tuple => tuple.join('@') ).join(" ")
26
-    logger.info("Installing plaform dependencies: "+deps)
31
+    logger.info('npm install --prefix', prefix, deps)
32
+
33
+    const { error, stdout, stderr } = await exec('npm i --prefix ' + prefix + ' ' + deps)
34
+
35
+    if (error) throw new Error(stderr)
36
+    else logger.info(stdout)
37
+}
27 38
 
28
-    exec("npm i --prefix ./plugins " + deps).then(process => {
29
-    
30
-        logger.debug(process.stdout)    
31
-        const Admin = require("./Admin").FrontblockAdmin
32
-        new Admin(plugins)
33
-    })
39
+export const installAdmin = async (plugins: Plugin[] = []) => {
40
+    logger.debug('Installing Admin')
41
+
42
+    try {
43
+        await npmInstall()(defaultNodePkgs())
44
+        logger.info('Installed node dependencies')
45
+    } catch (error) {
46
+        logger.fatal('Unable to install node dependencies: ', error)
47
+        process.exit(1);
48
+    }
34 49
 
50
+    const Admin = require("./Admin").FrontblockAdmin
51
+    new Admin(plugins)
35 52
 }

+ 2
- 2
src/backend/Launcher.ts View File

@@ -1,2 +1,2 @@
1
-import { install } from "./Installer";
2
-install([])
1
+import { installAdmin } from "./Installer";
2
+installAdmin([])

Loading…
Cancel
Save