isOutdated in NPMExtension
This commit is contained in:
+7
-1
@@ -51,5 +51,11 @@
|
|||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"lib/**/*"
|
"lib/**/*"
|
||||||
]
|
],
|
||||||
|
"main": "index.js",
|
||||||
|
"directories": {
|
||||||
|
"lib": "lib",
|
||||||
|
"test": "test"
|
||||||
|
},
|
||||||
|
"keywords": []
|
||||||
}
|
}
|
||||||
|
|||||||
+50
-39
@@ -4,10 +4,11 @@ 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 * as rmrf 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"
|
||||||
|
import { version } from "punycode";
|
||||||
|
|
||||||
var exec = require('child-process-promise').exec;
|
var exec = require('child-process-promise').exec;
|
||||||
|
|
||||||
@@ -45,7 +46,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>{
|
||||||
@@ -108,17 +109,19 @@ 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 empty = await this.isEmpty()
|
const empty = await this.isEmpty()
|
||||||
return {
|
return {
|
||||||
name: this.name,
|
name: this.name,
|
||||||
prefix: this.prefix,
|
prefix: this.prefix,
|
||||||
installed: installed,
|
installed: installed,
|
||||||
|
outdated: outdated,
|
||||||
empty: empty
|
empty: empty
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async uninstall(): Promise<boolean>{
|
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>{
|
public async isEmpty(): Promise<boolean>{
|
||||||
@@ -140,9 +143,7 @@ export abstract class FSExtension<Status extends FSStatus> extends Extension<FSS
|
|||||||
}
|
}
|
||||||
|
|
||||||
type NPMStatus = FSStatus & {
|
type NPMStatus = FSStatus & {
|
||||||
current?: string
|
version?: string
|
||||||
wanted?: string
|
|
||||||
latest?: string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class NPMExtension extends FSExtension<NPMStatus>{
|
export class NPMExtension extends FSExtension<NPMStatus>{
|
||||||
@@ -154,31 +155,19 @@ 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 { _error, _stdout, _stderr } = await exec('npm outdated --prefix ' + this.prefix + " --json" + ' ' + this.name)
|
const fsStatus = await super.status()
|
||||||
const { error, stdout, stderr } = await exec('npm info --prefix ' + this.prefix + ' ' + this.name + " version")
|
const { error,
|
||||||
|
stdout,
|
||||||
|
stderr } = await exec('npm info --prefix ' + this.prefix + ' ' + this.name + " version")
|
||||||
|
|
||||||
const status = {
|
if(error){
|
||||||
empty: empty,
|
logger.warn(stderr)
|
||||||
installed: installed,
|
return fsStatus
|
||||||
name: this.name,
|
|
||||||
prefix: this.prefix
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(_error | error){
|
|
||||||
logger.warn( _stderr, stderr)
|
|
||||||
return status
|
|
||||||
}
|
|
||||||
|
|
||||||
const statusJson:{latest:string, location: string, wanted:string} = JSON.parse(_stdout)
|
|
||||||
return {
|
return {
|
||||||
...status,
|
...fsStatus,
|
||||||
current: stdout,
|
version: stdout
|
||||||
latest: statusJson.latest,
|
|
||||||
wanted: statusJson.wanted,
|
|
||||||
outdated: statusJson.wanted !== stdout
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,16 +207,37 @@ export class NPMExtension extends FSExtension<NPMStatus>{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async isOutdated(): Promise<boolean> { //TODO
|
public async isOutdated(): Promise<boolean> {
|
||||||
const status = await this.status()
|
try {
|
||||||
return !((status.wanted && status.current) && status.wanted === status.current)
|
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 GitStatus = FSStatus & {
|
||||||
export type GitExtensionState = UnknownState | GitRef
|
current?: string
|
||||||
|
wanted?: string
|
||||||
|
latest?: string
|
||||||
|
}
|
||||||
|
|
||||||
export class GitExtension extends Extension<GitExtensionState>{
|
export class GitExtension extends FSExtension<GitStatus>{
|
||||||
constructor(
|
constructor(
|
||||||
name:string,
|
name:string,
|
||||||
version = "latest",
|
version = "latest",
|
||||||
@@ -236,16 +246,17 @@ export class GitExtension extends Extension<GitExtensionState>{
|
|||||||
super(name, version)
|
super(name, version)
|
||||||
}
|
}
|
||||||
|
|
||||||
public async install(): Promise<GitExtensionState> {
|
public async status(): Promise<GitStatus>{
|
||||||
return 'unknown'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async uninstall(): Promise<GitExtensionState> {
|
public async install(): Promise<boolean> {
|
||||||
return 'unknown'
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
public async update(): Promise<GitExtensionState> {
|
|
||||||
return 'unknown'
|
public async update(): Promise<boolean> {
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
public async isOutdated(): Promise<boolean> {
|
public async isOutdated(): Promise<boolean> {
|
||||||
|
|||||||
Reference in New Issue
Block a user