From 3495e182355949d30036f653e2df6b3aa29d7d7f Mon Sep 17 00:00:00 2001 From: Florent BENOIT Date: Wed, 4 Jan 2023 14:36:08 +0100 Subject: [PATCH] chore(podman): move getAssetsFolder to the utility (#1105) chore: move getAssetsFolder to the utility Change-Id: I2c50ca9990f1fc31c2983ca188b1531f9c344e23 Signed-off-by: Florent Benoit Signed-off-by: Florent Benoit --- extensions/podman/src/podman-install.ts | 19 +++---------------- extensions/podman/src/util.ts | 11 +++++++++++ 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/extensions/podman/src/podman-install.ts b/extensions/podman/src/podman-install.ts index d7e3e72b082..2699ca3a7ac 100755 --- a/extensions/podman/src/podman-install.ts +++ b/extensions/podman/src/podman-install.ts @@ -26,7 +26,7 @@ import * as podmanTool from './podman.json'; import type { InstalledPodman } from './podman-cli'; import { execPromise } from './podman-cli'; import { getPodmanInstallation } from './podman-cli'; -import { isDev, runCliCommand } from './util'; +import { getAssetsFolder, runCliCommand } from './util'; import { getDetectionChecks } from './detection-checks'; import { BaseCheck } from './base-check'; import { MacCPUCheck, MacMemoryCheck, MacPodmanInstallCheck, MacVersionCheck } from './macos-checks'; @@ -250,16 +250,6 @@ abstract class BaseInstaller implements Installer { requireUpdate(installedVersion: string): boolean { return compare(installedVersion, getBundledPodmanVersion(), '<'); } - - protected getAssetsFolder(): string { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - if (isDev()) { - return path.resolve(__dirname, '..', 'assets'); - } else { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - return path.resolve((process as any).resourcesPath, 'extensions', 'podman', 'assets'); - } - } } class WinInstaller extends BaseInstaller { @@ -278,7 +268,7 @@ class WinInstaller extends BaseInstaller { install(): Promise { return extensionApi.window.withProgress({ location: extensionApi.ProgressLocation.APP_ICON }, async progress => { progress.report({ increment: 5 }); - const setupPath = path.resolve(this.getAssetsFolder(), `podman-${podmanTool.version}-setup.exe`); + const setupPath = path.resolve(getAssetsFolder(), `podman-${podmanTool.version}-setup.exe`); try { if (fs.existsSync(setupPath)) { const runResult = await runCliCommand(setupPath, ['/install', '/norestart']); @@ -309,10 +299,7 @@ class MacOSInstaller extends BaseInstaller { progress.report({ increment: 5 }); const pkgArch = process.arch === 'arm64' ? 'aarch64' : 'amd64'; - const pkgPath = path.resolve( - this.getAssetsFolder(), - `podman-installer-macos-${pkgArch}-v${podmanTool.version}.pkg`, - ); + const pkgPath = path.resolve(getAssetsFolder(), `podman-installer-macos-${pkgArch}-v${podmanTool.version}.pkg`); try { if (fs.existsSync(pkgPath)) { const runResult = await runCliCommand('open', [pkgPath, '-W']); diff --git a/extensions/podman/src/util.ts b/extensions/podman/src/util.ts index e2a2e77dfba..a1944c58b27 100644 --- a/extensions/podman/src/util.ts +++ b/extensions/podman/src/util.ts @@ -17,6 +17,7 @@ ***********************************************************************/ import * as os from 'node:os'; +import * as path from 'node:path'; import { spawn } from 'node:child_process'; import { getInstallationPath } from './podman-cli'; @@ -43,6 +44,16 @@ export interface RunOptions { env?: NodeJS.ProcessEnv; } +export function getAssetsFolder(): string { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + if (isDev()) { + return path.resolve(__dirname, '..', 'assets'); + } else { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return path.resolve((process as any).resourcesPath, 'extensions', 'podman', 'assets'); + } +} + export function runCliCommand(command: string, args: string[], options?: RunOptions): Promise { return new Promise((resolve, reject) => { let output = '';