import { Plugin } from "./Plugin"
import { getLogger } from "frontblock-generic/Types"
import { FrontworkAdmin } from "./Admin";
var exec = require('child-process-promise').exec;

const logger = getLogger("installer", 'info') 

export type NPMPkgName = string
export type NPMVersion = string

export const installAdmin = (plugins: Plugin[] = []) => {
    
    const npmPkgs:[NPMPkgName, NPMVersion][] = [['sqlite3', '4.1.0'], ['knex', '0.19.2']]
    const deps = npmPkgs.map(tuple => tuple.join('@') ).join(" ")
    logger.info("Installing plaform dependencies: "+deps)

    exec("npm i " + deps).then(async process => {
        logger.debug(process.stdout)    
        const Admin = require("./Admin").FrontworkAdmin
        const fbAdmin:FrontworkAdmin = new Admin(plugins)
        fbAdmin.start()
    })

}