Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#196 Publish a global dotnet tool (AsyncAPI.Saunter.Generator.Cli) #217

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
6318f80
#196 Publish a global dotnet tool
Jul 6, 2024
2162d72
#196 Publish a global dotnet tool -- Api/API casing fix
Jul 6, 2024
55895a2
#196 .NET8
Jul 6, 2024
6ba3409
#196 .NET6
Jul 6, 2024
74c9cff
#196 I'd like .NET8 more, request both for ci
Jul 6, 2024
cc5d952
#196 I'd like .NET8 more, request both for ci?
Jul 6, 2024
569a30a
#196 Fixed resolving, added support for multiple asyncAPI documents, …
Jul 6, 2024
0419101
#196 Test for dotnet cli tool, added support for default asyncapi doc…
Jul 6, 2024
b29a1ab
#196 Pack_Install_Run_Uninstall Test
Jul 6, 2024
12593dc
#196 Pack_Install_Run_Uninstall fix casing in test, add meta data to …
Jul 6, 2024
93dc17e
#196 fix accident
Jul 6, 2024
e701660
#196 fix warnings, fix permission
Jul 6, 2024
d9b558c
#196 unix needs a shebang
Jul 6, 2024
f0af6d1
#196 sourcelink properties
Jul 6, 2024
1ebb77c
#196 renamed tool to make up a more logical name, fixed empty paramet…
Jul 7, 2024
ba1e856
#196 fix readme error
Jul 7, 2024
90dcff1
Merge remote-tracking branch 'remotes/origin/main' into #196-Publish-…
Jul 8, 2024
a746e4d
#196 Fixed formatting etc + some PR remarks
Jul 9, 2024
8e7a01f
#196 Tool rewrite to make its components testable, removed Swachbuckl…
Jul 9, 2024
240c9ed
#196 formatting
Jul 9, 2024
715a62d
#196 add unitTests for tofile classes
Jul 10, 2024
e181850
#196 add unitTests for tofile
Jul 10, 2024
ab5b375
#196-Publish-a-global-dotnet-tool
Jul 11, 2024
183a4e8
#196 formatting
Jul 11, 2024
8d2fd49
#196 ALL tests should run
Jul 11, 2024
a9d544a
#196 Tests use streetlights DLL in integegration tests, add dependency
Jul 11, 2024
72dc742
#196 release also the CLI tool
Jul 11, 2024
7b22ce0
#196 Add example project with top level statement, because that faile…
Jul 13, 2024
ba8dd8e
#196 Ignore expected warning (ASP0014 needs #173)
Jul 13, 2024
3d6c0ea
#196 formatting and readme wording
Jul 13, 2024
8a4f5c6
#196 ExitCode test problems
Jul 13, 2024
07b4273
#196 ExitCode test problems -- the issue is a missing reference
Jul 13, 2024
e846dd9
#196 GetStreamFor logging
Jul 13, 2024
fc7cccd
#196 GetStreamFor try recreate directory?
Jul 13, 2024
4f1064e
#196 GetStreamFor try recreate directory??
Jul 13, 2024
74260a8
#196 permission issue?
Jul 13, 2024
5fe8c6e
#196 cleanup csproj
Jul 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ spelling_exclusion_path = SpellingExclusions.dic
indent_size = 4
insert_final_newline = true
charset = utf-8-bom
end_of_line = lf

# XML project files
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}]
indent_size = 4
indent_size = 2
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

current files were using a size of 2 and lf line endings, so I changed it (because my VS defaults are different)

end_of_line = lf

# XML config files
[*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}]
Expand Down
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text eol=lf
4 changes: 3 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ jobs:
node-version: 'lts/*' # latest LTS version
- uses: actions/setup-dotnet@v2
with:
dotnet-version: '6.0.x' # SDK Version to use; x will use the latest version of the channel
dotnet-version: |
6.0.x
8.0.x

