mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Introduce function to read YAML file
Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
5032301ecb
commit
fadbca0c7c
25
src/common/fs/read-yaml-file.injectable.ts
Normal file
25
src/common/fs/read-yaml-file.injectable.ts
Normal file
@ -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<unknown>;
|
||||||
|
|
||||||
|
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;
|
||||||
Loading…
Reference in New Issue
Block a user