-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
--- Refer to commit d437468 for more info. --- Type: add Breaking: False Doc Required: False Backport Required: False Part: 1/1
- Loading branch information
Showing
11 changed files
with
472 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -410,3 +410,6 @@ DocGen/api/ | |
|
||
# Vim | ||
*.swp | ||
|
||
# Nitrocid Generators | ||
public/*/Generated/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
private/Nitrocid.Generators/Nitrocid.Generators.KnownAddons/KnownAddonInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// Nitrocid KS Copyright (C) 2018-2024 Aptivi | ||
// | ||
// This file is part of Nitrocid KS | ||
// | ||
// Nitrocid KS is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Nitrocid KS is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY, without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
// | ||
|
||
using Newtonsoft.Json; | ||
|
||
namespace Nitrocid.Generators.KnownAddons | ||
{ | ||
internal class KnownAddonInfo | ||
{ | ||
[JsonProperty("name")] | ||
public string Name { get; set; } = ""; | ||
|
||
[JsonProperty("display")] | ||
public string Display { get; set; } = ""; | ||
|
||
[JsonProperty("project")] | ||
public string Project { get; set; } = ""; | ||
} | ||
|
||
} |
185 changes: 185 additions & 0 deletions
185
private/Nitrocid.Generators/Nitrocid.Generators.KnownAddons/KnownAddonsGen.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
// | ||
// Nitrocid KS Copyright (C) 2018-2024 Aptivi | ||
// | ||
// This file is part of Nitrocid KS | ||
// | ||
// Nitrocid KS is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Nitrocid KS is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY, without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
// | ||
|
||
using Microsoft.CodeAnalysis; | ||
using Newtonsoft.Json; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Nitrocid.Generators.KnownAddons | ||
{ | ||
[Generator] | ||
public class KnownAddonsGen : ISourceGenerator | ||
{ | ||
private string knownAddons = ""; | ||
|
||
public void Execute(GeneratorExecutionContext context) | ||
{ | ||
// Get the data content | ||
var asm = typeof(KnownAddonsGen).Assembly; | ||
var stream = asm.GetManifestResourceStream($"{asm.GetName().Name}.Resources.KnownAddons.json"); | ||
using var reader = new StreamReader(stream); | ||
knownAddons = reader.ReadToEnd(); | ||
|
||
// Now, populate the enumerations and data properties | ||
PopulateEnums(context); | ||
PopulateData(context); | ||
} | ||
|
||
public void Initialize(GeneratorInitializationContext context) | ||
{ } | ||
|
||
private void PopulateData(GeneratorExecutionContext context) | ||
{ | ||
string header = | ||
$$""" | ||
// | ||
// Nitrocid KS Copyright (C) 2018-2024 Aptivi | ||
// | ||
// This file is part of Nitrocid KS | ||
// | ||
// Nitrocid KS is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Nitrocid KS is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY, without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
// | ||
|
||
// <auto-generated/> | ||
|
||
using System.Collections.Generic; | ||
|
||
namespace Nitrocid.Kernel.Extensions | ||
{ | ||
public static partial class InterAddonTranslations | ||
{ | ||
private static readonly Dictionary<KnownAddons, (string, string)> knownAddons = new() | ||
{ | ||
// Note: The names are not to be localized for usage with GetAddonName(), because they are constant addon names. | ||
|
||
"""; | ||
string footer = | ||
$$""" | ||
}; | ||
} | ||
} | ||
"""; | ||
var builder = new StringBuilder(header); | ||
|
||
// Read all the data | ||
var list = JsonConvert.DeserializeObject<KnownAddonInfo[]>(knownAddons); | ||
var names = list.Select((data) => data.Name).ToArray(); | ||
if (list is null) | ||
return; | ||
|
||
// Populate all the data properties | ||
foreach (var addonData in list) | ||
{ | ||
string name = addonData.Name; | ||
string display = addonData.Display; | ||
string project = addonData.Project; | ||
builder.AppendLine( | ||
$$""" | ||
{ KnownAddons.{{name}}, ("{{project}}", /* Localizable */ "{{display}}") }, | ||
""" | ||
); | ||
} | ||
builder.AppendLine(); | ||
|
||
// Add the source code to the compilation | ||
builder.AppendLine(footer); | ||
context.AddSource("InterAddonTranslations.g.cs", builder.ToString()); | ||
} | ||
|
||
private void PopulateEnums(GeneratorExecutionContext context) | ||
{ | ||
string header = | ||
$$""" | ||
// | ||
// Nitrocid KS Copyright (C) 2018-2024 Aptivi | ||
// | ||
// This file is part of Nitrocid KS | ||
// | ||
// Nitrocid KS is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Nitrocid KS is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY, without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
// | ||
|
||
// <auto-generated/> | ||
|
||
namespace Nitrocid.Kernel.Extensions | ||
{ | ||
/// <summary> | ||
/// Known addons list for inter-addon communication | ||
/// </summary> | ||
public enum KnownAddons | ||
{ | ||
|
||
"""; | ||
string footer = | ||
$$""" | ||
} | ||
} | ||
"""; | ||
var builder = new StringBuilder(header); | ||
|
||
// Read all the data | ||
var list = JsonConvert.DeserializeObject<KnownAddonInfo[]>(knownAddons); | ||
if (list is null) | ||
return; | ||
|
||
// Populate all the enumerations | ||
foreach (var addonData in list) | ||
{ | ||
string name = addonData.Name; | ||
string display = addonData.Display; | ||
string project = addonData.Project; | ||
builder.AppendLine( | ||
$$""" | ||
/// <summary> | ||
/// "{{display}}" from the Nitrocid.{{project}} addon project | ||
/// </summary> | ||
{{name}}, | ||
""" | ||
); | ||
} | ||
|
||
// Add the source code to the compilation | ||
builder.AppendLine(footer); | ||
context.AddSource("KnownAddons.cs", builder.ToString()); | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...itrocid.Generators/Nitrocid.Generators.KnownAddons/Nitrocid.Generators.KnownAddons.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules> | ||
<DefineConstants>GENERATOR</DefineConstants> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="[4.8.0]" PrivateAssets="all" /> | ||
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" PrivateAssets="all" /> | ||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" PrivateAssets="all" GeneratePathProperty="true" /> | ||
|
||
<PackageReference Remove="Microsoft.SourceLink.GitHub" /> | ||
</ItemGroup> | ||
|
||
<PropertyGroup> | ||
<GetTargetPathDependsOn>$(GetTargetPathDependsOn);GetDependencyTargetPaths</GetTargetPathDependsOn> | ||
</PropertyGroup> | ||
|
||
<Target Name="GetDependencyTargetPaths"> | ||
<ItemGroup> | ||
<TargetPathWithTargetPlatformMoniker Include="$(PKGNewtonsoft_Json)\lib\netstandard2.0\*.dll" IncludeRuntimeDependency="false" /> | ||
</ItemGroup> | ||
</Target> | ||
|
||
<ItemGroup> | ||
<EmbeddedResource Include="Resources\KnownAddons.json" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.