Skip to content

Commit

Permalink
Add dotnet tool ability to XMLtoMD proj (#157)
Browse files Browse the repository at this point in the history
* Modify to run with .net5.0 #WIP

- upgraded from .netcore3.1 to .net5.0
- suppressed warning syslib0012
Will need to address https://docs.microsoft.com/en-us/dotnet/core/compatibility/syslib-warnings/syslib0012
Most likely by using Assembly.Location

* Add pack ability

- added XML nodes for ability to pack and distribute the application as a nupkg

* Add nupkg tool

* add DragonFruit cli tool

* dotnet 5 and added dragonfruit command line for running locally.

* minor format cleaning

* .netcore3.1

.Net 5.0 upgrade will be coming in the future

* Apply suggestions from code review

Co-authored-by: Kevin B <Keboo@users.noreply.github.com>

* revisions based on Kevin's Comments

* A little code cleanup to take more advantage of DragonFruit

Co-authored-by: twofingerrightclick <austensaffron@gmail.com>
Co-authored-by: Kevin B <Keboo@users.noreply.github.com>
Co-authored-by: Kevin Bost <kitokeboo@gmail.com>
  • Loading branch information
4 people authored Apr 7, 2021
1 parent bdb47ed commit 9dd61df
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ConvertGuidelinesXmlToMarkdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- name: restore_compile_run_createMD
run: |
dotnet run --configuration Release --project ./XMLtoMD/GuidelineXmlToMD/GuidelineXmlToMD.csproj
./XMLtoMD/GuidelineXmlToMD/bin/Release/netcoreapp3.1/GuidelineXmlToMD "${{ env.XmlFileName }}"
-- --xml-input-file "./docs/${{ env.XmlFileName }}" --markdown-output-file "./docs/coding/csharp.md"
if: ${{ steps.diff.outputs.modified == 'true' }}

- name: Create commit and push to CodingGuideLinesMDUpdate
Expand Down
12 changes: 12 additions & 0 deletions XMLtoMD/GuidelineXmlToMD/.config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"guidelinexmltomd": {
"version": "1.0.0",
"commands": [
"XMLtoMD"
]
}
}
}
2 changes: 1 addition & 1 deletion XMLtoMD/GuidelineXmlToMD/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file is used by Code Analysis to maintain SuppressMessage
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.
Expand Down
2 changes: 1 addition & 1 deletion XMLtoMD/GuidelineXmlToMD/Guideline.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;


namespace GuidelineXmlToMD
Expand Down
15 changes: 11 additions & 4 deletions XMLtoMD/GuidelineXmlToMD/GuidelineXmlToMD.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>9.0</LangVersion>
<PackAsTool>true</PackAsTool>
<ToolCommandName>IntelliTect.EssentialCSharp.Publishing</ToolCommandName>
<PackageOutputPath>./nupkg</PackageOutputPath>
</PropertyGroup>

<ItemGroup>
<Folder Include="MarkdownOut\" />
</ItemGroup>

<PropertyGroup>
<NoWarn>1591</NoWarn>
<Version>1.0.0</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <!-- #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member -->
</PropertyGroup>

<ItemGroup>
<PackageReference Include="IntelliTect.Analyzers" Version="0.1.8" />
<PackageReference Include="System.CommandLine.DragonFruit" Version="0.3.0-alpha.20574.7" />
</ItemGroup>

</Project>
7 changes: 7 additions & 0 deletions XMLtoMD/GuidelineXmlToMD/GuidelineXmlToMD.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ VisualStudioVersion = 16.0.30225.117
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GuidelineXmlToMD", "GuidelineXmlToMD.csproj", "{D9C7CC15-01DB-46FE-922A-6EB41CE1759B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2D6BFDEE-B212-4BD3-A8D4-750F9BF9ACDE}"
ProjectSection(SolutionItems) = preProject
..\..\.github\workflows\ConvertGuidelinesXmlToMarkdown.yml = ..\..\.github\workflows\ConvertGuidelinesXmlToMarkdown.yml
..\..\docs\coding\csharp.md = ..\..\docs\coding\csharp.md
..\..\docs\Guidelines(8th Edition).xml = ..\..\docs\Guidelines(8th Edition).xml
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
2 changes: 1 addition & 1 deletion XMLtoMD/GuidelineXmlToMD/MarkdownOut/MdText.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Text.RegularExpressions;