- name: Run NPM install
run: npm ci
Expand Down
31 changes: 31 additions & 0 deletions Saunter.sln
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E0D34C77-924E-4F6B-9289-5A2F07D125A8}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.gitattributes = .gitattributes
CHANGELOG.md = CHANGELOG.md
.github\workflows\ci.yaml = .github\workflows\ci.yaml
README.md = README.md
Expand All @@ -28,6 +29,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Saunter.IntegrationTests.Re
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Saunter.Tests.MarkerTypeTests", "test\Saunter.Tests.MarkerTypeTests\Saunter.Tests.MarkerTypeTests.csproj", "{02284473-6DE7-4EE0-8433-2AC295045549}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AsyncAPI.Saunter.Generator.Cli", "src\AsyncAPI.Saunter.Generator.Cli\AsyncAPI.Saunter.Generator.Cli.csproj", "{6C102D4D-3DA4-4763-B75E-C15E33E7E94A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AsyncAPI.Saunter.Generator.Cli.Tests", "test\AsyncAPI.Saunter.Generator.Cli.Tests\AsyncAPI.Saunter.Generator.Cli.Tests.csproj", "{18AD0249-0436-4A26-9972-B97BA6905A54}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -98,6 +103,30 @@ Global
{02284473-6DE7-4EE0-8433-2AC295045549}.Release|x64.Build.0 = Release|Any CPU
{02284473-6DE7-4EE0-8433-2AC295045549}.Release|x86.ActiveCfg = Release|Any CPU
{02284473-6DE7-4EE0-8433-2AC295045549}.Release|x86.Build.0 = Release|Any CPU
{6C102D4D-3DA4-4763-B75E-C15E33E7E94A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6C102D4D-3DA4-4763-B75E-C15E33E7E94A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6C102D4D-3DA4-4763-B75E-C15E33E7E94A}.Debug|x64.ActiveCfg = Debug|Any CPU
{6C102D4D-3DA4-4763-B75E-C15E33E7E94A}.Debug|x64.Build.0 = Debug|Any CPU
{6C102D4D-3DA4-4763-B75E-C15E33E7E94A}.Debug|x86.ActiveCfg = Debug|Any CPU
{6C102D4D-3DA4-4763-B75E-C15E33E7E94A}.Debug|x86.Build.0 = Debug|Any CPU
{6C102D4D-3DA4-4763-B75E-C15E33E7E94A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6C102D4D-3DA4-4763-B75E-C15E33E7E94A}.Release|Any CPU.Build.0 = Release|Any CPU
{6C102D4D-3DA4-4763-B75E-C15E33E7E94A}.Release|x64.ActiveCfg = Release|Any CPU
{6C102D4D-3DA4-4763-B75E-C15E33E7E94A}.Release|x64.Build.0 = Release|Any CPU
{6C102D4D-3DA4-4763-B75E-C15E33E7E94A}.Release|x86.ActiveCfg = Release|Any CPU
{6C102D4D-3DA4-4763-B75E-C15E33E7E94A}.Release|x86.Build.0 = Release|Any CPU
{18AD0249-0436-4A26-9972-B97BA6905A54}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{18AD0249-0436-4A26-9972-B97BA6905A54}.Debug|Any CPU.Build.0 = Debug|Any CPU
{18AD0249-0436-4A26-9972-B97BA6905A54}.Debug|x64.ActiveCfg = Debug|Any CPU
{18AD0249-0436-4A26-9972-B97BA6905A54}.Debug|x64.Build.0 = Debug|Any CPU
{18AD0249-0436-4A26-9972-B97BA6905A54}.Debug|x86.ActiveCfg = Debug|Any CPU
{18AD0249-0436-4A26-9972-B97BA6905A54}.Debug|x86.Build.0 = Debug|Any CPU
{18AD0249-0436-4A26-9972-B97BA6905A54}.Release|Any CPU.ActiveCfg = Release|Any CPU
{18AD0249-0436-4A26-9972-B97BA6905A54}.Release|Any CPU.Build.0 = Release|Any CPU
{18AD0249-0436-4A26-9972-B97BA6905A54}.Release|x64.ActiveCfg = Release|Any CPU
{18AD0249-0436-4A26-9972-B97BA6905A54}.Release|x64.Build.0 = Release|Any CPU
{18AD0249-0436-4A26-9972-B97BA6905A54}.Release|x86.ActiveCfg = Release|Any CPU
{18AD0249-0436-4A26-9972-B97BA6905A54}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -108,6 +137,8 @@ Global
{F188D4A7-BBCB-464F-A370-2BD84D18EA79} = {6ABD4842-47AF-49A5-B057-0EBA64416789}
{7CD09B89-130A-41AF-ADAE-2166C4ED695B} = {6491E321-2D02-44AB-9116-D722FE169595}
{02284473-6DE7-4EE0-8433-2AC295045549} = {6491E321-2D02-44AB-9116-D722FE169595}
{6C102D4D-3DA4-4763-B75E-C15E33E7E94A} = {28D4C365-FDED-49AE-A97D-36202E24A55A}
{18AD0249-0436-4A26-9972-B97BA6905A54} = {6491E321-2D02-44AB-9116-D722FE169595}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2F85D9DA-DBCF-4F13-8C42-5719F1469B2E}
Expand Down
14 changes: 14 additions & 0 deletions src/AsyncAPI.Saunter.Generator.Cli/Args.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

