mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
1 parent
746c0a73a2
commit
ba45bfea1e
14 files changed
+79
-84
No files matched your search
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
|
||||
import fsInjectable from "./fs.injectable";
|
||||
|
||||
const readDirInjectable = getInjectable({
|
||||
instantiate: (di) => di.inject(fsInjectable).readdir,
|
||||
lifecycle: lifecycleEnum.singleton,
|
||||
});
|
||||
|
||||
export default readDirInjectable;
|
||||
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
|
||||
import fsInjectable from "./fs.injectable";
|
||||
|
||||
const readFileInjectable = getInjectable({
|
||||
instantiate: (di) => di.inject(fsInjectable).readFile,
|
||||
lifecycle: lifecycleEnum.singleton,
|
||||
});
|
||||
|
||||
export default readFileInjectable;
|
||||
+2
-6
@@ -2,15 +2,11 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { readJsonFile } from "./read-json-file";
|
||||
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
|
||||
import fsInjectable from "../fs.injectable";
|
||||
import fsInjectable from "./fs.injectable";
|
||||
|
||||
const readJsonFileInjectable = getInjectable({
|
||||
instantiate: (di) => readJsonFile({
|
||||
fs: di.inject(fsInjectable),
|
||||
}),
|
||||
|
||||
instantiate: (di) => di.inject(fsInjectable).readJson,
|
||||
lifecycle: lifecycleEnum.singleton,
|
||||
});
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { JsonObject } from "type-fest";
|
||||
|
||||
interface Dependencies {
|
||||
fs: {
|
||||
readJson: (filePath: string) => Promise<JsonObject>;
|
||||
};
|
||||
}
|
||||
|
||||
export const readJsonFile =
|
||||
({ fs }: Dependencies) =>
|
||||
(filePath: string) =>
|
||||
fs.readJson(filePath);
|
||||
+2
-3
@@ -3,11 +3,10 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
|
||||
import { writeJsonFile } from "./write-json-file";
|
||||
import fsInjectable from "../fs.injectable";
|
||||
import fsInjectable from "./fs.injectable";
|
||||
|
||||
const writeJsonFileInjectable = getInjectable({
|
||||
instantiate: (di) => writeJsonFile({ fs: di.inject(fsInjectable) }),
|
||||
instantiate: (di) => di.inject(fsInjectable).writeJson,
|
||||
lifecycle: lifecycleEnum.singleton,
|
||||
});
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import path from "path";
|
||||
import type { JsonObject } from "type-fest";
|
||||
|
||||
interface Dependencies {
|
||||
fs: {
|
||||
ensureDir: (
|
||||
directoryName: string,
|
||||
options: { mode: number }
|
||||
) => Promise<void>;
|
||||
|
||||
writeJson: (
|
||||
filePath: string,
|
||||
contentObject: JsonObject,
|
||||
options: { spaces: number }
|
||||
) => Promise<void>;
|
||||
};
|
||||
}
|
||||
|
||||
export const writeJsonFile =
|
||||
({ fs }: Dependencies) =>
|
||||
async (filePath: string, contentObject: JsonObject) => {
|
||||
const directoryName = path.dirname(filePath);
|
||||
|
||||
await fs.ensureDir(directoryName, { mode: 0o755 });
|
||||
|
||||
await fs.writeJson(filePath, contentObject, { spaces: 2 });
|
||||
};
|
||||
Reference in new issue
Block a user