namespace MarkdownOut {
Expand Down
4 changes: 2 additions & 2 deletions XMLtoMD/GuidelineXmlToMD/MarkdownOut/MdWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public void Write(object output, MdStyle style = MdStyle.None,
/// breaks to maintain the assumed intended line breaks in the text; otherwise, the text's
/// newlines will not parsed as line breaks by Markdown parsers.
/// </param>
/// <param name="numNewLines">Optional number of new lines to add after each list element</param>
public void WriteLine(object output, MdStyle style = MdStyle.None,
MdFormat format = MdFormat.None, bool useMdLineBreaks = true, int numNewLines = 2) {
string text = MdText.StyleAndFormat(output, style, format);
Expand Down Expand Up @@ -125,9 +126,8 @@ public void WriteLineSingle(object output, MdStyle style = MdStyle.None,
/// create a sublist, etc). Negative values are ignored.
/// </param>
/// <param name="style">The optional Markdown style to apply.</param>

/// <param name="format">The optional Markdown format to apply.</param>
/// </param>
/// <param name="numNewLines">Optional number of new lines to add after each list element</param>
public void WriteUnorderedListItem(object output, int listIndent = 0,
MdStyle style = MdStyle.None, MdFormat format = MdFormat.None, int numNewLines=1) {
string text = MdText.Format(output, format);
Expand Down
112 changes: 45 additions & 67 deletions XMLtoMD/GuidelineXmlToMD/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.CommandLine;
using System.CommandLine.IO;
using System.IO;
using System.Linq;
using System.Reflection;
Expand All @@ -11,54 +13,49 @@ namespace GuidelineXmlToMD
{
class Program
{
static MarkdownOut.MdWriter _MdWriter;
static void Main(string[] args)
/// <summary>
/// A simple tool to convert coding guidelines xml to the website formatted markdown.
/// </summary>
/// <param name="xmlInputFile">The xml file to process.</param>
/// <param name="markdownOutputFile">The md file to create.</param>
/// <param name="console">Injected by System.CommandLine</param>
static void Main(FileInfo xmlInputFile, FileInfo markdownOutputFile, IConsole console)
{
string xmlFileName = "Guidelines(8th Edition).xml";
if (args.Length != 0) { //check for input fileName
if (Regex.Match(args[0], @".*.xml").Success) {
xmlFileName = args[0];
}
if (console is null)
{
throw new ArgumentNullException(nameof(console));
}

Match repoRefFolder = Regex.Match(AssemblyDirectory, @$".*CodingGuidelines");

string[] xmlFilePath = { repoRefFolder.Value, "docs", xmlFileName};
ICollection<Guideline> guidelines = GuidelineXmlFileReader.ReadExisitingGuidelinesFile(Path.Combine(xmlFilePath));


string mdFileName = "csharp.md";
string[] mdFilePath = { repoRefFolder.Value, "docs", "coding", mdFileName};

using (_MdWriter = new MdWriter(Path.Combine(mdFilePath)))
if (!xmlInputFile.Exists)
{


_MdWriter.WriteLine("C# Guidelines", format: MdFormat.Heading1);
PrintSections(guidelines);
_MdWriter.WriteLine("Guidelines", format: MdFormat.Heading1);
_MdWriter.WriteLine("");
PrintGuidelinesBySection(guidelines);
throw new FileNotFoundException("Could not find input file", xmlInputFile.FullName);
}



string markDownOutputFilePath = markdownOutputFile.FullName;
string xmlInputFilePath = xmlInputFile.FullName;

//C: \Users\saffron\source\repos\CodingGuidelines\XMLtoMD\GuidelineXmlToMD\bin\Debug\netcoreapp3.1
//C: \Users\saffron\source\repos\CodingGuidelines\docs
console.Out.WriteLine($"Converting {xmlInputFilePath} to {markDownOutputFilePath}");

ICollection<Guideline> guidelines = GuidelineXmlFileReader.ReadExisitingGuidelinesFile(xmlInputFilePath);

using var mdWriter = new MdWriter(markDownOutputFilePath);
mdWriter.WriteLine("C# Guidelines", format: MdFormat.Heading1);
PrintSections(guidelines, mdWriter, console);
mdWriter.WriteLine("Guidelines", format: MdFormat.Heading1);
mdWriter.WriteLine("");
PrintGuidelinesBySection(guidelines, mdWriter, console);
}

private static void PrintGuidelinesBySection(ICollection<Guideline> guidelines)
private static void PrintGuidelinesBySection(
ICollection<Guideline> guidelines,
MdWriter mdWriter,
IConsole console)
{
foreach (string section in GetSections(guidelines))
{
_MdWriter.WriteLine("");
Console.WriteLine(section);
_MdWriter.WriteLine(section, format: MdFormat.Heading2,style: MdStyle.BoldItalic);


mdWriter.WriteLine("");
console.Out.WriteLine(section);
mdWriter.WriteLine(section, format: MdFormat.Heading2, style: MdStyle.BoldItalic);

IEnumerable<Guideline> guidelinesInSections = (from guideline in guidelines
where string.Equals(guideline.Section, section, StringComparison.OrdinalIgnoreCase)
Expand All @@ -73,15 +70,15 @@ where string.Equals(guideline.Subsection, subsection, StringComparison.OrdinalIg

if (guidelinesInSubsection.Any())
{
Console.WriteLine($" { subsection}");
_MdWriter.WriteLine(subsection, format: MdFormat.Heading3, numNewLines: 1);
console.Out.WriteLine($" { subsection}");
mdWriter.WriteLine(subsection, format: MdFormat.Heading3, numNewLines: 1);

foreach (Guideline guideline in guidelinesInSubsection)
{
_MdWriter.WriteUnorderedListItem(GetGuidelineEmoji(guideline) + " " + guideline.Text.Trim('"'), listIndent: 0);
mdWriter.WriteUnorderedListItem(GetGuidelineEmoji(guideline) + " " + guideline.Text.Trim('"'), listIndent: 0);
}
}
_MdWriter.WriteLine("", numNewLines: 1);
mdWriter.WriteLine("", numNewLines: 1);

}
}
Expand Down Expand Up @@ -111,18 +108,21 @@ private static string GetGuidelineEmoji(Guideline guideline)
return emoji;
}

private static void PrintSections(ICollection<Guideline> guidelines)
private static void PrintSections(
ICollection<Guideline> guidelines,
MdWriter mdWriter,
IConsole console)
{
_MdWriter.WriteLine("Sections", format: MdFormat.Heading2);
mdWriter.WriteLine("Sections", format: MdFormat.Heading2);

List<string> subSections = new List<string>();

List<string> sections = GetSections(guidelines);
foreach (string section in sections)
{
Console.WriteLine(section);
console.Out.WriteLine(section);

_MdWriter.WriteUnorderedListItem(section, format: MdFormat.InternalLink, listIndent: 0);
mdWriter.WriteUnorderedListItem(section, format: MdFormat.InternalLink, listIndent: 0);


subSections = (from guideline in guidelines
Expand All @@ -131,17 +131,11 @@ where string.Equals(guideline.Section, section, System.StringComparison.OrdinalI

foreach (string subsection in subSections)
{
Console.WriteLine($" { subsection}");
_MdWriter.WriteUnorderedListItem(subsection, format: MdFormat.InternalLink, listIndent: 1);
console.Out.WriteLine($" { subsection}");
mdWriter.WriteUnorderedListItem(subsection, format: MdFormat.InternalLink, listIndent: 1);
}
_MdWriter.WriteLine("", numNewLines: 1);



mdWriter.WriteLine("", numNewLines: 1);
}



}

public static List<string> GetSections(ICollection<Guideline> guidelines)
Expand All @@ -159,21 +153,5 @@ public static List<string> GetSubSections(ICollection<Guideline> guidelines)
select guideline.Subsection).Distinct().OrderBy(x => x).ToList();
return subSections;
}

public static string AssemblyDirectory
{
get
{
string codeBase = Assembly.GetExecutingAssembly().CodeBase;
UriBuilder uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
return Path.GetDirectoryName(path);
}
}
}





}
8 changes: 8 additions & 0 deletions XMLtoMD/GuidelineXmlToMD/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"GuidelineXmlToMD": {
"commandName": "Project",
"commandLineArgs": "--xml-input-file \"..\\..\\..\\..\\..\\docs\\Guidelines(8th Edition).xml\" --markdown-output-file \"..\\..\\..\\..\\..\\docs\\coding\\csharp.md\""
}
}
}

0 comments on commit 9dd61df

Please sign in to comment.