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 { version } from "punycode";
|
||||||
import * as git from "simple-git/promise"
|
import * as git from "simple-git/promise"
|
||||||
import * as trash from "trash"
|
import * as trash from "trash"
|
||||||
|
import { type } from "os";
|
||||||
|
|
||||||
var exec = require('child-process-promise').exec;
|
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))
|
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>{
|
public async isEmpty(): Promise<boolean | undefined>{
|
||||||
if (!this.isInstalled()) return true
|
if (!this.isInstalled()) return true
|
||||||
try {
|
try {
|
||||||
@@ -157,27 +163,29 @@ export abstract class FSExtension<Status extends FSStatus> extends Extension<Sta
|
|||||||
|
|
||||||
type NPMStatus = FSStatus & {
|
type NPMStatus = FSStatus & {
|
||||||
latest?: string,
|
latest?: string,
|
||||||
current?: string, // TODO
|
current?: string,
|
||||||
author?: string
|
author?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export class NPMExtension extends FSExtension<NPMStatus>{
|
export class NPMExtension extends FSExtension<NPMStatus>{
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
name: string,
|
pkgName: string,
|
||||||
prefix: string){
|
prefix: string){
|
||||||
super(name, prefix)
|
super(pkgName, prefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
public async status(): Promise<NPMStatus> {
|
public async status(): Promise<NPMStatus> {
|
||||||
|
|
||||||
const fsStatus = await super.status()
|
const fsStatus = await super.status()
|
||||||
const latest = await this.getLatest()
|
const latest = await this.getLatestVersion()
|
||||||
const author = await this.getAuthor()
|
const author = await this.getAuthor()
|
||||||
|
const current = await this.getCurrentVersion()
|
||||||
return {
|
return {
|
||||||
...fsStatus,
|
...fsStatus,
|
||||||
latest: latest,
|
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()
|
super.uninstall()
|
||||||
logger.info("npm uninstall", this.name, 'from', path.resolve(this.prefix, this.name))
|
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)
|
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))
|
logger.info("npm update", path.resolve(this.prefix, this.name))
|
||||||
const { error, stdout, stderr } = await exec('npm update --prefix '+ this.prefix + ' ' + this.name)
|
const { error, stdout, stderr } = await exec('npm update --prefix '+ this.prefix + ' ' + this.name)
|
||||||
if (error) {
|
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 {
|
const {
|
||||||
error,
|
error,
|
||||||
stdout,
|
stdout,
|
||||||
@@ -261,6 +270,10 @@ export class NPMExtension extends FSExtension<NPMStatus>{
|
|||||||
return stdout
|
return stdout
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async getCurrentVersion(): Promise<string | undefined>{
|
||||||
|
return //TODO
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type GitStatus = FSStatus & {
|
export type GitStatus = FSStatus & {
|
||||||
@@ -272,12 +285,12 @@ export type GitStatus = FSStatus & {
|
|||||||
export class GitExtension<Status extends GitStatus> extends FSExtension<Status>{
|
export class GitExtension<Status extends GitStatus> extends FSExtension<Status>{
|
||||||
protected repo: git.SimpleGit
|
protected repo: git.SimpleGit
|
||||||
constructor(
|
constructor(
|
||||||
name:string,
|
repoName:string,
|
||||||
prefix:string,
|
localPrefix:string,
|
||||||
protected gitCloneURL: string,
|
protected gitCloneURL: string,
|
||||||
protected credentials?: [string, string]
|
protected credentials?: [string, string]
|
||||||
){
|
){
|
||||||
super(name, version)
|
super(repoName, localPrefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
public async status(): Promise<Status>{
|
public async status(): Promise<Status>{
|
||||||
@@ -292,7 +305,7 @@ export class GitExtension<Status extends GitStatus> extends FSExtension<Status>{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async install(): Promise<boolean> {
|
public async install(): Promise<boolean> {
|
||||||
if (!this.isInstalled()){
|
if (super.install()){
|
||||||
if (this.credentials){
|
if (this.credentials){
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -305,7 +318,7 @@ export class GitExtension<Status extends GitStatus> extends FSExtension<Status>{
|
|||||||
|
|
||||||
|
|
||||||
public async update(): Promise<boolean> {
|
public async update(): Promise<boolean> {
|
||||||
return true
|
return true // do git pull remote origin && git checkout
|
||||||
}
|
}
|
||||||
|
|
||||||
public async isOutdated(): Promise<boolean> {
|
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{
|
export class UpdateManager extends Plugin{
|
||||||
|
|
||||||
private loadedPlugins:{[name in string]:Plugin} = {}
|
private loadedPlugins:{[name in string]:Plugin} = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user