From 14e5291cae615f18cff52620677a1c5611ab9ed6 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 22 May 2018 19:15:35 -0400 Subject: [PATCH] use execPath if in pkg --- src/commands/update.command.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/commands/update.command.ts b/src/commands/update.command.ts index e4182b6c356..dc2f74d93b8 100644 --- a/src/commands/update.command.ts +++ b/src/commands/update.command.ts @@ -1,6 +1,7 @@ import * as AdmZip from 'adm-zip'; import * as program from 'commander'; import * as fetch from 'node-fetch'; +import * as path from 'path'; import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; @@ -8,7 +9,11 @@ import { Response } from '../models/response'; import { MessageResponse } from '../models/response/messageResponse'; export class UpdateCommand { - constructor(private platformUtilsService: PlatformUtilsService) { } + inPkg: boolean = false; + + constructor(private platformUtilsService: PlatformUtilsService) { + this.inPkg = !!(process as any).pkg; + } async run(cmd: program.Command): Promise { const currentVersion = this.platformUtilsService.getApplicationVersion(); @@ -56,7 +61,8 @@ export class UpdateCommand { try { const zipBuffer = await zipResponse.buffer(); const zip = new AdmZip(zipBuffer); - zip.extractAllTo(__dirname, true); + const currentDir = this.inPkg ? path.dirname(process.execPath) : __dirname; + zip.extractAllTo(currentDir, true); res.title = 'Updated self to ' + tagName + '.'; if (responseJson.body != null && responseJson.body !== '') { res.message = responseJson.body;