extension stuff
This commit is contained in:
+65
-27
@@ -23,29 +23,55 @@ Logger.configure({
|
||||
})
|
||||
const logger = Logger.getLogger("admin/updatemanager")
|
||||
|
||||
type SuccessType = { success: boolean }
|
||||
type OutdatedType = { outdated: boolean }
|
||||
|
||||
|
||||
abstract class Extension<StatusType>{
|
||||
abstract class Extension<Status>{
|
||||
constructor(
|
||||
public name: string,
|
||||
){}
|
||||
|
||||
abstract getStatus:Promise<StatusType>
|
||||
abstract install():Promise<StatusType & SuccessType>
|
||||
abstract uninstall():Promise<StatusType & SuccessType>
|
||||
abstract update():Promise<StatusType & SuccessType>
|
||||
abstract isOutdated():Promise<OutdatedType & SuccessType>
|
||||
/**
|
||||
* promises the generic Status object
|
||||
*/
|
||||
abstract status():Promise<Status>
|
||||
/**
|
||||
* promises a boolean.
|
||||
* true => isInstalled should be true afterwards
|
||||
* false => an error happend and nothing was installed
|
||||
*/
|
||||
abstract install():Promise<boolean>
|
||||
/**
|
||||
* 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<boolean>
|
||||
|
||||
/**
|
||||
* promises a boolean.
|
||||
* true => an update was performed
|
||||
* false => no update was performed
|
||||
*/
|
||||
abstract async update(): Promise<boolean>
|
||||
|
||||
/**
|
||||
* promises a boolean
|
||||
* true => update would install a newer version
|
||||
* false => nothing would happen if update would be called
|
||||
*/
|
||||
abstract async isOutdated():Promise<boolean>
|
||||
|
||||
/**
|
||||
* 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<boolean>
|
||||
}
|
||||
|
||||
type NpmExtensionInformation = {
|
||||
version: string,
|
||||
name: string,
|
||||
location: string,
|
||||
}
|
||||
export class NPMExtension extends Extension<NPMExtensionStatus>{
|
||||
|
||||
|
||||
|
||||
export class NPMExtension extends Extension<NpmExtensionInformation>{
|
||||
constructor(
|
||||
name,
|
||||
public localPrefix,
|
||||
@@ -53,7 +79,11 @@ export class NPMExtension extends Extension<NpmExtensionInformation>{
|
||||
super(name)
|
||||
}
|
||||
|
||||
public async install(): Promise<NpmExtensionInformation & SuccessType> {
|
||||
status(): Promise<any> {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
|
||||
public async install(): Promise<boolean> {
|
||||
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<NpmExtensionInformation>{
|
||||
}
|
||||
}
|
||||
|
||||
public async uninstall(): Promise<NpmExtensionInformation & SuccessType> {
|
||||
public async uninstall(): Promise<boolean> {
|
||||
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<NpmExtensionInformation>{
|
||||
}
|
||||
}
|
||||
|
||||
public async update(): Promise<NpmExtensionInformation & SuccessType> {
|
||||
public async update(): Promise<boolean> {
|
||||
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<NpmExtensionInformation>{
|
||||
}
|
||||
}
|
||||
|
||||
public async isOutdated(): Promise<NpmExtensionInformation & SuccessType> {
|
||||
public async isOutdated(): Promise<boolean> {
|
||||
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<NpmExtensionInformation>{
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
isInstalled(): Promise<boolean> {
|
||||
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<GitExtensionState>{
|
||||
constructor(
|
||||
name:string,
|
||||
version = "latest",
|
||||
@@ -112,20 +150,20 @@ export class GitExtension extends Extension{
|
||||
super(name, version)
|
||||
}
|
||||
|
||||
public async install(): Promise<boolean> {
|
||||
|
||||
public async install(): Promise<GitExtensionState> {
|
||||
return 'unknown'
|
||||
}
|
||||
|
||||
public async uninstall(): Promise<boolean> {
|
||||
|
||||
public async uninstall(): Promise<GitExtensionState> {
|
||||
return 'unknown'
|
||||
}
|
||||
|
||||
public async update(): Promise<boolean> {
|
||||
|
||||
public async update(): Promise<GitExtensionState> {
|
||||
return 'unknown'
|
||||
}
|
||||
|
||||
public async isOutdated(): Promise<boolean> {
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user