isOutdated in NPMExtension
This commit is contained in:
+53
-42
@@ -4,10 +4,11 @@ import { GitUpdater, RepoFolderStatus } from "./GitUpdater";
|
||||
import { FrontblockCherryPicker } from "git-cherrypicker";
|
||||
import * as Logger from 'log4js'
|
||||
import * as path from "path";
|
||||
import * as rimraf from "rimraf"
|
||||
import * as rmrf from "rimraf"
|
||||
import { FrontblockAdmin } from "./FrontblockAdmin";
|
||||
import { TableDefiniton } from "frontblock-generic/Admin";
|
||||
import { promises as fs, mkdirSync as mkdir } from "fs"
|
||||
import { version } from "punycode";
|
||||
|
||||
var exec = require('child-process-promise').exec;
|
||||
|
||||
@@ -45,7 +46,7 @@ const SharedStatus = <Status>
|
||||
type SharedStatus = {
|
||||
name: string
|
||||
installed: boolean
|
||||
outdated?: boolean
|
||||
outdated: boolean
|
||||
}
|
||||
|
||||
abstract class Extension<Status extends SharedStatus>{
|
||||
@@ -108,17 +109,19 @@ export abstract class FSExtension<Status extends FSStatus> extends Extension<FSS
|
||||
|
||||
public async status(): Promise<Status | FSStatus>{
|
||||
const installed = await this.isInstalled()
|
||||
const outdated = await this.isOutdated()
|
||||
const empty = await this.isEmpty()
|
||||
return {
|
||||
name: this.name,
|
||||
prefix: this.prefix,
|
||||
installed: installed,
|
||||
outdated: outdated,
|
||||
empty: empty
|
||||
}
|
||||
}
|
||||
|
||||
public async uninstall(): Promise<boolean>{
|
||||
return await rimraf(path.resolve(this.prefix, this.name))
|
||||
return await rmrf(path.resolve(this.prefix, this.name))
|
||||
}
|
||||
|
||||
public async isEmpty(): Promise<boolean>{
|
||||
@@ -140,9 +143,7 @@ export abstract class FSExtension<Status extends FSStatus> extends Extension<FSS
|
||||
}
|
||||
|
||||
type NPMStatus = FSStatus & {
|
||||
current?: string
|
||||
wanted?: string
|
||||
latest?: string
|
||||
version?: string
|
||||
}
|
||||
|
||||
export class NPMExtension extends FSExtension<NPMStatus>{
|
||||
@@ -154,31 +155,19 @@ export class NPMExtension extends FSExtension<NPMStatus>{
|
||||
}
|
||||
|
||||
public async status(): Promise<NPMStatus> {
|
||||
const empty = await this.isEmpty()
|
||||
const installed = await this.isInstalled()
|
||||
|
||||
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")
|
||||
|
||||
const status = {
|
||||
empty: empty,
|
||||
installed: installed,
|
||||
name: this.name,
|
||||
prefix: this.prefix
|
||||
const fsStatus = await super.status()
|
||||
const { error,
|
||||
stdout,
|
||||
stderr } = await exec('npm info --prefix ' + this.prefix + ' ' + this.name + " version")
|
||||
|
||||
if(error){
|
||||
logger.warn(stderr)
|
||||
return fsStatus
|
||||
}
|
||||
|
||||
if(_error | error){
|
||||
logger.warn( _stderr, stderr)
|
||||
return status
|
||||
}
|
||||
|
||||
const statusJson:{latest:string, location: string, wanted:string} = JSON.parse(_stdout)
|
||||
return {
|
||||
...status,
|
||||
current: stdout,
|
||||
latest: statusJson.latest,
|
||||
wanted: statusJson.wanted,
|
||||
outdated: statusJson.wanted !== stdout
|
||||
...fsStatus,
|
||||
version: stdout
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,16 +207,37 @@ export class NPMExtension extends FSExtension<NPMStatus>{
|
||||
}
|
||||
}
|
||||
|
||||
public async isOutdated(): Promise<boolean> { //TODO
|
||||
const status = await this.status()
|
||||
return !((status.wanted && status.current) && status.wanted === status.current)
|
||||
public async isOutdated(): Promise<boolean> {
|
||||
try {
|
||||
const {
|
||||
error,
|
||||
stdout,
|
||||
stderr } = await exec('npm outdated --prefix ' + this.prefix + " --json" + ' ' + this.name)
|
||||
if (error){
|
||||
logger.warn(stderr)
|
||||
return false
|
||||
}
|
||||
const status = JSON.parse(stdout)
|
||||
if (status){
|
||||
const outdated = (Object.keys(status).length > 0)
|
||||
if (outdated){
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
} catch (error) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export type GitRef = string
|
||||
export type GitExtensionState = UnknownState | GitRef
|
||||
export type GitStatus = FSStatus & {
|
||||
current?: string
|
||||
wanted?: string
|
||||
latest?: string
|
||||
}
|
||||
|
||||
export class GitExtension extends Extension<GitExtensionState>{
|
||||
export class GitExtension extends FSExtension<GitStatus>{
|
||||
constructor(
|
||||
name:string,
|
||||
version = "latest",
|
||||
@@ -236,16 +246,17 @@ export class GitExtension extends Extension<GitExtensionState>{
|
||||
super(name, version)
|
||||
}
|
||||
|
||||
public async install(): Promise<GitExtensionState> {
|
||||
return 'unknown'
|
||||
}
|
||||
|
||||
public async uninstall(): Promise<GitExtensionState> {
|
||||
return 'unknown'
|
||||
public async status(): Promise<GitStatus>{
|
||||
|
||||
}
|
||||
|
||||
public async update(): Promise<GitExtensionState> {
|
||||
return 'unknown'
|
||||
public async install(): Promise<boolean> {
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
public async update(): Promise<boolean> {
|
||||
return true
|
||||
}
|
||||
|
||||
public async isOutdated(): Promise<boolean> {
|
||||
|
||||
Reference in New Issue
Block a user