mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Introduce way for execute file
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
2b5d54e8d9
commit
0ba16a81de
23
src/common/fs/exec-file.injectable.ts
Normal file
23
src/common/fs/exec-file.injectable.ts
Normal file
@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { execFile } from "child_process";
|
||||
|
||||
export type ExecFile = (filePath: string, args: string[]) => Promise<string>;
|
||||
|
||||
const execFileInjectable = getInjectable({
|
||||
id: "exec-file",
|
||||
|
||||
instantiate: (): ExecFile => async (filePath, args) =>
|
||||
new Promise((resolve) => {
|
||||
execFile(filePath, args, (error, stdout) => {
|
||||
resolve(stdout);
|
||||
});
|
||||
}),
|
||||
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
export default execFileInjectable;
|
||||
@ -84,6 +84,7 @@ import startKubeConfigSyncInjectable from "./start-main-application/runnables/ku
|
||||
import appVersionInjectable from "../common/get-configuration-file-model/app-version/app-version.injectable";
|
||||
import getRandomIdInjectable from "../common/utils/get-random-id.injectable";
|
||||
import periodicalCheckForUpdatesInjectable from "./application-update/periodical-check-for-updates/periodical-check-for-updates.injectable";
|
||||
import execFileInjectable from "../common/fs/exec-file.injectable";
|
||||
|
||||
export function getDiForUnitTesting(opts: { doGeneralOverrides?: boolean } = {}) {
|
||||
const {
|
||||
@ -162,6 +163,11 @@ export function getDiForUnitTesting(opts: { doGeneralOverrides?: boolean } = {})
|
||||
throw new Error("Tried to read file from file system without specifying explicit override.");
|
||||
});
|
||||
|
||||
di.override(execFileInjectable, () => () => {
|
||||
throw new Error("Tried to exec file from file system without specifying explicit override.");
|
||||
});
|
||||
|
||||
|
||||
di.override(loggerInjectable, () => ({
|
||||
warn: noop,
|
||||
debug: noop,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user