mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix remaining type errors
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
8e2c535bd3
commit
9e72f90393
@ -12,6 +12,7 @@ import normalizedPlatformInjectable from "../../common/vars/normalized-platform.
|
|||||||
import kubectlBinaryNameInjectable from "./binary-name.injectable";
|
import kubectlBinaryNameInjectable from "./binary-name.injectable";
|
||||||
import bundledKubectlBinaryPathInjectable from "./bundled-binary-path.injectable";
|
import bundledKubectlBinaryPathInjectable from "./bundled-binary-path.injectable";
|
||||||
import baseBundledBinariesDirectoryInjectable from "../../common/vars/base-bundled-binaries-dir.injectable";
|
import baseBundledBinariesDirectoryInjectable from "../../common/vars/base-bundled-binaries-dir.injectable";
|
||||||
|
import loggerInjectable from "../../common/logger.injectable";
|
||||||
|
|
||||||
const createKubectlInjectable = getInjectable({
|
const createKubectlInjectable = getInjectable({
|
||||||
id: "create-kubectl",
|
id: "create-kubectl",
|
||||||
@ -25,6 +26,7 @@ const createKubectlInjectable = getInjectable({
|
|||||||
kubectlBinaryName: di.inject(kubectlBinaryNameInjectable),
|
kubectlBinaryName: di.inject(kubectlBinaryNameInjectable),
|
||||||
bundledKubectlBinaryPath: di.inject(bundledKubectlBinaryPathInjectable),
|
bundledKubectlBinaryPath: di.inject(bundledKubectlBinaryPathInjectable),
|
||||||
baseBundeledBinariesDirectory: di.inject(baseBundledBinariesDirectoryInjectable),
|
baseBundeledBinariesDirectory: di.inject(baseBundledBinariesDirectoryInjectable),
|
||||||
|
logger: di.inject(loggerInjectable),
|
||||||
};
|
};
|
||||||
|
|
||||||
return (clusterVersion: string) => new Kubectl(dependencies, clusterVersion);
|
return (clusterVersion: string) => new Kubectl(dependencies, clusterVersion);
|
||||||
|
|||||||
@ -6,7 +6,6 @@
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import { promiseExecFile } from "../../common/utils/promise-exec";
|
import { promiseExecFile } from "../../common/utils/promise-exec";
|
||||||
import logger from "../logger";
|
|
||||||
import { ensureDir, pathExists } from "fs-extra";
|
import { ensureDir, pathExists } from "fs-extra";
|
||||||
import * as lockFile from "proper-lockfile";
|
import * as lockFile from "proper-lockfile";
|
||||||
import { getBundledKubectlVersion } from "../../common/utils/app-version";
|
import { getBundledKubectlVersion } from "../../common/utils/app-version";
|
||||||
@ -16,6 +15,7 @@ import got from "got/dist/source";
|
|||||||
import { promisify } from "util";
|
import { promisify } from "util";
|
||||||
import stream from "stream";
|
import stream from "stream";
|
||||||
import { noop } from "lodash/fp";
|
import { noop } from "lodash/fp";
|
||||||
|
import type { Logger } from "../../common/logger";
|
||||||
|
|
||||||
const bundledVersion = getBundledKubectlVersion();
|
const bundledVersion = getBundledKubectlVersion();
|
||||||
const kubectlMap: Map<string, string> = new Map([
|
const kubectlMap: Map<string, string> = new Map([
|
||||||
@ -52,6 +52,7 @@ export interface KubectlDependencies {
|
|||||||
readonly downloadKubectlBinaries: boolean;
|
readonly downloadKubectlBinaries: boolean;
|
||||||
readonly downloadMirror: string;
|
readonly downloadMirror: string;
|
||||||
};
|
};
|
||||||
|
readonly logger: Logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Kubectl {
|
export class Kubectl {
|
||||||
@ -80,10 +81,10 @@ export class Kubectl {
|
|||||||
*/
|
*/
|
||||||
if (fromMajorMinor) {
|
if (fromMajorMinor) {
|
||||||
this.kubectlVersion = fromMajorMinor;
|
this.kubectlVersion = fromMajorMinor;
|
||||||
logger.debug(`Set kubectl version ${this.kubectlVersion} for cluster version ${clusterVersion} using version map`);
|
this.dependencies.logger.debug(`Set kubectl version ${this.kubectlVersion} for cluster version ${clusterVersion} using version map`);
|
||||||
} else {
|
} else {
|
||||||
this.kubectlVersion = version.format();
|
this.kubectlVersion = version.format();
|
||||||
logger.debug(`Set kubectl version ${this.kubectlVersion} for cluster version ${clusterVersion} using fallback`);
|
this.dependencies.logger.debug(`Set kubectl version ${this.kubectlVersion} for cluster version ${clusterVersion} using fallback`);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.url = `${this.getDownloadMirror()}/v${this.kubectlVersion}/bin/${this.dependencies.normalizedDownloadPlatform}/${this.dependencies.normalizedDownloadArch}/${this.dependencies.kubectlBinaryName}`;
|
this.url = `${this.getDownloadMirror()}/v${this.kubectlVersion}/bin/${this.dependencies.normalizedDownloadPlatform}/${this.dependencies.normalizedDownloadArch}/${this.dependencies.kubectlBinaryName}`;
|
||||||
@ -125,14 +126,14 @@ export class Kubectl {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (!await this.ensureKubectl()) {
|
if (!await this.ensureKubectl()) {
|
||||||
logger.error("Failed to ensure kubectl, fallback to the bundled version");
|
this.dependencies.logger.error("Failed to ensure kubectl, fallback to the bundled version");
|
||||||
|
|
||||||
return this.getBundledPath();
|
return this.getBundledPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.path;
|
return this.path;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error("Failed to ensure kubectl, fallback to the bundled version", err);
|
this.dependencies.logger.error("Failed to ensure kubectl, fallback to the bundled version", err);
|
||||||
|
|
||||||
return this.getBundledPath();
|
return this.getBundledPath();
|
||||||
}
|
}
|
||||||
@ -145,7 +146,7 @@ export class Kubectl {
|
|||||||
|
|
||||||
return this.dirname;
|
return this.dirname;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error("Failed to get biniary directory", err);
|
this.dependencies.logger.error("Failed to get the directory of the binary", err);
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@ -174,13 +175,13 @@ export class Kubectl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (version === this.kubectlVersion) {
|
if (version === this.kubectlVersion) {
|
||||||
logger.debug(`Local kubectl is version ${this.kubectlVersion}`);
|
this.dependencies.logger.debug(`Local kubectl is version ${this.kubectlVersion}`);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
logger.error(`Local kubectl is version ${version}, expected ${this.kubectlVersion}, unlinking`);
|
this.dependencies.logger.error(`Local kubectl is version ${version}, expected ${this.kubectlVersion}, unlinking`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Local kubectl failed to run properly (${error}), unlinking`);
|
this.dependencies.logger.error(`Local kubectl failed to run properly (${error}), unlinking`);
|
||||||
}
|
}
|
||||||
await fs.promises.unlink(this.path);
|
await fs.promises.unlink(this.path);
|
||||||
}
|
}
|
||||||
@ -200,7 +201,7 @@ export class Kubectl {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(`Could not copy the bundled kubectl to app-data: ${err}`);
|
this.dependencies.logger.error(`Could not copy the bundled kubectl to app-data: ${err}`);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -215,7 +216,7 @@ export class Kubectl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Kubectl.invalidBundle) {
|
if (Kubectl.invalidBundle) {
|
||||||
logger.error(`Detected invalid bundle binary, returning ...`);
|
this.dependencies.logger.error(`Detected invalid bundle binary, returning ...`);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -225,7 +226,7 @@ export class Kubectl {
|
|||||||
try {
|
try {
|
||||||
const release = await lockFile.lock(this.dirname);
|
const release = await lockFile.lock(this.dirname);
|
||||||
|
|
||||||
logger.debug(`Acquired a lock for ${this.kubectlVersion}`);
|
this.dependencies.logger.debug(`Acquired a lock for ${this.kubectlVersion}`);
|
||||||
const bundled = await this.checkBundled();
|
const bundled = await this.checkBundled();
|
||||||
let isValid = await this.checkBinary(this.path, !bundled);
|
let isValid = await this.checkBinary(this.path, !bundled);
|
||||||
|
|
||||||
@ -233,8 +234,8 @@ export class Kubectl {
|
|||||||
try {
|
try {
|
||||||
await this.downloadKubectl();
|
await this.downloadKubectl();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`[KUBECTL]: failed to download kubectl`, error);
|
this.dependencies.logger.error(`[KUBECTL]: failed to download kubectl`, error);
|
||||||
logger.debug(`[KUBECTL]: Releasing lock for ${this.kubectlVersion}`);
|
this.dependencies.logger.debug(`[KUBECTL]: Releasing lock for ${this.kubectlVersion}`);
|
||||||
await release();
|
await release();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -244,18 +245,18 @@ export class Kubectl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!isValid) {
|
if (!isValid) {
|
||||||
logger.debug(`[KUBECTL]: Releasing lock for ${this.kubectlVersion}`);
|
this.dependencies.logger.debug(`[KUBECTL]: Releasing lock for ${this.kubectlVersion}`);
|
||||||
await release();
|
await release();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug(`[KUBECTL]: Releasing lock for ${this.kubectlVersion}`);
|
this.dependencies.logger.debug(`[KUBECTL]: Releasing lock for ${this.kubectlVersion}`);
|
||||||
await release();
|
await release();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`[KUBECTL]: Failed to get a lock for ${this.kubectlVersion}`, error);
|
this.dependencies.logger.error(`[KUBECTL]: Failed to get a lock for ${this.kubectlVersion}`, error);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -264,7 +265,7 @@ export class Kubectl {
|
|||||||
public async downloadKubectl() {
|
public async downloadKubectl() {
|
||||||
await ensureDir(path.dirname(this.path), 0o755);
|
await ensureDir(path.dirname(this.path), 0o755);
|
||||||
|
|
||||||
logger.info(`Downloading kubectl ${this.kubectlVersion} from ${this.url} to ${this.path}`);
|
this.dependencies.logger.info(`Downloading kubectl ${this.kubectlVersion} from ${this.url} to ${this.path}`);
|
||||||
|
|
||||||
const downloadStream = got.stream({ url: this.url, decompress: true });
|
const downloadStream = got.stream({ url: this.url, decompress: true });
|
||||||
const fileWriteStream = fs.createWriteStream(this.path, { mode: 0o755 });
|
const fileWriteStream = fs.createWriteStream(this.path, { mode: 0o755 });
|
||||||
@ -273,7 +274,7 @@ export class Kubectl {
|
|||||||
try {
|
try {
|
||||||
await pipeline(downloadStream, fileWriteStream);
|
await pipeline(downloadStream, fileWriteStream);
|
||||||
await fs.promises.chmod(this.path, 0o755);
|
await fs.promises.chmod(this.path, 0o755);
|
||||||
logger.debug("kubectl binary download finished");
|
this.dependencies.logger.debug("kubectl binary download finished");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
await fs.promises.unlink(this.path).catch(noop);
|
await fs.promises.unlink(this.path).catch(noop);
|
||||||
throw error;
|
throw error;
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
|
import loggerInjectable from "../../common/logger.injectable";
|
||||||
import userStoreInjectable from "../../common/user-store/user-store.injectable";
|
import userStoreInjectable from "../../common/user-store/user-store.injectable";
|
||||||
import ipcRendererInjectable from "../utils/channel/ipc-renderer.injectable";
|
import ipcRendererInjectable from "../utils/channel/ipc-renderer.injectable";
|
||||||
import { ThemeStore } from "./store";
|
import { ThemeStore } from "./store";
|
||||||
@ -13,6 +14,7 @@ const themeStoreInjectable = getInjectable({
|
|||||||
instantiate: (di) => new ThemeStore({
|
instantiate: (di) => new ThemeStore({
|
||||||
ipcRenderer: di.inject(ipcRendererInjectable),
|
ipcRenderer: di.inject(ipcRendererInjectable),
|
||||||
userStore: di.inject(userStoreInjectable),
|
userStore: di.inject(userStoreInjectable),
|
||||||
|
logger: di.inject(loggerInjectable),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
import { comparer, computed, makeObservable, observable, reaction } from "mobx";
|
import { comparer, computed, makeObservable, observable, reaction } from "mobx";
|
||||||
import { autoBind } from "../utils";
|
import { autoBind } from "../utils";
|
||||||
import logger from "../../main/logger";
|
|
||||||
import lensDarkTheme from "./lens-dark";
|
import lensDarkTheme from "./lens-dark";
|
||||||
import lensLightTheme from "./lens-light";
|
import lensLightTheme from "./lens-light";
|
||||||
import type { MonacoTheme } from "../components/monaco-editor";
|
import type { MonacoTheme } from "../components/monaco-editor";
|
||||||
@ -15,6 +14,7 @@ import type { IpcRenderer } from "electron";
|
|||||||
import { getNativeThemeChannel, setNativeThemeChannel } from "../../common/ipc/native-theme";
|
import { getNativeThemeChannel, setNativeThemeChannel } from "../../common/ipc/native-theme";
|
||||||
import type { ReadonlyDeep } from "type-fest/source/readonly-deep";
|
import type { ReadonlyDeep } from "type-fest/source/readonly-deep";
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
|
import type { Logger } from "../../common/logger";
|
||||||
|
|
||||||
export type ThemeId = string;
|
export type ThemeId = string;
|
||||||
|
|
||||||
@ -29,16 +29,17 @@ export interface Theme {
|
|||||||
|
|
||||||
interface Dependencies {
|
interface Dependencies {
|
||||||
readonly userStore: {
|
readonly userStore: {
|
||||||
colorTheme: string;
|
readonly colorTheme: string;
|
||||||
terminalTheme: ThemeId;
|
readonly terminalTheme: ThemeId;
|
||||||
resetTheme(): void;
|
resetTheme(): void;
|
||||||
};
|
};
|
||||||
readonly ipcRenderer: IpcRenderer;
|
readonly ipcRenderer: IpcRenderer;
|
||||||
|
readonly logger: Logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ThemeStore {
|
const terminalColorPrefix = "terminal";
|
||||||
private terminalColorPrefix = "terminal";
|
|
||||||
|
|
||||||
|
export class ThemeStore {
|
||||||
#themes = observable.map<ThemeId, Theme>({
|
#themes = observable.map<ThemeId, Theme>({
|
||||||
"lens-dark": lensDarkTheme,
|
"lens-dark": lensDarkTheme,
|
||||||
"lens-light": lensLightTheme,
|
"lens-light": lensLightTheme,
|
||||||
@ -77,7 +78,7 @@ export class ThemeStore {
|
|||||||
|
|
||||||
return Object
|
return Object
|
||||||
.entries(theme.colors)
|
.entries(theme.colors)
|
||||||
.filter(([name]) => name.startsWith(this.terminalColorPrefix));
|
.filter(([name]) => name.startsWith(terminalColorPrefix));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replacing keys stored in styles to format accepted by terminal
|
// Replacing keys stored in styles to format accepted by terminal
|
||||||
@ -85,7 +86,7 @@ export class ThemeStore {
|
|||||||
@computed get xtermColors(): Record<string, string> {
|
@computed get xtermColors(): Record<string, string> {
|
||||||
return Object.fromEntries(
|
return Object.fromEntries(
|
||||||
this.terminalColors.map(([name, color]) => [
|
this.terminalColors.map(([name, color]) => [
|
||||||
camelCase(name.replace(this.terminalColorPrefix, "")),
|
camelCase(name.replace(terminalColorPrefix, "")),
|
||||||
color,
|
color,
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
@ -117,11 +118,11 @@ export class ThemeStore {
|
|||||||
reaction(() => ({
|
reaction(() => ({
|
||||||
themeId: this.activeThemeId,
|
themeId: this.activeThemeId,
|
||||||
terminalThemeId: this.terminalThemeId,
|
terminalThemeId: this.terminalThemeId,
|
||||||
}), () => {
|
}), (themes) => {
|
||||||
try {
|
try {
|
||||||
this.applyActiveTheme();
|
this.applyActiveTheme();
|
||||||
} catch (err) {
|
} catch (error) {
|
||||||
logger.error(`Failed to apply active theme: ${err}`);
|
this.dependencies.logger.error(`Failed to apply themes: ${error}`, themes);
|
||||||
this.dependencies.userStore.resetTheme();
|
this.dependencies.userStore.resetTheme();
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user