Files
Umbraco-CMS/src/JsonSchema/Program.cs

46 lines
1.4 KiB
C#
Raw Normal View History

using System;
using System.IO;
using System.Threading.Tasks;
using CommandLine;
namespace JsonSchema
{
class Program
{
2021-06-24 14:49:11 +02:00
private class Options
{
[Option('o', "outputFile", Required = false, HelpText = "Set path of the output file.", Default = "../../../../Umbraco.Web.UI.NetCore/umbraco/config/appsettings-schema.json")]
public string OutputFile { get; set; }
2021-06-24 14:49:11 +02:00
[Option('d', "definitionPrefix", Required = false, HelpText = "Set prefix used for all definisions.", Default = "umbraco")]
public string DefinitionPrefix { get; set; }
}
2021-06-24 14:49:11 +02:00
public static async Task Main(string[] args)
{
2021-06-24 13:24:57 +02:00
try
{
2021-06-24 13:37:57 +02:00
await Parser.Default.ParseArguments<Options>(args)
2021-06-24 14:49:11 +02:00
.WithParsedAsync(Execute);
2021-06-24 13:24:57 +02:00
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
private static async Task Execute(Options options)
{
2021-06-24 14:49:11 +02:00
var generator = new UmbracoJsonSchemaGenerator(options.DefinitionPrefix);
2021-06-24 13:24:57 +02:00
var schema = await generator.Generate();
2021-06-24 14:49:11 +02:00
var path = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, options.OutputFile));
2021-06-24 13:24:57 +02:00
await File.WriteAllTextAsync(path, schema);
2021-06-24 14:49:11 +02:00
Console.WriteLine("File written at " + Path.GetFullPath(path));
}
}
}