From 3eaf6309900ac63719cea9af834b288a87e258d7 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 26 Aug 2019 23:42:06 +0200 Subject: [PATCH] npm --- src/backend/UpdateManger.ts | 83 +++++++++++++------------------------ 1 file changed, 29 insertions(+), 54 deletions(-) diff --git a/src/backend/UpdateManger.ts b/src/backend/UpdateManger.ts index 2e1bf8c..7c516e7 100644 --- a/src/backend/UpdateManger.ts +++ b/src/backend/UpdateManger.ts @@ -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 = type SharedStatus = { name: string installed: boolean - outdated: boolean + outdated?: boolean } abstract class Extension{ @@ -107,18 +108,17 @@ export abstract class FSExtension extends Extension{ 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{ + return await rimraf(path.resolve(this.prefix, this.name)) } public async isEmpty(): Promise{ @@ -154,45 +154,32 @@ export class NPMExtension extends FSExtension{ } public async status(): Promise { + 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 - - - return {name: this.name,} - - return { - name: n, - prefix: p, - installed: i, - outdated: o, - exists: exists, - empty: empty, - }; - - //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 { _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){ + const status = { + empty: empty, + installed: installed, + name: this.name, + prefix: this.prefix + } + + 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 { @@ -232,21 +219,9 @@ export class NPMExtension extends FSExtension{ } public async isOutdated(): Promise { //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 { - throw new Error("Method not implemented."); //TODO - } - } export type GitRef = string