now its time for me
This commit is contained in:
+75
-13
@@ -11,6 +11,7 @@ import { promises as fs, mkdirSync as mkdir } from "fs"
|
||||
import { version } from "punycode";
|
||||
import * as git from "simple-git/promise"
|
||||
import * as trash from "trash"
|
||||
import { type } from "os";
|
||||
|
||||
var exec = require('child-process-promise').exec;
|
||||
|
||||
@@ -134,6 +135,11 @@ export abstract class FSExtension<Status extends FSStatus> extends Extension<Sta
|
||||
return await trash(path.resolve(this.prefix, this.name))
|
||||
}
|
||||
|
||||
public async update(force?: boolean): Promise<boolean | undefined>{
|
||||
if (force) await this.uninstall()
|
||||
return await this.install()
|
||||
}
|
||||
|
||||
public async isEmpty(): Promise<boolean | undefined>{
|
||||
if (!this.isInstalled()) return true
|
||||
try {
|
||||
@@ -157,27 +163,29 @@ export abstract class FSExtension<Status extends FSStatus> extends Extension<Sta
|
||||
|
||||
type NPMStatus = FSStatus & {
|
||||
latest?: string,
|
||||
current?: string, // TODO
|
||||
current?: string,
|
||||
author?: string
|
||||
}
|
||||
|
||||
export class NPMExtension extends FSExtension<NPMStatus>{
|
||||
|
||||
constructor(
|
||||
name: string,
|
||||
pkgName: string,
|
||||
prefix: string){
|
||||
super(name, prefix)
|
||||
super(pkgName, prefix)
|
||||
}
|
||||
|
||||
public async status(): Promise<NPMStatus> {
|
||||
|
||||
const fsStatus = await super.status()
|
||||
const latest = await this.getLatest()
|
||||
const latest = await this.getLatestVersion()
|
||||
const author = await this.getAuthor()
|
||||
const current = await this.getCurrentVersion()
|
||||
return {
|
||||
...fsStatus,
|
||||
latest: latest,
|
||||
author: author
|
||||
author: author,
|
||||
current: current
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,7 +202,7 @@ export class NPMExtension extends FSExtension<NPMStatus>{
|
||||
}
|
||||
}
|
||||
|
||||
public async uninstall(): Promise<void> {
|
||||
public async uninstall(force?: boolean): Promise<void> {
|
||||
super.uninstall()
|
||||
logger.info("npm uninstall", this.name, 'from', path.resolve(this.prefix, this.name))
|
||||
const { error, stdout, stderr } = await exec('npm uninstall --prefix '+ this.prefix + ' ' + this.name)
|
||||
@@ -205,7 +213,8 @@ export class NPMExtension extends FSExtension<NPMStatus>{
|
||||
}
|
||||
}
|
||||
|
||||
public async update(): Promise<boolean> {
|
||||
public async update(force?: boolean): Promise<boolean> {
|
||||
super.update(force)
|
||||
logger.info("npm update", path.resolve(this.prefix, this.name))
|
||||
const { error, stdout, stderr } = await exec('npm update --prefix '+ this.prefix + ' ' + this.name)
|
||||
if (error) {
|
||||
@@ -247,7 +256,7 @@ export class NPMExtension extends FSExtension<NPMStatus>{
|
||||
}
|
||||
}
|
||||
|
||||
private async getLatest(): Promise<string | undefined>{
|
||||
private async getLatestVersion(): Promise<string | undefined>{
|
||||
const {
|
||||
error,
|
||||
stdout,
|
||||
@@ -261,6 +270,10 @@ export class NPMExtension extends FSExtension<NPMStatus>{
|
||||
return stdout
|
||||
}
|
||||
}
|
||||
|
||||
private async getCurrentVersion(): Promise<string | undefined>{
|
||||
return //TODO
|
||||
}
|
||||
}
|
||||
|
||||
export type GitStatus = FSStatus & {
|
||||
@@ -272,12 +285,12 @@ export type GitStatus = FSStatus & {
|
||||
export class GitExtension<Status extends GitStatus> extends FSExtension<Status>{
|
||||
protected repo: git.SimpleGit
|
||||
constructor(
|
||||
name:string,
|
||||
prefix:string,
|
||||
repoName:string,
|
||||
localPrefix:string,
|
||||
protected gitCloneURL: string,
|
||||
protected credentials?: [string, string]
|
||||
){
|
||||
super(name, version)
|
||||
super(repoName, localPrefix)
|
||||
}
|
||||
|
||||
public async status(): Promise<Status>{
|
||||
@@ -292,7 +305,7 @@ export class GitExtension<Status extends GitStatus> extends FSExtension<Status>{
|
||||
}
|
||||
|
||||
public async install(): Promise<boolean> {
|
||||
if (!this.isInstalled()){
|
||||
if (super.install()){
|
||||
if (this.credentials){
|
||||
|
||||
} else {
|
||||
@@ -305,7 +318,7 @@ export class GitExtension<Status extends GitStatus> extends FSExtension<Status>{
|
||||
|
||||
|
||||
public async update(): Promise<boolean> {
|
||||
return true
|
||||
return true // do git pull remote origin && git checkout
|
||||
}
|
||||
|
||||
public async isOutdated(): Promise<boolean> {
|
||||
@@ -313,6 +326,55 @@ export class GitExtension<Status extends GitStatus> extends FSExtension<Status>{
|
||||
}
|
||||
}
|
||||
|
||||
export type PluginStatus = GitStatus & {
|
||||
hasFrontend: boolean,
|
||||
hasBackend: boolean,
|
||||
isFrontendLoaded: boolean,
|
||||
isBackendLoaded: boolean
|
||||
}
|
||||
|
||||
export class PluginExtension<Status extends GitStatus> extends GitExtension<Status> {
|
||||
protected frontendLoaded: boolean
|
||||
protected backendLoaded: boolean
|
||||
|
||||
constructor(
|
||||
pluginName: string,
|
||||
gitCloneURL: string,
|
||||
localPrefix: string = './plugins',
|
||||
credentials?: [string, string],
|
||||
protected hasBackend: boolean = true,
|
||||
protected hasFrontend: boolean = true){
|
||||
super(pluginName,localPrefix,gitCloneURL,credentials)
|
||||
}
|
||||
|
||||
public async load(): Promise<void>{
|
||||
if (this.hasFrontend) await this.loadFrontend()
|
||||
if (this.hasBackend) await this.loadBackend()
|
||||
}
|
||||
|
||||
public async loadFrontend(): Promise<void>{
|
||||
return //TODO
|
||||
}
|
||||
|
||||
public async loadBackend(): Promise<void>{
|
||||
return //TODO
|
||||
}
|
||||
|
||||
public async unload(): Promise<void>{
|
||||
if (this.hasFrontend) await this.unloadFrontend()
|
||||
if (this.hasBackend) await this.unloadBackend()
|
||||
}
|
||||
|
||||
public async unloadFrontend(): Promise<void>{
|
||||
return //TODO
|
||||
}
|
||||
|
||||
public async unloadBackend(): Promise<void>{
|
||||
return //TODO
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class UpdateManager extends Plugin{
|
||||
|
||||
private loadedPlugins:{[name in string]:Plugin} = {}
|
||||
|
||||
Reference in New Issue
Block a user