Skip to content

Commit

Permalink
remove document comment option, support future version(#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
itn3000 committed Apr 7, 2022
1 parent c6850de commit 3e306a1
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 27 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@ jobs:
- run: "pwsh ./build.ps1 --target Test --configuration Release"
name: "running test suite"
- name: "build nuget package"
run: "pwsh ./build.ps1 --target Pack --configuration Release"
run: "pwsh ./build.ps1 --target Pack --configuration Release --version-suffix alpha.${{ github.run_number }}"
if: ${{ matrix.os == 'windows-2022' }}
- name: "build tgz binary"
run: "pwsh ./build.ps1 --target ArchiveTgz --configuration Release --runtime ${{ matrix.runtime }}"
run: "pwsh ./build.ps1 --target ArchiveTgz --configuration Release --runtime ${{ matrix.runtime }} --version-suffix alpha.${{ github.run_number }}"
if: ${{ matrix.os != 'windows-2022'}}
- name: "build zip binary"
run: "pwsh ./build.ps1 --target ArchiveZip --configuration Release --runtime ${{ matrix.runtime }}"
run: "pwsh ./build.ps1 --target ArchiveZip --configuration Release --runtime ${{ matrix.runtime }} --version-suffix alpha.${{ github.run_number }}"
if: ${{ matrix.os == 'windows-2022'}}
- name: "collect nupkg"
uses: actions/upload-artifact@v3
with:
name: nupkg
path: |
artifacts/Release/Any/cs2mmd.*.nupkg
artifacts/Release/Any/cs2mmd.*.snupkg
artifacts/Release/Any/*.nupkg
artifacts/Release/Any/*.snupkg
if: ${{ matrix.os == 'windows-2022' }}
- name: "collect tgz binary"
uses: actions/upload-artifact@v3
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ jobs:
with:
name: nupkg
path: |
artifacts/Release/Any/cs2mmd.*.nupkg
artifacts/Release/Any/cs2mmd.*.snupkg
artifacts/Release/Any/*.nupkg
artifacts/Release/Any/*.snupkg
if: ${{ matrix.os == 'windows-2022' }}
- name: "collect tgz binary"
uses: actions/upload-artifact@v3
Expand Down
4 changes: 4 additions & 0 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
"VSCode"
]
},
"IsReleaseBuild": {
"type": "boolean",
"description": "release build flag"
},
"NoLogo": {
"type": "boolean",
"description": "Disables displaying the NUKE logo"
Expand Down
17 changes: 6 additions & 11 deletions Cs2Mermaid.Lib/ConvertCsToMermaid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ public class ConvertOptions
public string[]? PreprocessorSymbols { get; set; }
public string? LangVersion { get; set; }
public string? ChartOrientation { get; set; }
public string? SourceKind { get; set; }
public bool ParseDocumentComment { get; set; }
public bool? AsScript { get; set; }
}
public static class ConvertCsToMermaid
{
Expand All @@ -34,25 +33,21 @@ static CSharpParseOptions CreateParseOption(ConvertOptions options)
throw new Exception($"failed to parse langveresion: {options.LangVersion}", e);
}
}
if(!string.IsNullOrEmpty(options.SourceKind))
if(options.AsScript.HasValue)
{
try
if(options.AsScript.Value)
{
ret = ret.WithKind(Enum.Parse<SourceCodeKind>(options.SourceKind, true));
ret = ret.WithKind(SourceCodeKind.Script);
}
catch(Exception e)
else
{
throw new Exception($"failed to parse sourcecode kind: {options.SourceKind}", e);
ret = ret.WithKind(SourceCodeKind.Regular);
}
}
if (options.PreprocessorSymbols != null && options.PreprocessorSymbols.Length != 0)
{
ret = ret.WithPreprocessorSymbols(options.PreprocessorSymbols);
}
if(options.ParseDocumentComment)
{
ret = ret.WithDocumentationMode(DocumentationMode.Parse);
}
return ret;
}
public static void Convert(Stream input, Encoding inputEncoding, TextWriter tw, ConvertOptions convertOptions)
Expand Down
42 changes: 42 additions & 0 deletions Cs2Mermaid.Test/ConvertTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,46 @@ public void IfDef()
_OutputHelper.WriteLine(generated);
Assert.NotNull(generated);
}
// [Fact]
// public void DocComment()
// {
// var options = new ConvertOptions()
// {
// ParseDocumentComment = true,
// };
// var code = @"
// /// <summary>this is summary</summary>
// /// <remarks>this is remarks</remarks>
// class C1
// {
// public void M(int x){}
// }
// ";
// var withdoc = ConvertCsToMermaid.Convert(code, options);
// _OutputHelper.WriteLine("withdoc: " + withdoc);
// Assert.NotNull(withdoc);
// options.ParseDocumentComment = false;
// var nodoc = ConvertCsToMermaid.Convert(code, options);
// _OutputHelper.WriteLine("nodoc: " + nodoc);
// Assert.NotEqual(nodoc, withdoc);
// }
[Fact]
public void SourceCodeKindTest()
{
var options = new ConvertOptions()
{
AsScript = true
};
var code = @"
#r """"
var x = 1 + 1;
";
var asscript = ConvertCsToMermaid.Convert(code, options);
options.AsScript = false;
var asregular = ConvertCsToMermaid.Convert(code, options);
_OutputHelper.WriteLine("script: " + asscript);
_OutputHelper.WriteLine("regular: " + asregular);
Assert.NotEqual(asregular, asscript);

}
}
6 changes: 6 additions & 0 deletions Cs2Mermaid.Test/TestClasses/DocComment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

/// <summary>this is summary</summary>
class C1
{

}
1 change: 1 addition & 0 deletions Cs2Mermaid/Cs2Mermaid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<PackageReadmeFile>README.md</PackageReadmeFile>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<PackageId>Cs2Mermaid</PackageId>
</PropertyGroup>

</Project>
12 changes: 4 additions & 8 deletions Cs2Mermaid/MyCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ class MyCommandHandler : ICommandHandler
Option<bool> showAvailableVersion = new Option<bool>("--available-version", "output available C# version and exit");
Option<string[]> symbolOption = new Option<string[]>("--pp-symbol", "preprocessor symbol(can be multiple)");
Option<string> orientationOption = new Option<string>(new string[] { "--chart-orientation", "-co" }, "flowchart orientation(default: LR)");
Option<string> sourceKindOption = new Option<string>("--source-kind", "source code kind: 'regular'(default) or 'script')");
Option<bool> parseDocCommentOption = new Option<bool>("--parse-doc-comment", "parse document comment too");
Option<bool> asScriptOption = new Option<bool>("--as-script", "parse as C# script");
public Option[] GetOptions()
{
return new Option[]
Expand All @@ -30,8 +29,7 @@ public Option[] GetOptions()
showAvailableVersion,
symbolOption,
orientationOption,
sourceKindOption,
parseDocCommentOption,
asScriptOption,
};
}
public MyCommandHandler()
Expand Down Expand Up @@ -78,15 +76,13 @@ ConvertOptions CreateConvertOptions(InvocationContext context)
var presymbols = context.ParseResult.GetValueForOption<string[]>(symbolOption);
var langver = context.ParseResult.GetValueForOption<string>(langVersion);
var orientation = context.ParseResult.GetValueForOption<string>(orientationOption);
var sourceKind = context.ParseResult.GetValueForOption<string>(sourceKindOption);
var parseDocComment = context.ParseResult.GetValueForOption<bool>(parseDocCommentOption);
var asscript = context.ParseResult.GetValueForOption<bool>(asScriptOption);
return new ConvertOptions()
{
LangVersion = langver,
PreprocessorSymbols = presymbols,
ChartOrientation = orientation,
SourceKind = sourceKind,
ParseDocumentComment = parseDocComment,
AsScript = asscript,
};
}
void ProcessWithMd(string? output, string? outputEncoding, string? input, string? inputEncoding, ConvertOptions convertOptions)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ This tool converts from C# syntax tree to mermaid diagram
`--symbol` option can be specified multiple.
`cs2mmd -i path/to/cs --pp-symbol ABC --pp-symbol DEF`

## Read from file and output to file by markdown with original source
## output as markdown with original source(github format)

`cs2mmd -i path/to/cs -o output.md --md-with-source --chart-orientation TD`

Expand Down
2 changes: 2 additions & 0 deletions nbuild/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class Build : NukeBuild
{
DotNetTasks.DotNetBuild(cfg => cfg.SetConfiguration(Configuration)
.SetProjectFile(Solution)
.SetVersionSuffix(VersionSuffix)
.SetRuntime(Runtime));
});
Target Test => _ => _
Expand All @@ -90,6 +91,7 @@ class Build : NukeBuild
.SetSelfContained(!string.IsNullOrEmpty(Runtime))
.SetPublishSingleFile(!string.IsNullOrEmpty(Runtime))
.SetPublishTrimmed(!string.IsNullOrEmpty(Runtime))
.SetVersionSuffix(VersionSuffix)
.SetProperty("LinkMode", "copyused")
);
});
Expand Down

0 comments on commit 3e306a1

Please sign in to comment.