From 259013d81a0005bc7d60ba618ac996eb0360ca75 Mon Sep 17 00:00:00 2001 From: "Goughnour, Erik" Date: Tue, 12 Sep 2017 09:13:17 -0500 Subject: [PATCH 01/15] Added MSBuild task Added Task. Included file merge also. --- .../GenerateMarkdown.cs | 138 ++++++++++++++++++ .../Properties/AssemblyInfo.cs | 36 +++++ ...XmlCommentMarkDownGenerator.MSBuild.csproj | 56 +++++++ XmlCommentMarkDownGenerator.sln | 10 +- 4 files changed, 238 insertions(+), 2 deletions(-) create mode 100644 PxtlCa.XmlCommentMarkDownGenerator.MSBuild/GenerateMarkdown.cs create mode 100644 PxtlCa.XmlCommentMarkDownGenerator.MSBuild/Properties/AssemblyInfo.cs create mode 100644 PxtlCa.XmlCommentMarkDownGenerator.MSBuild/PxtlCa.XmlCommentMarkDownGenerator.MSBuild.csproj diff --git a/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/GenerateMarkdown.cs b/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/GenerateMarkdown.cs new file mode 100644 index 0000000..122f754 --- /dev/null +++ b/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/GenerateMarkdown.cs @@ -0,0 +1,138 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +//using System.Threading.Tasks; +using Microsoft.Build.Framework; +using Microsoft.Build.Utilities; +using System.IO; +using System.Xml.Linq; + +namespace PxtlCa.XmlCommentMarkDownGenerator.MSBuild +{ + public class GenerateMarkdown : Task + { + [Required] + public ITaskItem[] InputXml { get; set; } + + [Required] + public ITaskItem DocumentationPath { get; set; } + + [Required] + public bool MergeFiles { get; set; } + + public ITaskItem OutputFile { get; set; } + + + + + public override bool Execute() + { + if(InputXml.Length == 0) + { + Log.LogError("InputXml cannot be empty"); + } + else if(MergeFiles && (null == OutputFile)) + { + Log.LogError("OutputFile must be specified if input files are merged"); + } + else if(DocumentationPathIsFile && InputXml.Length != 1) + { + Log.LogError("DocumentationPath must specify a directory is more than one input XML value is supplied"); + } + else + { + try + { + CreateDirectoryIfNeeded(); + GenerateFiles(); + if(MergeFiles) + { + Merge(); + } + return true; + } + catch(Exception ex) + { + Log.LogErrorFromException(ex); + } + } + return false; + } + + private void Merge() + { + //get all md files in Documentation Path + //except those generated in this task + var otherMDFiles = Directory.EnumerateFiles(DocumentationPath.ItemSpec, "*.md", SearchOption.AllDirectories).ToList(); + otherMDFiles = otherMDFiles.Except(GeneratedMDFiles).ToList(); + var mergeInto = otherMDFiles.FirstOrDefault(); + if(null == mergeInto) + { + mergeInto = GeneratedMDFiles.First(); + File.Copy(mergeInto, OutputFile.ItemSpec, true); + foreach(var mdFile in GeneratedMDFiles.Skip(1)) + { + File.AppendAllText(OutputFile.ItemSpec, Environment.NewLine); + File.AppendAllText(OutputFile.ItemSpec, File.ReadAllText(mdFile)); + } + } + else if(otherMDFiles.Count > 1) + { + File.Copy(mergeInto, OutputFile.ItemSpec, true); + foreach (var mdFile in otherMDFiles.Skip(1)) + { + File.AppendAllText(OutputFile.ItemSpec, Environment.NewLine); + File.AppendAllText(OutputFile.ItemSpec, File.ReadAllText(mdFile)); + } + foreach(var mdFile in GeneratedMDFiles) + { + File.AppendAllText(OutputFile.ItemSpec, Environment.NewLine); + File.AppendAllText(OutputFile.ItemSpec, File.ReadAllText(mdFile)); + } + } + } + + private void GenerateFiles() + { + foreach (var inputFile in InputXml) + { + var mdOutput = OutputPath(inputFile.ItemSpec); + GeneratedMDFiles.Add(mdOutput); + var sr = new StreamReader(inputFile.ItemSpec); + using (var sw = new StreamWriter(mdOutput)) + { + var xml = sr.ReadToEnd(); + var doc = XDocument.Parse(xml); + var md = doc.Root.ToMarkDown(); + sw.Write(md); + sw.Close(); + } + } + } + + private string OutputPath(string inputXml) + { + if (DocumentationPathIsFile) + { + return DocumentationPath.ItemSpec; + } + return $@"{DocumentationPath.ItemSpec}\{inputXml.Replace(".xml", ".md")}"; + } + + private bool DocumentationPathIsFile + { + get { return File.Exists(DocumentationPath.ItemSpec); } + } + + public List GeneratedMDFiles { get; private set; } = new List(); + + private void CreateDirectoryIfNeeded() + { + if ((!DocumentationPathIsFile) && (!Directory.Exists(DocumentationPath.ItemSpec))) + { + Directory.CreateDirectory(DocumentationPath.ItemSpec); + } + } + } +} diff --git a/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/Properties/AssemblyInfo.cs b/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..fababd2 --- /dev/null +++ b/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("PxtlCa.XmlCommentMarkDownGenerator.MSBuild")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("PxtlCa.XmlCommentMarkDownGenerator.MSBuild")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("9fcee209-508f-474e-80c2-d0966e4aa126")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/PxtlCa.XmlCommentMarkDownGenerator.MSBuild.csproj b/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/PxtlCa.XmlCommentMarkDownGenerator.MSBuild.csproj new file mode 100644 index 0000000..7137b43 --- /dev/null +++ b/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/PxtlCa.XmlCommentMarkDownGenerator.MSBuild.csproj @@ -0,0 +1,56 @@ + + + + + Debug + AnyCPU + {9FCEE209-508F-474E-80C2-D0966E4AA126} + Library + Properties + PxtlCa.XmlCommentMarkDownGenerator.MSBuild + PxtlCa.XmlCommentMarkDownGenerator.MSBuild + v4.5.2 + 512 + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + {1375dc94-03f8-496c-981c-d5d6e1b0fd26} + PxtlCa.XmlCommentMarkDownGenerator + + + + \ No newline at end of file diff --git a/XmlCommentMarkDownGenerator.sln b/XmlCommentMarkDownGenerator.sln index a3870bb..942b813 100644 --- a/XmlCommentMarkDownGenerator.sln +++ b/XmlCommentMarkDownGenerator.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.24720.0 +# Visual Studio 15 +VisualStudioVersion = 15.0.26430.16 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{9CB54D49-0D43-462C-B250-38BEB7F38312}" ProjectSection(SolutionItems) = preProject @@ -17,6 +17,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PxtlCa.XmlCommentMarkDownGe EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PxtlCa.XmlCommentMarkDownGenerator.Test", "PxtlCa.XmlCommentMarkDownGenerator.Test\PxtlCa.XmlCommentMarkDownGenerator.Test.csproj", "{7993D07F-7F81-477E-ABA1-E3E6DC5CAB6A}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PxtlCa.XmlCommentMarkDownGenerator.MSBuild", "PxtlCa.XmlCommentMarkDownGenerator.MSBuild\PxtlCa.XmlCommentMarkDownGenerator.MSBuild.csproj", "{9FCEE209-508F-474E-80C2-D0966E4AA126}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -31,6 +33,10 @@ Global {7993D07F-7F81-477E-ABA1-E3E6DC5CAB6A}.Debug|Any CPU.Build.0 = Debug|Any CPU {7993D07F-7F81-477E-ABA1-E3E6DC5CAB6A}.Release|Any CPU.ActiveCfg = Release|Any CPU {7993D07F-7F81-477E-ABA1-E3E6DC5CAB6A}.Release|Any CPU.Build.0 = Release|Any CPU + {9FCEE209-508F-474E-80C2-D0966E4AA126}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9FCEE209-508F-474E-80C2-D0966E4AA126}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9FCEE209-508F-474E-80C2-D0966E4AA126}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9FCEE209-508F-474E-80C2-D0966E4AA126}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 8fd2049685bc7598c209079e79a37c8e27c4e81c Mon Sep 17 00:00:00 2001 From: "Goughnour, Erik" Date: Tue, 12 Sep 2017 10:18:48 -0500 Subject: [PATCH 02/15] Added Unit Test for Task added mock build engine and real TaskItem instances to a test on the new task. --- .../GenerateMarkdown.cs | 28 ++++++- ...XmlCommentMarkDownGenerator.MSBuild.csproj | 1 + .../BuildEngine.cs | 48 +++++++++++ .../Properties/AssemblyInfo.cs | 20 +++++ ...mmentMarkdownGenerator.MSBuild.Test.csproj | 83 +++++++++++++++++++ .../packages.config | 6 ++ XmlCommentMarkDownGenerator.sln | 6 ++ 7 files changed, 190 insertions(+), 2 deletions(-) create mode 100644 PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/BuildEngine.cs create mode 100644 PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/Properties/AssemblyInfo.cs create mode 100644 PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test.csproj create mode 100644 PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/packages.config diff --git a/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/GenerateMarkdown.cs b/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/GenerateMarkdown.cs index 122f754..4ac98b2 100644 --- a/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/GenerateMarkdown.cs +++ b/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/GenerateMarkdown.cs @@ -10,22 +10,43 @@ namespace PxtlCa.XmlCommentMarkDownGenerator.MSBuild { + /// + /// A task that generates and optionally merges markdown + /// public class GenerateMarkdown : Task { + /// + /// The file(s) from which to generate markdown. This should be in XmlDocumentation format. + /// [Required] public ITaskItem[] InputXml { get; set; } + /// + /// DocumentationPath is the top level directory in which to search for files. + /// It is also the path where generated markdown files are created. + /// [Required] public ITaskItem DocumentationPath { get; set; } + /// + /// Whether the generated markdown files should merge. Only valid if multiple markdown files exist. + /// DocumentationPath is the top level directory in which to search for files. + /// Both existing markdown files and the generated files are merged. + /// [Required] public bool MergeFiles { get; set; } + /// + /// The file to be created by the merge. Unused if MergeFiles evaluates to false. + /// public ITaskItem OutputFile { get; set; } - + /// + /// Runs the task as configured + /// + /// true if task has succeeded public override bool Execute() { if(InputXml.Length == 0) @@ -117,7 +138,7 @@ private string OutputPath(string inputXml) { return DocumentationPath.ItemSpec; } - return $@"{DocumentationPath.ItemSpec}\{inputXml.Replace(".xml", ".md")}"; + return $@"{DocumentationPath.ItemSpec}\{Path.GetFileNameWithoutExtension(inputXml)}.md"; } private bool DocumentationPathIsFile @@ -125,6 +146,9 @@ private bool DocumentationPathIsFile get { return File.Exists(DocumentationPath.ItemSpec); } } + /// + /// The files generated during execution of the task + /// public List GeneratedMDFiles { get; private set; } = new List(); private void CreateDirectoryIfNeeded() diff --git a/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/PxtlCa.XmlCommentMarkDownGenerator.MSBuild.csproj b/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/PxtlCa.XmlCommentMarkDownGenerator.MSBuild.csproj index 7137b43..7de077a 100644 --- a/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/PxtlCa.XmlCommentMarkDownGenerator.MSBuild.csproj +++ b/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/PxtlCa.XmlCommentMarkDownGenerator.MSBuild.csproj @@ -21,6 +21,7 @@ DEBUG;TRACE prompt 4 + bin\Debug\PxtlCa.XmlCommentMarkDownGenerator.MSBuild.xml pdbonly diff --git a/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/BuildEngine.cs b/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/BuildEngine.cs new file mode 100644 index 0000000..777daa8 --- /dev/null +++ b/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/BuildEngine.cs @@ -0,0 +1,48 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.Build.Framework; +using Microsoft.Build.Tasks; +using Microsoft.Build.Utilities; +using PxtlCa.XmlCommentMarkdownGenerator; +using PxtlCa.XmlCommentMarkDownGenerator.MSBuild; +using Rhino.Mocks; + +namespace PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test +{ + [TestClass] + public class BuildEngine + { + [TestMethod] + public void ExecuteMerge() + { + var mockRepo = new MockRepository(); + var buildEngine = mockRepo.Stub(); + + var inputPath = @"bin\Debug\PxtlCa.XmlCommentMarkDownGenerator.MSBuild.xml"; + //get relative path here + //1. get current directory + //2. find PxtlCa.XmlCommentMarkDownGenerator.MSBuild.xml in the file system. + //3. adjust relative path until File.Exists(inputPath) + + //then adjust the path and doc path, output file, etc. + var docPath = @"..\Docs"; + var outputFile = new TaskItem("Readme.md"); + + + var inputXml = new ITaskItem[] { new TaskItem(inputPath) }; + var documentPath = new TaskItem(docPath); + var merge = true; + + var task = new GenerateMarkdown + { + BuildEngine = buildEngine, + DocumentationPath = documentPath, + InputXml = inputXml, + MergeFiles = merge, + OutputFile = outputFile + }; + + task.Execute(); + } + } +} diff --git a/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/Properties/AssemblyInfo.cs b/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..734583c --- /dev/null +++ b/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/Properties/AssemblyInfo.cs @@ -0,0 +1,20 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: ComVisible(false)] + +[assembly: Guid("2358183d-b57c-467d-b89c-16c6be040753")] + +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test.csproj b/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test.csproj new file mode 100644 index 0000000..f6761b9 --- /dev/null +++ b/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test.csproj @@ -0,0 +1,83 @@ + + + + + Debug + AnyCPU + {2358183D-B57C-467D-B89C-16C6BE040753} + Library + Properties + PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test + PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test + v4.5.2 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 15.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + ..\packages\MSTest.TestFramework.1.1.11\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + + + ..\packages\MSTest.TestFramework.1.1.11\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + + + ..\packages\RhinoMocks.3.6.1\lib\net\Rhino.Mocks.dll + + + + + + + + + + + + + + {9fcee209-508f-474e-80c2-d0966e4aa126} + PxtlCa.XmlCommentMarkDownGenerator.MSBuild + + + {1375dc94-03f8-496c-981c-d5d6e1b0fd26} + PxtlCa.XmlCommentMarkDownGenerator + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + \ No newline at end of file diff --git a/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/packages.config b/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/packages.config new file mode 100644 index 0000000..5930689 --- /dev/null +++ b/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/packages.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/XmlCommentMarkDownGenerator.sln b/XmlCommentMarkDownGenerator.sln index 942b813..cd6610d 100644 --- a/XmlCommentMarkDownGenerator.sln +++ b/XmlCommentMarkDownGenerator.sln @@ -19,6 +19,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PxtlCa.XmlCommentMarkDownGe EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PxtlCa.XmlCommentMarkDownGenerator.MSBuild", "PxtlCa.XmlCommentMarkDownGenerator.MSBuild\PxtlCa.XmlCommentMarkDownGenerator.MSBuild.csproj", "{9FCEE209-508F-474E-80C2-D0966E4AA126}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test", "PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test\PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test.csproj", "{2358183D-B57C-467D-B89C-16C6BE040753}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -37,6 +39,10 @@ Global {9FCEE209-508F-474E-80C2-D0966E4AA126}.Debug|Any CPU.Build.0 = Debug|Any CPU {9FCEE209-508F-474E-80C2-D0966E4AA126}.Release|Any CPU.ActiveCfg = Release|Any CPU {9FCEE209-508F-474E-80C2-D0966E4AA126}.Release|Any CPU.Build.0 = Release|Any CPU + {2358183D-B57C-467D-B89C-16C6BE040753}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2358183D-B57C-467D-B89C-16C6BE040753}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2358183D-B57C-467D-B89C-16C6BE040753}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2358183D-B57C-467D-B89C-16C6BE040753}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 87a8c96be7599f0b95ef5097e5e3bfce9d66f24a Mon Sep 17 00:00:00 2001 From: "Goughnour, Erik" Date: Tue, 12 Sep 2017 10:49:55 -0500 Subject: [PATCH 03/15] Updated paths. Test Passes Test Passes. --- .../GenerateMarkdown.cs | 10 ++-- .../BuildEngine.cs | 17 +++--- .../Docs/Notes.md | 1 + ...lCa.XmlCommentMarkDownGenerator.MSBuild.md | 55 ++++++++++++++++++ .../Readme.md | 57 +++++++++++++++++++ 5 files changed, 126 insertions(+), 14 deletions(-) create mode 100644 PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/Docs/Notes.md create mode 100644 PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/Docs/PxtlCa.XmlCommentMarkDownGenerator.MSBuild.md create mode 100644 PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/Readme.md diff --git a/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/GenerateMarkdown.cs b/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/GenerateMarkdown.cs index 4ac98b2..60e6c52 100644 --- a/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/GenerateMarkdown.cs +++ b/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/GenerateMarkdown.cs @@ -88,25 +88,25 @@ private void Merge() var otherMDFiles = Directory.EnumerateFiles(DocumentationPath.ItemSpec, "*.md", SearchOption.AllDirectories).ToList(); otherMDFiles = otherMDFiles.Except(GeneratedMDFiles).ToList(); var mergeInto = otherMDFiles.FirstOrDefault(); - if(null == mergeInto) + if (null == mergeInto) { mergeInto = GeneratedMDFiles.First(); File.Copy(mergeInto, OutputFile.ItemSpec, true); - foreach(var mdFile in GeneratedMDFiles.Skip(1)) + foreach (var mdFile in GeneratedMDFiles.Skip(1)) { File.AppendAllText(OutputFile.ItemSpec, Environment.NewLine); File.AppendAllText(OutputFile.ItemSpec, File.ReadAllText(mdFile)); } } - else if(otherMDFiles.Count > 1) + else { - File.Copy(mergeInto, OutputFile.ItemSpec, true); + File.Copy(mergeInto, OutputFile.ItemSpec, true); foreach (var mdFile in otherMDFiles.Skip(1)) { File.AppendAllText(OutputFile.ItemSpec, Environment.NewLine); File.AppendAllText(OutputFile.ItemSpec, File.ReadAllText(mdFile)); } - foreach(var mdFile in GeneratedMDFiles) + foreach (var mdFile in GeneratedMDFiles) { File.AppendAllText(OutputFile.ItemSpec, Environment.NewLine); File.AppendAllText(OutputFile.ItemSpec, File.ReadAllText(mdFile)); diff --git a/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/BuildEngine.cs b/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/BuildEngine.cs index 777daa8..2aa510b 100644 --- a/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/BuildEngine.cs +++ b/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/BuildEngine.cs @@ -18,15 +18,9 @@ public void ExecuteMerge() var mockRepo = new MockRepository(); var buildEngine = mockRepo.Stub(); - var inputPath = @"bin\Debug\PxtlCa.XmlCommentMarkDownGenerator.MSBuild.xml"; - //get relative path here - //1. get current directory - //2. find PxtlCa.XmlCommentMarkDownGenerator.MSBuild.xml in the file system. - //3. adjust relative path until File.Exists(inputPath) - - //then adjust the path and doc path, output file, etc. - var docPath = @"..\Docs"; - var outputFile = new TaskItem("Readme.md"); + var inputPath = @"..\..\..\PxtlCa.XmlCommentMarkdownGenerator.MSBuild\bin\Debug\PxtlCa.XmlCommentMarkDownGenerator.MSBuild.xml"; + var docPath = @"..\..\Docs"; + var outputFile = new TaskItem(@"..\..\Readme.md"); var inputXml = new ITaskItem[] { new TaskItem(inputPath) }; @@ -43,6 +37,11 @@ public void ExecuteMerge() }; task.Execute(); + + var expectFileExists = true; + var fileActuallyExists = System.IO.File.Exists(outputFile.ItemSpec); + + Assert.AreEqual(expectFileExists, fileActuallyExists); } } } diff --git a/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/Docs/Notes.md b/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/Docs/Notes.md new file mode 100644 index 0000000..b81254f --- /dev/null +++ b/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/Docs/Notes.md @@ -0,0 +1 @@ +## No Documentation Yet Authored diff --git a/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/Docs/PxtlCa.XmlCommentMarkDownGenerator.MSBuild.md b/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/Docs/PxtlCa.XmlCommentMarkDownGenerator.MSBuild.md new file mode 100644 index 0000000..7c6b41c --- /dev/null +++ b/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/Docs/PxtlCa.XmlCommentMarkDownGenerator.MSBuild.md @@ -0,0 +1,55 @@ +# PxtlCa.XmlCommentMarkDownGenerator.MSBuild # + +## Type GenerateMarkdown + + A task that generates and optionally merges markdown + + + +--- +#### Property GenerateMarkdown.InputXml + + The file(s) from which to generate markdown. This should be in XmlDocumentation format. + + + +--- +#### Property GenerateMarkdown.DocumentationPath + + DocumentationPath is the top level directory in which to search for files. It is also the path where generated markdown files are created. + + + +--- +#### Property GenerateMarkdown.MergeFiles + + Whether the generated markdown files should merge. Only valid if multiple markdown files exist. DocumentationPath is the top level directory in which to search for files. Both existing markdown files and the generated files are merged. + + + +--- +#### Property GenerateMarkdown.OutputFile + + The file to be created by the merge. Unused if MergeFiles evaluates to false. + + + +--- +#### Method GenerateMarkdown.Execute + + Runs the task as configured + +**Returns**: true if task has succeeded + + + +--- +#### Property GenerateMarkdown.GeneratedMDFiles + + The files generated during execution of the task + + + +--- + + diff --git a/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/Readme.md b/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/Readme.md new file mode 100644 index 0000000..5e785e4 --- /dev/null +++ b/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/Readme.md @@ -0,0 +1,57 @@ +## No Documentation Yet Authored + +# PxtlCa.XmlCommentMarkDownGenerator.MSBuild # + +## Type GenerateMarkdown + + A task that generates and optionally merges markdown + + + +--- +#### Property GenerateMarkdown.InputXml + + The file(s) from which to generate markdown. This should be in XmlDocumentation format. + + + +--- +#### Property GenerateMarkdown.DocumentationPath + + DocumentationPath is the top level directory in which to search for files. It is also the path where generated markdown files are created. + + + +--- +#### Property GenerateMarkdown.MergeFiles + + Whether the generated markdown files should merge. Only valid if multiple markdown files exist. DocumentationPath is the top level directory in which to search for files. Both existing markdown files and the generated files are merged. + + + +--- +#### Property GenerateMarkdown.OutputFile + + The file to be created by the merge. Unused if MergeFiles evaluates to false. + + + +--- +#### Method GenerateMarkdown.Execute + + Runs the task as configured + +**Returns**: true if task has succeeded + + + +--- +#### Property GenerateMarkdown.GeneratedMDFiles + + The files generated during execution of the task + + + +--- + + From fba7a28d142352d325bd098935653cc0f1816c6c Mon Sep 17 00:00:00 2001 From: "Goughnour, Erik" Date: Tue, 12 Sep 2017 12:19:36 -0500 Subject: [PATCH 04/15] Simplified AfterBuild Target Added custom task to .targets file. Removed redundant elements of target. --- PxtlCa.XmlCommentMarkDownGenerator.targets | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/PxtlCa.XmlCommentMarkDownGenerator.targets b/PxtlCa.XmlCommentMarkDownGenerator.targets index 1d94f3c..cccee8c 100644 --- a/PxtlCa.XmlCommentMarkDownGenerator.targets +++ b/PxtlCa.XmlCommentMarkDownGenerator.targets @@ -1,20 +1,17 @@ + - - - \ No newline at end of file From 0735a7b9e124f061a053d72b68317d31b1d01577 Mon Sep 17 00:00:00 2001 From: "Goughnour, Erik" Date: Tue, 12 Sep 2017 12:32:17 -0500 Subject: [PATCH 05/15] Updating .Nuspec updated nuspec. Should point files back to tools directory though. --- PxtlCa.XmlCommentMarkDownGenerator.nuspec | 35 ++++++++++++----------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/PxtlCa.XmlCommentMarkDownGenerator.nuspec b/PxtlCa.XmlCommentMarkDownGenerator.nuspec index fff99a6..8c1ef42 100644 --- a/PxtlCa.XmlCommentMarkDownGenerator.nuspec +++ b/PxtlCa.XmlCommentMarkDownGenerator.nuspec @@ -1,20 +1,21 @@  - - PxtlCa.XmlCommentMarkDownGenerator - 0.2.6130.564 - PxtlCa.XmlCommentMarkDownGenerator - Martin Zarate - https://opensource.org/licenses/MIT - https://github.com/Pxtl/XmlCommentMarkDownGenerator - false - Convert Visual Studio generated XML Comment XML files into Github-flavoured MarkDown. - Guide available at https://github.com/Pxtl/XmlCommentMarkDownGenerator/blob/master/README.md - 2016 Martin Zarate - - - - - - + + PxtlCa.XmlCommentMarkDownGenerator + 0.2.6130.564 + PxtlCa.XmlCommentMarkDownGenerator + Martin Zarate + https://opensource.org/licenses/MIT + https://github.com/Pxtl/XmlCommentMarkDownGenerator + false + Convert Visual Studio generated XML Comment XML files into Github-flavoured MarkDown. + Guide available at https://github.com/Pxtl/XmlCommentMarkDownGenerator/blob/master/README.md + 2016 Martin Zarate + + + + + + + \ No newline at end of file From 38088a8aff405d706353a647726917a6d04493b8 Mon Sep 17 00:00:00 2001 From: "Goughnour, Erik" Date: Tue, 12 Sep 2017 12:49:57 -0500 Subject: [PATCH 06/15] nuspec and targets changes slight changes to paths. --- PxtlCa.XmlCommentMarkDownGenerator.nuspec | 36 +++++++++++----------- PxtlCa.XmlCommentMarkDownGenerator.targets | 2 +- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/PxtlCa.XmlCommentMarkDownGenerator.nuspec b/PxtlCa.XmlCommentMarkDownGenerator.nuspec index 8c1ef42..7face35 100644 --- a/PxtlCa.XmlCommentMarkDownGenerator.nuspec +++ b/PxtlCa.XmlCommentMarkDownGenerator.nuspec @@ -1,21 +1,21 @@  - - PxtlCa.XmlCommentMarkDownGenerator - 0.2.6130.564 - PxtlCa.XmlCommentMarkDownGenerator - Martin Zarate - https://opensource.org/licenses/MIT - https://github.com/Pxtl/XmlCommentMarkDownGenerator - false - Convert Visual Studio generated XML Comment XML files into Github-flavoured MarkDown. - Guide available at https://github.com/Pxtl/XmlCommentMarkDownGenerator/blob/master/README.md - 2016 Martin Zarate - - - - - - - + + PxtlCa.XmlCommentMarkDownGenerator + 0.2.6130.564 + PxtlCa.XmlCommentMarkDownGenerator + Martin Zarate + https://opensource.org/licenses/MIT + https://github.com/Pxtl/XmlCommentMarkDownGenerator + false + Convert Visual Studio generated XML Comment XML files into Github-flavoured MarkDown. + Guide available at https://github.com/Pxtl/XmlCommentMarkDownGenerator/blob/master/README.md + 2016 Martin Zarate + + + + + + + \ No newline at end of file diff --git a/PxtlCa.XmlCommentMarkDownGenerator.targets b/PxtlCa.XmlCommentMarkDownGenerator.targets index cccee8c..831f26a 100644 --- a/PxtlCa.XmlCommentMarkDownGenerator.targets +++ b/PxtlCa.XmlCommentMarkDownGenerator.targets @@ -1,6 +1,6 @@ - + Date: Tue, 12 Sep 2017 13:00:19 -0500 Subject: [PATCH 07/15] Delete PxtlCa.XmlCommentMarkDownGenerator.MSBuild.md This file is generated during build. Not needed. --- ...lCa.XmlCommentMarkDownGenerator.MSBuild.md | 55 ------------------- 1 file changed, 55 deletions(-) delete mode 100644 PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/Docs/PxtlCa.XmlCommentMarkDownGenerator.MSBuild.md diff --git a/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/Docs/PxtlCa.XmlCommentMarkDownGenerator.MSBuild.md b/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/Docs/PxtlCa.XmlCommentMarkDownGenerator.MSBuild.md deleted file mode 100644 index 7c6b41c..0000000 --- a/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/Docs/PxtlCa.XmlCommentMarkDownGenerator.MSBuild.md +++ /dev/null @@ -1,55 +0,0 @@ -# PxtlCa.XmlCommentMarkDownGenerator.MSBuild # - -## Type GenerateMarkdown - - A task that generates and optionally merges markdown - - - ---- -#### Property GenerateMarkdown.InputXml - - The file(s) from which to generate markdown. This should be in XmlDocumentation format. - - - ---- -#### Property GenerateMarkdown.DocumentationPath - - DocumentationPath is the top level directory in which to search for files. It is also the path where generated markdown files are created. - - - ---- -#### Property GenerateMarkdown.MergeFiles - - Whether the generated markdown files should merge. Only valid if multiple markdown files exist. DocumentationPath is the top level directory in which to search for files. Both existing markdown files and the generated files are merged. - - - ---- -#### Property GenerateMarkdown.OutputFile - - The file to be created by the merge. Unused if MergeFiles evaluates to false. - - - ---- -#### Method GenerateMarkdown.Execute - - Runs the task as configured - -**Returns**: true if task has succeeded - - - ---- -#### Property GenerateMarkdown.GeneratedMDFiles - - The files generated during execution of the task - - - ---- - - From 522b8dcfe3576952f4e0be29d9d812e903405dd9 Mon Sep 17 00:00:00 2001 From: Erik Goughnour Date: Tue, 12 Sep 2017 13:01:31 -0500 Subject: [PATCH 08/15] Delete Readme.md Generated during build. Not needed. --- .../Readme.md | 57 ------------------- 1 file changed, 57 deletions(-) delete mode 100644 PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/Readme.md diff --git a/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/Readme.md b/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/Readme.md deleted file mode 100644 index 5e785e4..0000000 --- a/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/Readme.md +++ /dev/null @@ -1,57 +0,0 @@ -## No Documentation Yet Authored - -# PxtlCa.XmlCommentMarkDownGenerator.MSBuild # - -## Type GenerateMarkdown - - A task that generates and optionally merges markdown - - - ---- -#### Property GenerateMarkdown.InputXml - - The file(s) from which to generate markdown. This should be in XmlDocumentation format. - - - ---- -#### Property GenerateMarkdown.DocumentationPath - - DocumentationPath is the top level directory in which to search for files. It is also the path where generated markdown files are created. - - - ---- -#### Property GenerateMarkdown.MergeFiles - - Whether the generated markdown files should merge. Only valid if multiple markdown files exist. DocumentationPath is the top level directory in which to search for files. Both existing markdown files and the generated files are merged. - - - ---- -#### Property GenerateMarkdown.OutputFile - - The file to be created by the merge. Unused if MergeFiles evaluates to false. - - - ---- -#### Method GenerateMarkdown.Execute - - Runs the task as configured - -**Returns**: true if task has succeeded - - - ---- -#### Property GenerateMarkdown.GeneratedMDFiles - - The files generated during execution of the task - - - ---- - - From 6a164201160f0f945f9a01c9117a108a02c77ed8 Mon Sep 17 00:00:00 2001 From: Erik Goughnour Date: Tue, 12 Sep 2017 13:08:29 -0500 Subject: [PATCH 09/15] Update README.md mentions build task. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4df05cc..e8de49e 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Can be used as a stand-alone Markdown command-line tool, but is also available a https://www.nuget.org/packages/PxtlCa.XmlCommentMarkDownGenerator -When used as a nuget package, it will add a target to your project to automatically convert generated xml into markdown file stored in Docs at the solution level (peer to the project folder). +When used as a nuget package, it will add an MSBuild task to your project to automatically convert generated xml into markdown file stored in Docs at the project level. It will also merge any existing markdown files in Docs with the converted markdown. Takes multiple input xml files. (note: the above nuget target was broken after 0.1.5977.1837 because I forgot to commit the nuspec line that does it. Oops. Fixed in 0.2.6130.564) From 175f38e369c990404db99b1c54549d3c633ebf5c Mon Sep 17 00:00:00 2001 From: "Goughnour, Erik" Date: Tue, 12 Sep 2017 13:38:44 -0500 Subject: [PATCH 10/15] updated minor version updated nuspec and updated assembly info on both msbuild task and executable. --- .../Properties/AssemblyInfo.cs | 3 +-- PxtlCa.XmlCommentMarkDownGenerator.nuspec | 2 +- PxtlCa.XmlCommentMarkDownGenerator/Properties/AssemblyInfo.cs | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/Properties/AssemblyInfo.cs b/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/Properties/AssemblyInfo.cs index fababd2..67664f2 100644 --- a/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/Properties/AssemblyInfo.cs +++ b/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/Properties/AssemblyInfo.cs @@ -32,5 +32,4 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("0.3.*")] diff --git a/PxtlCa.XmlCommentMarkDownGenerator.nuspec b/PxtlCa.XmlCommentMarkDownGenerator.nuspec index 7face35..fa0cd86 100644 --- a/PxtlCa.XmlCommentMarkDownGenerator.nuspec +++ b/PxtlCa.XmlCommentMarkDownGenerator.nuspec @@ -2,7 +2,7 @@ PxtlCa.XmlCommentMarkDownGenerator - 0.2.6130.564 + 0.3.0.0 PxtlCa.XmlCommentMarkDownGenerator Martin Zarate https://opensource.org/licenses/MIT diff --git a/PxtlCa.XmlCommentMarkDownGenerator/Properties/AssemblyInfo.cs b/PxtlCa.XmlCommentMarkDownGenerator/Properties/AssemblyInfo.cs index a3bd64b..9046924 100644 --- a/PxtlCa.XmlCommentMarkDownGenerator/Properties/AssemblyInfo.cs +++ b/PxtlCa.XmlCommentMarkDownGenerator/Properties/AssemblyInfo.cs @@ -39,4 +39,4 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.2.*")] +[assembly: AssemblyVersion("0.3.*")] From 4c9024f4fcb275eedf673f5df8877b7933edf5e4 Mon Sep 17 00:00:00 2001 From: "Goughnour, Erik" Date: Tue, 12 Sep 2017 15:32:50 -0500 Subject: [PATCH 11/15] Added WarnOnUnexpectedTag added flag for msbuild task. warn rather than error when set to true and unexpected tag is encountered. --- .gitignore | 5 +- .../GenerateMarkdown.cs | 44 +++++++-- .../BuildEngine.cs | 94 +++++++++++++++++++ ...mmentMarkdownGenerator.MSBuild.Test.csproj | 2 + 4 files changed, 135 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 6ffdd84..8cbc059 100644 --- a/.gitignore +++ b/.gitignore @@ -252,4 +252,7 @@ paket-files/ # SSDT artifacts Model.xml -*.FileListAbsolute.txt \ No newline at end of file +*.FileListAbsolute.txt +PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/Readme.md +PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/Docs/PxtlCa.XmlCommentMarkDownGenerator.MSBuild_altered.md +PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/Docs/PxtlCa.XmlCommentMarkDownGenerator.MSBuild.md diff --git a/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/GenerateMarkdown.cs b/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/GenerateMarkdown.cs index 60e6c52..a750fa8 100644 --- a/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/GenerateMarkdown.cs +++ b/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/GenerateMarkdown.cs @@ -7,6 +7,7 @@ using Microsoft.Build.Utilities; using System.IO; using System.Xml.Linq; +using System.Xml; namespace PxtlCa.XmlCommentMarkDownGenerator.MSBuild { @@ -41,7 +42,13 @@ public class GenerateMarkdown : Task /// public ITaskItem OutputFile { get; set; } + /// + /// Defaults to false. When true unexpected tags in the documentation + /// will generate warnings rather than errors. + /// + public bool WarnOnUnexpectedTag { get; set; } = false; + /// /// Runs the task as configured @@ -75,12 +82,19 @@ public override bool Execute() } catch(Exception ex) { + LoggedException = ex; Log.LogErrorFromException(ex); } } return false; } + /// + /// for testing. + /// sets the exception for throw outside the catch + /// + public Exception LoggedException { get; set; } + private void Merge() { //get all md files in Documentation Path @@ -118,16 +132,28 @@ private void GenerateFiles() { foreach (var inputFile in InputXml) { - var mdOutput = OutputPath(inputFile.ItemSpec); - GeneratedMDFiles.Add(mdOutput); - var sr = new StreamReader(inputFile.ItemSpec); - using (var sw = new StreamWriter(mdOutput)) + try { - var xml = sr.ReadToEnd(); - var doc = XDocument.Parse(xml); - var md = doc.Root.ToMarkDown(); - sw.Write(md); - sw.Close(); + var mdOutput = OutputPath(inputFile.ItemSpec); + GeneratedMDFiles.Add(mdOutput); + var sr = new StreamReader(inputFile.ItemSpec); + using (var sw = new StreamWriter(mdOutput)) + { + var xml = sr.ReadToEnd(); + var doc = XDocument.Parse(xml); + var md = doc.Root.ToMarkDown(); + sw.Write(md); + sw.Close(); + } + }catch(XmlException xmlException) + { + if(WarnOnUnexpectedTag && null != xmlException.InnerException && + xmlException.InnerException.GetType() == typeof(KeyNotFoundException)) + { + Log.LogWarningFromException(xmlException); + continue; + } + throw; } } } diff --git a/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/BuildEngine.cs b/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/BuildEngine.cs index 2aa510b..67ac5d5 100644 --- a/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/BuildEngine.cs +++ b/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/BuildEngine.cs @@ -6,6 +6,10 @@ using PxtlCa.XmlCommentMarkdownGenerator; using PxtlCa.XmlCommentMarkDownGenerator.MSBuild; using Rhino.Mocks; +using System.IO; +using System.Xml.Linq; +using System.Xml.XPath; +using System.Xml; namespace PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test { @@ -43,5 +47,95 @@ public void ExecuteMerge() Assert.AreEqual(expectFileExists, fileActuallyExists); } + + [TestMethod] + public void HandleUnexpectedTag() + { + var mockRepo = new MockRepository(); + var buildEngine = mockRepo.Stub(); + + var inputPath = @"..\..\..\PxtlCa.XmlCommentMarkdownGenerator.MSBuild\bin\Debug\PxtlCa.XmlCommentMarkDownGenerator.MSBuild.xml"; + var toAlter = File.ReadAllText(inputPath); + toAlter = toAlter.Replace(@"", @"X"); + + var alteredPath = inputPath.Replace("MSBuild.xml", "MSBuild_altered.xml"); + File.WriteAllText(alteredPath, toAlter); + + var docPath = @"..\..\Docs"; + var outputFile = new TaskItem(@"..\..\Readme.md"); + + + var inputXml = new ITaskItem[] { new TaskItem(alteredPath) }; + + var documentPath = new TaskItem(docPath); + var merge = true; + + var task = new GenerateMarkdown + { + BuildEngine = buildEngine, + DocumentationPath = documentPath, + InputXml = inputXml, + MergeFiles = merge, + WarnOnUnexpectedTag = true, + OutputFile = outputFile + }; + + task.Execute(); + + if (null != task.LoggedException) + { + throw task.LoggedException; + } + + var expectFileExists = true; + var fileActuallyExists = System.IO.File.Exists(outputFile.ItemSpec); + + Assert.AreEqual(expectFileExists, fileActuallyExists); + } + + + [TestMethod] + [ExpectedException(typeof(XmlException))] + public void ExpectedErrorUnexpectedTag() + { + var mockRepo = new MockRepository(); + var buildEngine = mockRepo.Stub(); + + var inputPath = @"..\..\..\PxtlCa.XmlCommentMarkdownGenerator.MSBuild\bin\Debug\PxtlCa.XmlCommentMarkDownGenerator.MSBuild.xml"; + // var toAlter = File.ReadAllText(inputPath); + //toAlter = toAlter.Replace(@"", @"X"); + + var alteredPath = inputPath.Replace("MSBuild.xml", "MSBuild_altered.xml"); + //File.WriteAllText(alteredPath, toAlter); + + var docPath = @"..\..\Docs"; + var outputFile = new TaskItem(@"..\..\Readme.md"); + + + var inputXml = new ITaskItem[] { new TaskItem(alteredPath) }; + + var documentPath = new TaskItem(docPath); + var merge = true; + + var task = new GenerateMarkdown + { + BuildEngine = buildEngine, + DocumentationPath = documentPath, + InputXml = inputXml, + MergeFiles = merge, + OutputFile = outputFile + }; + + task.Execute(); + + if(null != task.LoggedException) + { + throw task.LoggedException; + } + var expectFileExists = true; + var fileActuallyExists = System.IO.File.Exists(outputFile.ItemSpec); + + Assert.AreEqual(expectFileExists, fileActuallyExists); + } } } diff --git a/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test.csproj b/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test.csproj index f6761b9..e766239 100644 --- a/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test.csproj +++ b/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test.csproj @@ -52,6 +52,8 @@ + + From e6b7c839303b34c5d682649c849d38140e4d781d Mon Sep 17 00:00:00 2001 From: Erik Goughnour Date: Sat, 28 Oct 2017 23:37:20 -0500 Subject: [PATCH 12/15] Create Plugin.csx A couple items of note: - Code52/pretzel is a partial .NET implementation of Jekyll. - Process() apparently is always called. - CanProcess() is only called as needed based on the file timestamps. - After the custom tag check, the MD file merging should occur. - `pretzel taste` may need some try/catch or other handling. Below is the output when run against my test content: ``` >pretzel taste -t=customxmlmd starting pretzel... taste - testing a site locally About to check CanProcess(context) again about to check 'mergexmlcomments' a bool as boolean 'mergexmlcomments' is true Custom Tag to allow: all Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object. at Pretzel.Logic.Minification.LessTransform.b__5_0(Page p) at System.Linq.Enumerable.WhereListIterator`1.MoveNext() at Pretzel.Logic.Minification.LessTransform.Transform(SiteContext siteContext) at Pretzel.Commands.TasteCommand.Execute(IEnumerable`1 arguments) at Pretzel.Program.Run(BaseParameters baseParameters) at Pretzel.Program.Main(String[] args) ``` --- PretzelPlugin/Plugin.csx | 60 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 PretzelPlugin/Plugin.csx diff --git a/PretzelPlugin/Plugin.csx b/PretzelPlugin/Plugin.csx new file mode 100644 index 0000000..5efa635 --- /dev/null +++ b/PretzelPlugin/Plugin.csx @@ -0,0 +1,60 @@ +using Pretzel.Logic.Templating; +using Pretzel.Logic.Templating.Context; +using System.ComponentModel.Composition; +using System.Collections.Generic; +using System.Linq; + + +[SiteEngineInfo(Engine="customxmlmd")] +public class Processor : ISiteEngine +{ + + public string AllowableCustomTags {get; set;} + public void Initialize() + { + + } + + public bool CanProcess(SiteContext context) + { + var readmePage = context.Posts.Where(p => p.File.ToLower().EndsWith("readme.md")).FirstOrDefault(); + if(null == readmePage) + { + //if no readme.md then return false + return false; + } + if(readmePage.Bag.ContainsKey("mergexmlcomments")) + { + Console.WriteLine("about to check 'mergexmlcomments' a bool"); + if(!(bool)(readmePage.Bag["mergexmlcomments"])) + { + Console.WriteLine("as boolean 'mergexmlcomments' is false"); + //if there is a mergexmlcomments value in the front matter + //but it is false + return false; + } + Console.WriteLine("as boolean 'mergexmlcomments' is true"); + AllowableCustomTags = (string)(readmePage.Bag["allowedcustomtags"]); + return true; + } + else + { + Console.WriteLine("Bag doesn't contain 'mergexmlcomments'"); + //no mergexmlcomments value + return false; + } + } + + public void Process(SiteContext context, bool skipFileOnError = false) + { + Console.WriteLine($@"About to check CanProcess(context) again"); + if(CanProcess(context)) + { + Console.WriteLine($@"Custom Tag to allow: {AllowableCustomTags}"); + } + else + { + Console.WriteLine($@"CanProcess(context) is false this time"); + } + } +} From 5a3bf1eaa5d412fbb902fe2c10352865356fd3a0 Mon Sep 17 00:00:00 2001 From: Erik Goughnour Date: Sat, 28 Oct 2017 23:40:32 -0500 Subject: [PATCH 13/15] Create readme.md These values are read by the custom plugin. --- PretzelPlugin/readme.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 PretzelPlugin/readme.md diff --git a/PretzelPlugin/readme.md b/PretzelPlugin/readme.md new file mode 100644 index 0000000..afde74d --- /dev/null +++ b/PretzelPlugin/readme.md @@ -0,0 +1,20 @@ +--- +layout: post +title: "README" +author: "The end user" +comments: false +mergexmlcomments: true +allowedcustomtags: "all" +--- + +## Hello world... + +```cs +static void Main() +{ + Console.WriteLine("Hello World!"); +} +``` + + +This is my first post on the site! From 2778b52e0671453ec38035838e6b14a69c11e536 Mon Sep 17 00:00:00 2001 From: "Goughnour, Erik" Date: Mon, 30 Oct 2017 21:40:40 -0500 Subject: [PATCH 14/15] Added front matter check --- .../GenerateMarkdown.cs | 106 +++++++++++++++--- .../Options/YamlOptions.cs | 31 +++++ ...XmlCommentMarkDownGenerator.MSBuild.csproj | 7 ++ .../packages.config | 4 + 4 files changed, 134 insertions(+), 14 deletions(-) create mode 100644 PxtlCa.XmlCommentMarkDownGenerator.MSBuild/Options/YamlOptions.cs create mode 100644 PxtlCa.XmlCommentMarkDownGenerator.MSBuild/packages.config diff --git a/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/GenerateMarkdown.cs b/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/GenerateMarkdown.cs index a750fa8..f157649 100644 --- a/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/GenerateMarkdown.cs +++ b/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/GenerateMarkdown.cs @@ -8,6 +8,9 @@ using System.IO; using System.Xml.Linq; using System.Xml; +using YamlDotNet.Serialization; +using YamlDotNet.Serialization.NamingConventions; +using PxtlCa.XmlCommentMarkDownGenerator.MSBuild.Options; namespace PxtlCa.XmlCommentMarkDownGenerator.MSBuild { @@ -34,7 +37,6 @@ public class GenerateMarkdown : Task /// DocumentationPath is the top level directory in which to search for files. /// Both existing markdown files and the generated files are merged. /// - [Required] public bool MergeFiles { get; set; } /// @@ -56,39 +58,115 @@ public class GenerateMarkdown : Task /// true if task has succeeded public override bool Execute() { - if(InputXml.Length == 0) + if (InputXml.Length == 0) { Log.LogError("InputXml cannot be empty"); } - else if(MergeFiles && (null == OutputFile)) + else { - Log.LogError("OutputFile must be specified if input files are merged"); + UpdateParametersFromInput(); + if (MergeFiles && (null == OutputFile)) + { + Log.LogError("OutputFile must be specified if input files are merged"); + } + else if (DocumentationPathIsFile && InputXml.Length != 1) + { + Log.LogError("DocumentationPath must specify a directory if more than one input XML value is supplied"); + } + else + { + try + { + CreateDirectoryIfNeeded(); + GenerateFiles(); + if (MergeFiles) + { + Merge(); + } + return true; + } + catch (Exception ex) + { + LoggedException = ex; + Log.LogErrorFromException(ex); + } + } } - else if(DocumentationPathIsFile && InputXml.Length != 1) + return false; + } + + /// + /// This updates the tag and merge parameters based on the input front matter + /// + public void UpdateParametersFromInput() + { + if(DocumentationPathIsFile) { - Log.LogError("DocumentationPath must specify a directory is more than one input XML value is supplied"); + if (TryGetFrontMatter(DocumentationPath.ItemSpec, out string frontMatter, out bool isEmpty) && + (!isEmpty)) + { + ReadOptionsFromString(frontMatter); + return; + } } else { - try + var mdFiles = Directory.EnumerateFiles(DocumentationPath.ItemSpec, "*.md", SearchOption.AllDirectories).ToList(); + foreach (var mdFile in mdFiles) { - CreateDirectoryIfNeeded(); - GenerateFiles(); - if(MergeFiles) + if (TryGetFrontMatter(mdFile, out string frontMatter, out bool isEmpty) && + (!isEmpty)) { - Merge(); + ReadOptionsFromString(frontMatter); + return; } + } + } + } + + private bool TryGetFrontMatter(string filePath, out string frontMatter, out bool isEmpty) + { + var lines = File.ReadLines(filePath); + var firstDashedLine = lines.FirstOrDefault() ?? string.Empty; + if (firstDashedLine.StartsWith("---")) + { + var followingLines = lines.Skip(1).TakeWhile(line => !line.StartsWith("---")).ToList(); + if(followingLines.Count == 0) + { + frontMatter = firstDashedLine; + isEmpty = true; return true; } - catch(Exception ex) + else { - LoggedException = ex; - Log.LogErrorFromException(ex); + followingLines.Insert(0, firstDashedLine); + frontMatter = String.Join(Environment.NewLine, followingLines); + isEmpty = false; + return true; } } + frontMatter = string.Empty; + isEmpty = true; return false; } + private void ReadOptionsFromString(string frontMatter) + { + var input = new StringReader(frontMatter); + var deserializer = new DeserializerBuilder() + .WithNamingConvention(new CamelCaseNamingConvention()) + .Build(); + var options = deserializer.Deserialize(input); + MergeFiles = options.MergeXmlComments; + if(Enum.TryParse(options.AllowedCustomTags, + out AllowedTagOptions result)) + { + //warn (rather than treat as error condition) + //if user indicates one of the two currently used options + WarnOnUnexpectedTag = result == AllowedTagOptions.All; + } + } + /// /// for testing. /// sets the exception for throw outside the catch diff --git a/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/Options/YamlOptions.cs b/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/Options/YamlOptions.cs new file mode 100644 index 0000000..f0238ec --- /dev/null +++ b/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/Options/YamlOptions.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PxtlCa.XmlCommentMarkDownGenerator.MSBuild.Options +{ + /// + /// Specifies the manner in which custom tags will be handled + /// + public enum AllowedTagOptions + { + /// + /// All custom tags are allowed + /// + All, + /// + /// No custom tags are allowed + /// + None + } + /// + /// The options to be deserialized from the front matter found. + /// + public class YamlOptions + { + public bool MergeXmlComments { get; set; } + public string AllowedCustomTags { get; set; } + } +} diff --git a/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/PxtlCa.XmlCommentMarkDownGenerator.MSBuild.csproj b/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/PxtlCa.XmlCommentMarkDownGenerator.MSBuild.csproj index 7de077a..a9b3b70 100644 --- a/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/PxtlCa.XmlCommentMarkDownGenerator.MSBuild.csproj +++ b/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/PxtlCa.XmlCommentMarkDownGenerator.MSBuild.csproj @@ -42,9 +42,13 @@ + + ..\packages\YamlDotNet.4.2.2\lib\net35\YamlDotNet.dll + + @@ -53,5 +57,8 @@ PxtlCa.XmlCommentMarkDownGenerator + + + \ No newline at end of file diff --git a/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/packages.config b/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/packages.config new file mode 100644 index 0000000..0cfcc50 --- /dev/null +++ b/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file From efcccd0bb8d8033db4282da21e82f7e073bd6788 Mon Sep 17 00:00:00 2001 From: "Goughnour, Erik" Date: Tue, 31 Oct 2017 08:17:50 -0500 Subject: [PATCH 15/15] Updates based on testing --- .../GenerateMarkdown.cs | 11 +- .../Options/YamlOptions.cs | 5 +- .../BuildEngine.cs | 104 ++++++++++++++++-- .../Docs/Notes.md | 4 +- ...mmentMarkdownGenerator.MSBuild.Test.csproj | 33 +++--- 5 files changed, 131 insertions(+), 26 deletions(-) diff --git a/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/GenerateMarkdown.cs b/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/GenerateMarkdown.cs index f157649..90949fa 100644 --- a/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/GenerateMarkdown.cs +++ b/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/GenerateMarkdown.cs @@ -124,7 +124,14 @@ public void UpdateParametersFromInput() } } - private bool TryGetFrontMatter(string filePath, out string frontMatter, out bool isEmpty) + /// + /// Use this to handle front matter in markdown files + /// + /// the path to the file + /// the front matter found + /// whether the front matter found is trivial + /// true if front matter indicator(s) are found + public static bool TryGetFrontMatter(string filePath, out string frontMatter, out bool isEmpty) { var lines = File.ReadLines(filePath); var firstDashedLine = lines.FirstOrDefault() ?? string.Empty; @@ -158,7 +165,7 @@ private void ReadOptionsFromString(string frontMatter) .Build(); var options = deserializer.Deserialize(input); MergeFiles = options.MergeXmlComments; - if(Enum.TryParse(options.AllowedCustomTags, + if(Enum.TryParse(options.AllowedCustomTags, true, out AllowedTagOptions result)) { //warn (rather than treat as error condition) diff --git a/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/Options/YamlOptions.cs b/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/Options/YamlOptions.cs index f0238ec..1e1bff3 100644 --- a/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/Options/YamlOptions.cs +++ b/PxtlCa.XmlCommentMarkDownGenerator.MSBuild/Options/YamlOptions.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using YamlDotNet.Serialization; namespace PxtlCa.XmlCommentMarkDownGenerator.MSBuild.Options { @@ -10,7 +11,7 @@ namespace PxtlCa.XmlCommentMarkDownGenerator.MSBuild.Options /// Specifies the manner in which custom tags will be handled /// public enum AllowedTagOptions - { + { /// /// All custom tags are allowed /// @@ -25,7 +26,9 @@ public enum AllowedTagOptions /// public class YamlOptions { + [YamlMember(Alias = "MergeXmlComments", ApplyNamingConventions = false)] public bool MergeXmlComments { get; set; } + [YamlMember(Alias = "AllowedCustomTags", ApplyNamingConventions = false)] public string AllowedCustomTags { get; set; } } } diff --git a/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/BuildEngine.cs b/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/BuildEngine.cs index 67ac5d5..822f476 100644 --- a/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/BuildEngine.cs +++ b/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/BuildEngine.cs @@ -10,6 +10,7 @@ using System.Xml.Linq; using System.Xml.XPath; using System.Xml; +using System.Linq; namespace PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test { @@ -17,13 +18,15 @@ namespace PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test public class BuildEngine { [TestMethod] + [DeploymentItem("Docs")] public void ExecuteMerge() { + PrepareDocsDirectory(); var mockRepo = new MockRepository(); var buildEngine = mockRepo.Stub(); var inputPath = @"..\..\..\PxtlCa.XmlCommentMarkdownGenerator.MSBuild\bin\Debug\PxtlCa.XmlCommentMarkDownGenerator.MSBuild.xml"; - var docPath = @"..\..\Docs"; + var docPath = @"Docs"; var outputFile = new TaskItem(@"..\..\Readme.md"); @@ -49,8 +52,51 @@ public void ExecuteMerge() } [TestMethod] + [DeploymentItem("Docs")] + public void TestAvertMerge() + { + PrepareDocsDirectory(overrideMerge:true); + var mockRepo = new MockRepository(); + var buildEngine = mockRepo.Stub(); + + var inputPath = @"..\..\..\PxtlCa.XmlCommentMarkdownGenerator.MSBuild\bin\Debug\PxtlCa.XmlCommentMarkDownGenerator.MSBuild.xml"; + var docPath = @"Docs"; + var outputFile = new TaskItem(@"..\..\Readme.md"); + + + var inputXml = new ITaskItem[] { new TaskItem(inputPath) }; + var documentPath = new TaskItem(docPath); + var merge = true; + + var task = new GenerateMarkdown + { + BuildEngine = buildEngine, + DocumentationPath = documentPath, + InputXml = inputXml, + MergeFiles = merge, + OutputFile = outputFile + }; + + task.Execute(); + + var expectFileExists = true; + var fileActuallyExists = System.IO.File.Exists(outputFile.ItemSpec); + + Assert.AreEqual(expectFileExists, fileActuallyExists); + + var docCount = Directory.EnumerateFiles(@"Docs", "*.md", SearchOption.TopDirectoryOnly).ToList().Count; + + //different than the case where the files are merged (into _one_ file) + var expectedDocCount = 2; + + Assert.AreEqual(expectedDocCount, docCount); + } + + [TestMethod] + [DeploymentItem("Docs")] public void HandleUnexpectedTag() { + PrepareDocsDirectory(); var mockRepo = new MockRepository(); var buildEngine = mockRepo.Stub(); @@ -61,7 +107,7 @@ public void HandleUnexpectedTag() var alteredPath = inputPath.Replace("MSBuild.xml", "MSBuild_altered.xml"); File.WriteAllText(alteredPath, toAlter); - var docPath = @"..\..\Docs"; + var docPath = @"Docs"; var outputFile = new TaskItem(@"..\..\Readme.md"); @@ -95,20 +141,22 @@ public void HandleUnexpectedTag() [TestMethod] + [DeploymentItem("Docs")] [ExpectedException(typeof(XmlException))] public void ExpectedErrorUnexpectedTag() { + PrepareDocsDirectory(); var mockRepo = new MockRepository(); var buildEngine = mockRepo.Stub(); var inputPath = @"..\..\..\PxtlCa.XmlCommentMarkdownGenerator.MSBuild\bin\Debug\PxtlCa.XmlCommentMarkDownGenerator.MSBuild.xml"; - // var toAlter = File.ReadAllText(inputPath); - //toAlter = toAlter.Replace(@"", @"X"); + var toAlter = File.ReadAllText(inputPath); + toAlter = toAlter.Replace(@"", @"X"); var alteredPath = inputPath.Replace("MSBuild.xml", "MSBuild_altered.xml"); - //File.WriteAllText(alteredPath, toAlter); + File.WriteAllText(alteredPath, toAlter); - var docPath = @"..\..\Docs"; + var docPath = @"Docs"; var outputFile = new TaskItem(@"..\..\Readme.md"); @@ -123,7 +171,8 @@ public void ExpectedErrorUnexpectedTag() DocumentationPath = documentPath, InputXml = inputXml, MergeFiles = merge, - OutputFile = outputFile + OutputFile = outputFile, + WarnOnUnexpectedTag = false }; task.Execute(); @@ -137,5 +186,46 @@ public void ExpectedErrorUnexpectedTag() Assert.AreEqual(expectFileExists, fileActuallyExists); } + + public static void PrepareDocsDirectory(bool overrideMerge = false) + { + var mergeDirectiveInserted = false; + if(Directory.Exists("Docs")) + { + Directory.Delete("Docs", true); + } + Directory.CreateDirectory("Docs"); + var filesToMove = Directory.EnumerateFiles(Environment.CurrentDirectory, "*.md", SearchOption.TopDirectoryOnly).ToList(); + foreach (var mdFile in filesToMove) + { + if(overrideMerge && (!mergeDirectiveInserted)) + { + mergeDirectiveInserted = TryUpdateFile(mergeDirectiveInserted, mdFile); + } + File.Copy(mdFile, $@".\Docs\{Path.GetFileName(mdFile)}"); + } + } + + private static bool TryUpdateFile(bool mergeDirectiveInserted, string mdFile) + { + if (GenerateMarkdown.TryGetFrontMatter(mdFile, out string frontMatter, out bool isEmpty)) + { + if (isEmpty) + { + //get all the lines starting with the second "---" line + var lines = File.ReadLines(mdFile).Skip(1).ToList(); + //now insert the front matter in reverse order + lines.Insert(0, "AllowedCustomTags: all"); + lines.Insert(0, "MergeXmlComments: false"); + lines.Insert(0, "---"); + //overwrite the file with the update + File.WriteAllText(mdFile, string.Join(Environment.NewLine, lines)); + //stop any additional preprocesssing + mergeDirectiveInserted = true; + } + } + + return mergeDirectiveInserted; + } } } diff --git a/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/Docs/Notes.md b/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/Docs/Notes.md index b81254f..5ceef91 100644 --- a/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/Docs/Notes.md +++ b/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/Docs/Notes.md @@ -1 +1,3 @@ -## No Documentation Yet Authored +--- +--- +## No Documentation Yet Authored diff --git a/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test.csproj b/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test.csproj index e766239..0b9c57c 100644 --- a/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test.csproj +++ b/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test/PxtlCa.XmlCommentMarkdownGenerator.MSBuild.Test.csproj @@ -1,5 +1,5 @@  - + Debug @@ -41,12 +41,6 @@ - - ..\packages\MSTest.TestFramework.1.1.11\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll - - - ..\packages\MSTest.TestFramework.1.1.11\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll - ..\packages\RhinoMocks.3.6.1\lib\net\Rhino.Mocks.dll @@ -55,11 +49,28 @@ + + + + + + + + + + False + + + + + + PreserveNewest + @@ -74,12 +85,4 @@ - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - - \ No newline at end of file