This commit is contained in:
peter
2019-08-26 23:42:06 +02:00
parent 43c27a3817
commit 3eaf630990
+28 -53
View File
@@ -4,6 +4,7 @@ import { GitUpdater, RepoFolderStatus } from "./GitUpdater";
import { FrontblockCherryPicker } from "git-cherrypicker"; import { FrontblockCherryPicker } from "git-cherrypicker";
import * as Logger from 'log4js' import * as Logger from 'log4js'
import * as path from "path"; import * as path from "path";
import * as rimraf from "rimraf"
import { FrontblockAdmin } from "./FrontblockAdmin"; import { FrontblockAdmin } from "./FrontblockAdmin";
import { TableDefiniton } from "frontblock-generic/Admin"; import { TableDefiniton } from "frontblock-generic/Admin";
import { promises as fs, mkdirSync as mkdir } from "fs" import { promises as fs, mkdirSync as mkdir } from "fs"
@@ -44,7 +45,7 @@ const SharedStatus = <Status>
type SharedStatus = { type SharedStatus = {
name: string name: string
installed: boolean installed: boolean
outdated: boolean outdated?: boolean
} }
abstract class Extension<Status extends SharedStatus>{ abstract class Extension<Status extends SharedStatus>{
@@ -107,18 +108,17 @@ export abstract class FSExtension<Status extends FSStatus> extends Extension<FSS
public async status(): Promise<Status | FSStatus>{ public async status(): Promise<Status | FSStatus>{
const installed = await this.isInstalled() const installed = await this.isInstalled()
const outdated = await this.isOutdated()
const exists = await this.exists()
const empty = await this.isEmpty() const empty = await this.isEmpty()
const status = { return {
name: this.name, name: this.name,
prefix: this.prefix, prefix: this.prefix,
installed: installed, installed: installed,
outdated: outdated,
exists: exists,
empty: empty empty: empty
} }
return status }
public async uninstall(): Promise<boolean>{
return await rimraf(path.resolve(this.prefix, this.name))
} }
public async isEmpty(): Promise<boolean>{ public async isEmpty(): Promise<boolean>{
@@ -154,45 +154,32 @@ export class NPMExtension extends FSExtension<NPMStatus>{
} }
public async status(): Promise<NPMStatus> { public async status(): Promise<NPMStatus> {
const empty = await this.isEmpty()
const installed = await this.isInstalled()
const empty = this.isEmpty() const { _error, _stdout, _stderr } = await exec('npm outdated --prefix ' + this.prefix + " --json" + ' ' + this.name)
const i = this.isInstalled() const { error, stdout, stderr } = await exec('npm info --prefix ' + this.prefix + ' ' + this.name + " version")
const o = this.isOutdated()
const n = this.name
const p = this.p
const status = {
return {name: this.name,}
return {
name: n,
prefix: p,
installed: i,
outdated: o,
exists: exists,
empty: empty, empty: empty,
}; installed: installed,
//const { _error, _stdout, _stderr } = await exec('npm outdated --prefix ' + this.prefix + " --json" + ' ' + this.name)
//const { error, stdout, stderr } = await exec('npm info --prefix ' + this.prefix + ' ' + this.name + " version")
/*if(_error | error){
logger.warn( _stderr, stderr)
return {
name: this.name, name: this.name,
prefix: this.prefix, prefix: this.prefix
installed: false, }
outdated: false,
exists: true, if(_error | error){
empty: false logger.warn( _stderr, stderr)
}; return status
return {exists: true, empty: false, name: this.name, location: this.localPrefix}
} }
const statusJson:{latest:string, location: string, wanted:string} = JSON.parse(_stdout) const statusJson:{latest:string, location: string, wanted:string} = JSON.parse(_stdout)
return { exists: true, empty: false, name: this.name, location: this.localPrefix, version: stdout, latest: statusJson.latest, wanted: statusJson.wanted } return {
...status,
*/ current: stdout,
latest: statusJson.latest,
wanted: statusJson.wanted,
outdated: statusJson.wanted !== stdout
}
} }
public async install(): Promise<boolean> { public async install(): Promise<boolean> {
@@ -232,21 +219,9 @@ export class NPMExtension extends FSExtension<NPMStatus>{
} }
public async isOutdated(): Promise<boolean> { //TODO public async isOutdated(): Promise<boolean> { //TODO
logger.info("npm outdated", path.resolve(this.prefix, this.name)) const status = await this.status()
const { error, stdout, stderr } = await exec('npm list --prefix '+ this.prefix + ' --depth=0 | grep ' + this.name) return !((status.wanted && status.current) && status.wanted === status.current)
if (error !== null) {
logger.warn('npm outdated', this.name, 'from prefix', this.prefix, 'stderr:', stderr)
return false
} else {
logger.info('npm outdated', this.name, 'from prefix', this.prefix, 'stdout:', stdout)
return true
} }
}
isInstalled(): Promise<boolean> {
throw new Error("Method not implemented."); //TODO
}
} }
export type GitRef = string export type GitRef = string