-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConvertYamlToJson.csx
35 lines (30 loc) · 1002 Bytes
/
ConvertYamlToJson.csx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#r ".\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll"
#r ".\packages\YamlDotNet.5.2.1\lib\net45\YamlDotNet.dll"
using Newtonsoft.Json;
using System.IO;
using YamlDotNet.Serialization;
static string ConvertYamlToJson(string yaml)
{
return JsonConvert.SerializeObject(new Deserializer().Deserialize(yaml, typeof(object)), Formatting.Indented);
}
static string ReadTextFile(string fileName)
{
using (var source = File.OpenRead(fileName))
using (var reader = new StreamReader(source))
{
return reader.ReadToEnd();
}
}
static void WriteTextFile(string fileName, string content)
{
using (var destination = File.OpenWrite(fileName))
using (var writer = new StreamWriter(destination))
{
writer.Write(content);
}
}
public static void ReadAndWriteFiles(string sourceFileName)
{
WriteTextFile($"{Path.GetFileNameWithoutExtension(sourceFileName)}.json", ConvertYamlToJson(ReadTextFile(sourceFileName)));
}
ReadAndWriteFiles(Environment.GetCommandLineArgs().Last());