|
1
|
import fs from "fs/promises" |
|
2
|
import * as yaml from "js-yaml" |
|
3
|
|
|
4
|
export const readYaml = async (filePath): Promise<unknown> => { |
|
5
|
const yamlString = await fs.readFile(filePath, "utf8") |
|
6
|
return yaml.load(yamlString) |
|
7
|
} |
|
8
|
|
|
9
|
export const writeYaml = async ( |
|
10
|
filePath: string, |
|
11
|
yamlContent: string |
|
12
|
): Promise<void> => { |
|
13
|
await fs.writeFile(filePath, yamlContent, "utf8") |
|
14
|
} |
|
15
|
|
|
16
|
export const writeYamlFromJson = async ( |
|
17
|
filePath, |
|
18
|
jsonObject |
|
19
|
): Promise<void> => { |
|
20
|
const yamlString = yaml.dump(jsonObject) |
|
21
|
await fs.writeFile(filePath, yamlString, "utf8") |
|
22
|
} |
|
23
|
|
|
24
|
export const jsonObjectToYamlString = (jsonObject): string => { |
|
25
|
return yaml.dump(jsonObject) |
|
26
|
} |
|
27
|
|
|
28
|
export const jsonFileToYamlFile = async (inputJsonFile, outputYamlFile) => { |
|
29
|
const jsonString = await fs.readFile(inputJsonFile, "utf8") |
|
30
|
const jsonObject = JSON.parse(jsonString) |
|
31
|
const yamlString = yaml.dump(jsonObject) |
|
32
|
await fs.writeFile(outputYamlFile, yamlString, "utf8") |
|
33
|
} |