diff --git a/src/common/vars/lens-resources-dir.injectable.ts b/src/common/vars/lens-resources-dir.injectable.ts new file mode 100644 index 0000000000..9e0122cbfb --- /dev/null +++ b/src/common/vars/lens-resources-dir.injectable.ts @@ -0,0 +1,24 @@ +/** + * 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 contextDirInjectable from "./context-dir.injectable"; +import isDevelopmentInjectable from "./is-development.injectable"; + +const lensResourcesDirInjectable = getInjectable({ + id: "lens-resources-dir", + + instantiate: (di) => { + const isDevelopment = di.inject(isDevelopmentInjectable); + const contextDir = di.inject(contextDirInjectable); + + return isDevelopment + ? contextDir + : (process.resourcesPath ?? contextDir); + }, + + causesSideEffects: true, +}); + +export default lensResourcesDirInjectable; diff --git a/src/common/vars/static-dir.injectable.ts b/src/common/vars/static-dir.injectable.ts new file mode 100644 index 0000000000..ba47b3b24f --- /dev/null +++ b/src/common/vars/static-dir.injectable.ts @@ -0,0 +1,20 @@ +/** + * 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 getAbsolutePathInjectable from "../path/get-absolute-path.injectable"; +import lensResourcesDirInjectable from "./lens-resources-dir.injectable"; + +const staticDirInjectable = getInjectable({ + id: "static-dir", + + instantiate: (di) => { + const getAbsolutePath = di.inject(getAbsolutePathInjectable); + const lensResourcesDir = di.inject(lensResourcesDirInjectable); + + return getAbsolutePath(lensResourcesDir, "static"); + }, +}); + +export default staticDirInjectable;