-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathWebsiteBuilder.cs
More file actions
98 lines (86 loc) · 3.99 KB
/
WebsiteBuilder.cs
File metadata and controls
98 lines (86 loc) · 3.99 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using Generator.DTO;
using Generator.DTO.Warnings;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Text;
namespace Generator;
internal class WebsiteBuilder
{
private readonly IConfiguration configuration;
private readonly IEnumerable<Record> records;
private readonly IEnumerable<SolutionWarning> warnings;
private readonly IEnumerable<SolutionComponentCollection> solutionComponents;
private readonly Dictionary<string, GlobalOptionSetUsage> globalOptionSetUsages;
private readonly string OutputFolder;
public WebsiteBuilder(
IConfiguration configuration,
IEnumerable<Record> records,
IEnumerable<SolutionWarning> warnings,
Dictionary<string, GlobalOptionSetUsage> globalOptionSetUsages,
IEnumerable<SolutionComponentCollection>? solutionComponents = null)
{
this.configuration = configuration;
this.records = records;
this.warnings = warnings;
this.solutionComponents = solutionComponents ?? Enumerable.Empty<SolutionComponentCollection>();
this.globalOptionSetUsages = globalOptionSetUsages;
// Assuming execution in bin/xxx/net8.0
OutputFolder = configuration["OutputFolder"] ?? Path.Combine(System.Reflection.Assembly.GetExecutingAssembly().Location, "../../../../../Website/generated");
Directory.CreateDirectory(OutputFolder);
}
internal void AddData()
{
var sb = new StringBuilder();
sb.AppendLine("import { GroupType, SolutionWarningType, SolutionComponentCollectionType } from \"@/lib/Types\";");
sb.AppendLine("");
sb.AppendLine($"export const LastSynched: Date = new Date('{DateTimeOffset.UtcNow:yyyy-MM-ddTHH:mm:ss.fffZ}');");
var logoUrl = configuration.GetValue<string?>("Logo", defaultValue: null);
var jsValue = logoUrl != null ? $"\"{logoUrl}\"" : "null";
sb.AppendLine($"export const Logo: string | null = {jsValue};");
sb.AppendLine($"export const SolutionCount: number = {configuration["DataverseSolutionNames"]?.Split(",").Length ?? -1};");
sb.AppendLine("");
// ENTITIES
sb.AppendLine("export let Groups: GroupType[] = [");
var groups = records.GroupBy(x => x.Group).OrderBy(x => x.Key);
foreach (var group in groups)
{
var groupName = group.Key ?? "Ungrouped";
sb.AppendLine(" {");
sb.AppendLine($" \"Name\":\"{groupName}\",");
sb.AppendLine(" \"Entities\":[");
foreach (var entity in group.OrderBy(x => x.DisplayName))
{
sb.AppendLine($" {JsonConvert.SerializeObject(entity)},");
}
sb.AppendLine(" ]");
sb.AppendLine(" },");
}
sb.AppendLine("]");
// WARNINGS
sb.AppendLine("");
sb.AppendLine("export let SolutionWarnings: SolutionWarningType[] = [");
foreach (var warning in warnings)
{
sb.AppendLine($" {JsonConvert.SerializeObject(warning)},");
}
sb.AppendLine("]");
// SOLUTION COMPONENTS (for insights)
sb.AppendLine("");
sb.AppendLine("export let SolutionComponents: SolutionComponentCollectionType[] = [");
foreach (var collection in solutionComponents)
{
sb.AppendLine($" {JsonConvert.SerializeObject(collection)},");
}
sb.AppendLine("]");
// GLOBAL OPTION SETS
sb.AppendLine("");
sb.AppendLine("export const GlobalOptionSets: Record<string, { Name: string; DisplayName: string; Usages: { EntitySchemaName: string; EntityDisplayName: string; AttributeSchemaName: string; AttributeDisplayName: string }[] }> = {");
foreach (var (key, usage) in globalOptionSetUsages)
{
sb.AppendLine($" \"{key}\": {JsonConvert.SerializeObject(usage)},");
}
sb.AppendLine("};");
File.WriteAllText(Path.Combine(OutputFolder, "Data.ts"), sb.ToString());
}
}