From bf7fd25e5c4368539642615553ae5c49daa80368 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 26 Aug 2019 20:21:27 +0200 Subject: [PATCH] types --- src/backend/UpdateManger.ts | 41 ++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/src/backend/UpdateManger.ts b/src/backend/UpdateManger.ts index 32870e4..da6869b 100644 --- a/src/backend/UpdateManger.ts +++ b/src/backend/UpdateManger.ts @@ -23,31 +23,40 @@ Logger.configure({ }) const logger = Logger.getLogger("admin/updatemanager") -abstract class Extension{ +type SuccessType = { success: boolean } +type OutdatedType = { outdated: boolean } + + +abstract class Extension{ constructor( public name: string, - public version: string, ){} - abstract install():Promise - abstract uninstall():Promise - abstract update():Promise - abstract isOutdated():Promise + abstract getStatus:Promise + abstract install():Promise + abstract uninstall():Promise + abstract update():Promise + abstract isOutdated():Promise } -export class NPMExtension extends Extension{ +type NpmExtensionInformation = { + version: string, + name: string, + location: string, +} + +export class NPMExtension extends Extension{ constructor( name, - version = "latest", public localPrefix, ){ - super(name, version) + super(name) } - public async install(): Promise { + public async install(): Promise { logger.info("npm install", this.name, 'to', path.resolve(this.localPrefix, this.name)) await fs.mkdir(this.localPrefix, {recursive: true}) - const { error, stdout, stderr } = await exec('npm install --prefix '+ this.localPrefix + ' ' + this.name+"@"+this.version) + const { error, stdout, stderr } = await exec('npm install --prefix '+ this.localPrefix + ' ' + this.name) if (error !== null) { logger.warn('npm install', this.name, 'from prefix', this.localPrefix, 'stderr:', stderr) return false @@ -57,7 +66,7 @@ export class NPMExtension extends Extension{ } } - public async uninstall(): Promise { + public async uninstall(): Promise { logger.info("npm uninstall", this.name, 'from', path.resolve(this.localPrefix, this.name)) const { error, stdout, stderr } = await exec('npm uninstall --prefix '+ this.localPrefix + ' ' + this.name) if (error !== null) { @@ -69,7 +78,7 @@ export class NPMExtension extends Extension{ } } - public async update(): Promise { + public async update(): Promise { logger.info("npm update", path.resolve(this.localPrefix, this.name)) const { error, stdout, stderr } = await exec('npm update --prefix '+ this.localPrefix + ' ' + this.name) if (error !== null) { @@ -81,7 +90,7 @@ export class NPMExtension extends Extension{ } } - public async isOutdated(): Promise { + public async isOutdated(): Promise { logger.info("npm outdated", path.resolve(this.localPrefix, this.name)) const { error, stdout, stderr } = await exec('npm list --prefix '+ this.localPrefix + ' --depth=0 | grep ' + this.name) if (error !== null) { @@ -183,8 +192,8 @@ export class UpdateManager extends Plugin{ logger.info(res.stdout) */ await Promise.all([ - new NPMExtension("knex", "./plugins", "0.19.2").install(), - new NPMExtension("sqlite3", "./plugins", "4.1.0").install() + new NPMExtension("knex@0.19.2", "./plugins").install(), + new NPMExtension("sqlite3@4.1.0", "./plugins").install() ]) }