types
This commit is contained in:
+25
-16
@@ -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<StatusType>{
|
||||
constructor(
|
||||
public name: string,
|
||||
public version: string,
|
||||
){}
|
||||
|
||||
abstract install():Promise<boolean>
|
||||
abstract uninstall():Promise<boolean>
|
||||
abstract update():Promise<boolean>
|
||||
abstract isOutdated():Promise<boolean>
|
||||
abstract getStatus:Promise<StatusType>
|
||||
abstract install():Promise<StatusType & SuccessType>
|
||||
abstract uninstall():Promise<StatusType & SuccessType>
|
||||
abstract update():Promise<StatusType & SuccessType>
|
||||
abstract isOutdated():Promise<OutdatedType & SuccessType>
|
||||
}
|
||||
|
||||
export class NPMExtension extends Extension{
|
||||
type NpmExtensionInformation = {
|
||||
version: string,
|
||||
name: string,
|
||||
location: string,
|
||||
}
|
||||
|
||||
export class NPMExtension extends Extension<NpmExtensionInformation>{
|
||||
constructor(
|
||||
name,
|
||||
version = "latest",
|
||||
public localPrefix,
|
||||
){
|
||||
super(name, version)
|
||||
super(name)
|
||||
}
|
||||
|
||||
public async install(): Promise<boolean> {
|
||||
public async install(): Promise<NpmExtensionInformation & SuccessType> {
|
||||
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<boolean> {
|
||||
public async uninstall(): Promise<NpmExtensionInformation & SuccessType> {
|
||||
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<boolean> {
|
||||
public async update(): Promise<NpmExtensionInformation & SuccessType> {
|
||||
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<boolean> {
|
||||
public async isOutdated(): Promise<NpmExtensionInformation & SuccessType> {
|
||||
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()
|
||||
])
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user