2021-06-24 08:47:37 +02:00
|
|
|
|
using System;
|
2021-06-24 09:58:38 +02:00
|
|
|
|
using System.IO;
|
2021-06-24 08:47:37 +02:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using CommandLine;
|
|
|
|
|
|
|
|
|
|
|
|
namespace JsonSchema
|
|
|
|
|
|
{
|
|
|
|
|
|
class Program
|
|
|
|
|
|
{
|
2021-06-24 14:49:11 +02:00
|
|
|
|
private class Options
|
2021-06-24 08:47:37 +02:00
|
|
|
|
{
|
2021-06-24 15:18:00 +02:00
|
|
|
|
[Option('o', "outputFile", Required = false, HelpText = "Set path of the output file.", Default = "../Umbraco.Web.UI.NetCore/umbraco/config/appsettings-schema.json")]
|
2021-06-24 08:47:37 +02:00
|
|
|
|
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 08:47:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-06-24 14:49:11 +02:00
|
|
|
|
public static async Task Main(string[] args)
|
2021-06-24 08:47:37 +02:00
|
|
|
|
{
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-06-24 08:47:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 08:47:37 +02:00
|
|
|
|
|
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 09:58:38 +02:00
|
|
|
|
|
2021-06-24 14:49:11 +02:00
|
|
|
|
Console.WriteLine("File written at " + Path.GetFullPath(path));
|
2021-06-24 08:47:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|