// ReSharper disable once CheckNamespace
public static partial class Program
{
internal const string StartupAssemblyArgument = "startupassembly";
internal const string DocOption = "--doc";
internal const string FormatOption = "--format";
internal const string FileNameOption = "--filename";
internal const string OutputOption = "--output";
internal const string EnvOption = "--env";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>12</LangVersion>
<RootNamespace>AsyncAPI.Saunter.Generator.Cli</RootNamespace>

<Description>AsyncAPI Command Line Tools</Description>
<Authors>AsyncAPI Initiative</Authors>
<PackAsTool>true</PackAsTool>
<PackageId>AsyncAPI.Saunter.Generator.Cli</PackageId>
<ToolCommandName>dotnet-asyncapi</ToolCommandName>
<PackageTags>asyncapi;aspnetcore;openapi;documentation;amqp;generator;cli;tool</PackageTags>
<PackageReadmeFile>readme.md</PackageReadmeFile>
<PackageIcon>logo.png</PackageIcon>
<RepositoryUrl>https://github.com/asyncapi/saunter</RepositoryUrl>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<PackageProjectUrl>https://github.com/asyncapi/saunter</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<Version>1.0.1</Version>
smoerijf marked this conversation as resolved.
Show resolved Hide resolved
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' != 'netstandard2.0' ">
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="AsyncAPI.NET.Readers" Version="5.2.1" />

<!-- Development Dependencies -->
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Saunter\Saunter.csproj" />
</ItemGroup>

<ItemGroup>
<None Include="readme.md" Pack="true" PackagePath="\"/>
<None Include="../../assets/logo.png" Pack="true" PackagePath="/" />
</ItemGroup>

</Project>
46 changes: 46 additions & 0 deletions src/AsyncAPI.Saunter.Generator.Cli/Commands/Tofile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Licensed to the .NET Foundation under one or more agreements.
smoerijf marked this conversation as resolved.
Show resolved Hide resolved
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Diagnostics;
using System.Reflection;
using static Program;

namespace AsyncApi.Saunter.Generator.Cli.Commands;

internal class Tofile
{
internal static Func<IDictionary<string, string>, int> Run(string[] args) => namedArgs =>
{
if (!File.Exists(namedArgs[StartupAssemblyArgument]))
{
throw new FileNotFoundException(namedArgs[StartupAssemblyArgument]);
}

var depsFile = namedArgs[StartupAssemblyArgument].Replace(".dll", ".deps.json");
var runtimeConfig = namedArgs[StartupAssemblyArgument].Replace(".dll", ".runtimeconfig.json");
var commandName = args[0];

var subProcessArguments = new string[args.Length - 1];
if (subProcessArguments.Length > 0)
{
Array.Copy(args, 1, subProcessArguments, 0, subProcessArguments.Length);
}

var assembly = typeof(Program).GetTypeInfo().Assembly;
var subProcessCommandLine =
$"exec --depsfile {EscapePath(depsFile)} " +
$"--runtimeconfig {EscapePath(runtimeConfig)} " +
$"{EscapePath(assembly.Location)} " +
$"_{commandName} {string.Join(" ", subProcessArguments.Select(EscapePath))}";

var subProcess = Process.Start("dotnet", subProcessCommandLine);
subProcess.WaitForExit();
return subProcess.ExitCode;
};

private static string EscapePath(string path)
{
return (path.Contains(' ') || string.IsNullOrWhiteSpace(path)) ? "\"" + path + "\"" : path;
}
}
Loading
Loading