From 7acd853745975d6f0009287d75f3f9f38f37e19d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20H=C3=BCbleitner?= Date: Mon, 26 Aug 2019 21:14:57 +0200 Subject: [PATCH] extension stuff --- src/backend/UpdateManger.ts | 92 ++++++++++++++++++++++++++----------- 1 file changed, 65 insertions(+), 27 deletions(-) diff --git a/src/backend/UpdateManger.ts b/src/backend/UpdateManger.ts index da6869b..d4aac52 100644 --- a/src/backend/UpdateManger.ts +++ b/src/backend/UpdateManger.ts @@ -23,29 +23,55 @@ Logger.configure({ }) const logger = Logger.getLogger("admin/updatemanager") -type SuccessType = { success: boolean } -type OutdatedType = { outdated: boolean } - -abstract class Extension{ +abstract class Extension{ constructor( public name: string, ){} - abstract getStatus:Promise - abstract install():Promise - abstract uninstall():Promise - abstract update():Promise - abstract isOutdated():Promise + /** + * promises the generic Status object + */ + abstract status():Promise + /** + * promises a boolean. + * true => isInstalled should be true afterwards + * false => an error happend and nothing was installed + */ + abstract install():Promise + /** + * promises a boolean. + * true => isInstalled should be false afterwards + * false => the function was not able to bring this plugin into an uninstalled state!!! + */ + abstract uninstall():Promise + + /** + * promises a boolean. + * true => an update was performed + * false => no update was performed + */ + abstract async update(): Promise + + /** + * promises a boolean + * true => update would install a newer version + * false => nothing would happen if update would be called + */ + abstract async isOutdated():Promise + + /** + * promises a boolean + * true => install would do nothing would it be called + * false => install would try to install the newest extension + */ + abstract async isInstalled():Promise } -type NpmExtensionInformation = { - version: string, - name: string, - location: string, -} +export class NPMExtension extends Extension{ + + -export class NPMExtension extends Extension{ constructor( name, public localPrefix, @@ -53,7 +79,11 @@ export class NPMExtension extends Extension{ super(name) } - public async install(): Promise { + status(): Promise { + throw new Error("Method not implemented."); + } + + 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) @@ -66,7 +96,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) { @@ -78,7 +108,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) { @@ -90,7 +120,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) { @@ -101,9 +131,17 @@ export class NPMExtension extends Extension{ return true } } + + isInstalled(): Promise { + throw new Error("Method not implemented."); + } + } -export class GitExtension extends Extension{ +export type GitRef = string +export type GitExtensionState = UnknownState | GitRef + +export class GitExtension extends Extension{ constructor( name:string, version = "latest", @@ -112,20 +150,20 @@ export class GitExtension extends Extension{ super(name, version) } - public async install(): Promise { - + public async install(): Promise { + return 'unknown' } - public async uninstall(): Promise { - + public async uninstall(): Promise { + return 'unknown' } - public async update(): Promise { - + public async update(): Promise { + return 'unknown' } public async isOutdated(): Promise { - + return true } }