-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathProgram.cs
70 lines (63 loc) · 3.73 KB
/
Program.cs
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/Beef
using Microsoft.Extensions.Logging;
using OnRamp.Config;
using OnRamp.Console;
using OnRamp.Utility;
using System;
using System.Diagnostics;
using System.Reflection;
using System.Threading.Tasks;
namespace Beef.CodeGen
{
/// <summary>
/// Provides the console capabilities.
/// </summary>
public static class Program
{
private static readonly ILogger _logger = new ConsoleLogger(null);
/// <summary>
/// The main entry point.
/// </summary>
/// <param name="args">The console arguments.</param>
/// <returns><b>Zero</b> indicates success; otherwise, unsuccessful.</returns>
public static async Task<int> Main(string[] args)
{
// Check for special case / internal use arguments.
if (args.Length == 1)
{
switch (args[0].ToUpperInvariant())
{
case "--GENERATEENTITYJSONSCHEMA": return SpecialActivitiesCenter("Generate Entity JSON Schema", "./Schema/entity.beef-5.json", fn => JsonSchemaGenerator.Generate<Config.Entity.CodeGenConfig>(fn, "JSON Schema for Beef Entity code-generation (https://github.com/Avanade/Beef)."));
case "--GENERATEDATABASEJSONSCHEMA": return SpecialActivitiesCenter("Generate Database JSON Schema", "./Schema/database.beef-5.json", fn => JsonSchemaGenerator.Generate<Config.Database.CodeGenConfig>(fn, "JSON Schema for Beef Database code-generation (https://github.com/Avanade/Beef)."));
case "--GENERATEENTITYMARKDOWN": return SpecialActivitiesCenter("Generate Entity YAML documentation markdown file(s)", "../../docs/", dn => GenerateMarkdown<Config.Entity.CodeGenConfig>(dn, ConfigType.Entity));
case "--GENERATEDATABASEMARKDOWN": return SpecialActivitiesCenter("Generate Database YAML documentation markdown file(s)", "../../docs/", dn => GenerateMarkdown<Config.Database.CodeGenConfig>(dn, ConfigType.Database));
}
}
var a = new OnRamp.CodeGeneratorArgs().AddAssembly(typeof(CodeGenConsole).Assembly).AddAssembly(Assembly.GetCallingAssembly());
return await new CodeGenConsole(a).RunAsync(args).ConfigureAwait(false);
}
/// <summary>
/// Manage/orchestrate the special activities execution.
/// </summary>
private static int SpecialActivitiesCenter(string title, string filename, Action<string> action)
{
// Method name inspired by: https://en.wikipedia.org/wiki/Special_Activities_Center
_logger.LogInformation("{Content}", "Business Entity Execution Framework (Beef) Code Generator - ** Special Activities Center **");
_logger.LogInformation("{Content}", $" Action: {title}");
_logger.LogInformation("{Content}", $" Filename: {filename}");
var sw = Stopwatch.StartNew();
action(filename);
sw.Stop();
_logger.LogInformation("{Content}", "");
_logger.LogInformation("{Content}", $"CodeGen complete [{sw.Elapsed.TotalMilliseconds}ms].");
_logger.LogInformation("{Content}", "");
return 0;
}
/// <summary>
/// Invoke the <see cref="MarkdownDocumentationGenerator"/>.
/// </summary>
private static void GenerateMarkdown<T>(string directory, ConfigType configType) where T : ConfigBase, IRootConfig
=> MarkdownDocumentationGenerator.Generate<T>(createFileName: (_, cgca) => $"{configType}-{cgca.Name}-Config.md",
directory: directory, includeExample: true, addBreaksBetweenSections: true, fileCreation: fn => _logger.LogWarning("{Content}", $" > {fn}"));
}
}