From fadbca0c7c4352c05a9ec1aefa41736d4aef2cf7 Mon Sep 17 00:00:00 2001 From: Janne Savolainen Date: Fri, 3 Jun 2022 15:31:10 +0300 Subject: [PATCH] Introduce function to read YAML file Co-authored-by: Mikko Aspiala Signed-off-by: Janne Savolainen --- src/common/fs/read-yaml-file.injectable.ts | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/common/fs/read-yaml-file.injectable.ts diff --git a/src/common/fs/read-yaml-file.injectable.ts b/src/common/fs/read-yaml-file.injectable.ts new file mode 100644 index 0000000000..a34a69d388 --- /dev/null +++ b/src/common/fs/read-yaml-file.injectable.ts @@ -0,0 +1,25 @@ +/** + * 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 readFileInjectable from "./read-file.injectable"; +import yaml from "js-yaml"; + +export type ReadYamlFile = (filePath: string) => Promise; + +const readYamlFileInjectable = getInjectable({ + id: "read-yaml-file", + + instantiate: (di): ReadYamlFile => { + const readFile = di.inject(readFileInjectable); + + return async (filePath: string) => { + const contents = await readFile(filePath); + + return yaml.load(contents); + }; + }, +}); + +export default readYamlFileInjectable;