npm
This commit is contained in:
+27
-52
@@ -4,6 +4,7 @@ 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 { FrontblockAdmin } from "./FrontblockAdmin";
|
||||
import { TableDefiniton } from "frontblock-generic/Admin";
|
||||
import { promises as fs, mkdirSync as mkdir } from "fs"
|
||||
@@ -44,7 +45,7 @@ const SharedStatus = <Status>
|
||||
type SharedStatus = {
|
||||
name: string
|
||||
installed: boolean
|
||||
outdated: boolean
|
||||
outdated?: boolean
|
||||
}
|
||||
|
||||
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>{
|
||||
const installed = await this.isInstalled()
|
||||
const outdated = await this.isOutdated()
|
||||
const exists = await this.exists()
|
||||
const empty = await this.isEmpty()
|
||||
const status = {
|
||||
return {
|
||||
name: this.name,
|
||||
prefix: this.prefix,
|
||||
installed: installed,
|
||||
outdated: outdated,
|
||||
exists: exists,
|
||||
empty: empty
|
||||
}
|
||||
return status
|
||||
}
|
||||
|
||||
public async uninstall(): Promise<boolean>{
|
||||
return await rimraf(path.resolve(this.prefix, this.name))
|
||||
}
|
||||
|
||||
public async isEmpty(): Promise<boolean>{
|
||||
@@ -154,45 +154,32 @@ export class NPMExtension extends FSExtension<NPMStatus>{
|
||||
}
|
||||
|
||||
public async status(): Promise<NPMStatus> {
|
||||
const empty = await this.isEmpty()
|
||||
const installed = await this.isInstalled()
|
||||
|
||||
const empty = this.isEmpty()
|
||||
const i = this.isInstalled()
|
||||
const o = this.isOutdated()
|
||||
const n = this.name
|
||||
const p = this.p
|
||||
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")
|
||||
|
||||
|
||||
return {name: this.name,}
|
||||
|
||||
return {
|
||||
name: n,
|
||||
prefix: p,
|
||||
installed: i,
|
||||
outdated: o,
|
||||
exists: exists,
|
||||
const status = {
|
||||
empty: empty,
|
||||
};
|
||||
installed: installed,
|
||||
name: this.name,
|
||||
prefix: this.prefix
|
||||
}
|
||||
|
||||
//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){
|
||||
if(_error | error){
|
||||
logger.warn( _stderr, stderr)
|
||||
return {
|
||||
name: this.name,
|
||||
prefix: this.prefix,
|
||||
installed: false,
|
||||
outdated: false,
|
||||
exists: true,
|
||||
empty: false
|
||||
};
|
||||
return {exists: true, empty: false, name: this.name, location: this.localPrefix}
|
||||
return status
|
||||
}
|
||||
|
||||
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> {
|
||||
@@ -232,21 +219,9 @@ export class NPMExtension extends FSExtension<NPMStatus>{
|
||||
}
|
||||
|
||||
public async isOutdated(): Promise<boolean> { //TODO
|
||||
logger.info("npm outdated", path.resolve(this.prefix, this.name))
|
||||
const { error, stdout, stderr } = await exec('npm list --prefix '+ this.prefix + ' --depth=0 | grep ' + this.name)
|
||||
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
|
||||
}
|
||||
const status = await this.status()
|
||||
return !((status.wanted && status.current) && status.wanted === status.current)
|
||||
}
|
||||
|
||||
isInstalled(): Promise<boolean> {
|
||||
throw new Error("Method not implemented."); //TODO
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export type GitRef = string
|
||||
|
||||
Reference in New Issue
Block a user