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

feat(): adjust apigenerator to use dotnet format #747

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

joefeser
Copy link
Contributor

@joefeser joefeser commented Aug 8, 2024

Description

Adjust the generator to use dotnet format

Issues Resolved

Request from #739, Phase 1

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@joefeser joefeser changed the title Feat/api generator use dotnetformat main feat(): adjust apigenerator to use dotnet format Aug 8, 2024
@joefeser joefeser force-pushed the feat/api-generator-use-dotnetformat-main branch 2 times, most recently from bb21002 to 7abde69 Compare August 8, 2024 02:23
Comment on lines 178 to 216
var rootPath = GetRootPath(typeof(Program).Assembly.Location);

var relativeFolderList = new List<string>();

foreach (var item in Generator.ApiGenerator.GeneratedFilePaths)
{
var relativePath = item.Replace(rootPath.FullName, string.Empty);
relativeFolderList.Add($".{relativePath.Replace("\\", "/")}");
}

var si = new System.Diagnostics.ProcessStartInfo
{
WorkingDirectory = rootPath.FullName,
FileName = "dotnet",
Arguments = "format -v diag --include " + string.Join(' ', relativeFolderList.Select(item => $"{item}")),
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true,
};

var process = System.Diagnostics.Process.Start(si);

Console.WriteLine();
Console.WriteLine($"Running dotnet format --include {string.Join(' ', relativeFolderList.Select(item => $"{item}"))} -v diag");

// hookup the eventhandlers to capture the data that is received
process.OutputDataReceived += (sender, args) => Console.WriteLine(args.Data);
process.ErrorDataReceived += (sender, args) => Console.WriteLine(args.Data);

process.Start();

// start our event pumps
process.BeginOutputReadLine();
process.BeginErrorReadLine();

process.WaitForExit();
Console.WriteLine();
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you add a package reference on Proc = 0.8.1 which is already used by other projects in the solution, this could be simplified down to something like:

            Proc.Exec(new ExecArguments("dotnet", "format", "--verbosity", "normal", "--include", "./src/*/_Generated/")
            {
                WorkingDirectory = GeneratorLocations.SolutionFolder
            })

And just define GeneratorLocations.SolutionFolder as something like:

        public static string SolutionFolder { get; } = $"{Root}../../";

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem, thank you for the feedback. I will make the changes this evening

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PR Comments resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Xtansia I updated the pr off the current main branch. If you ignore _generated files, there are less than 20 files to review.

@joefeser joefeser force-pushed the feat/api-generator-use-dotnetformat-main branch from 2338330 to 384648d Compare August 10, 2024 01:02
@joefeser joefeser force-pushed the feat/api-generator-use-dotnetformat-main branch from 44310c0 to 439ec72 Compare August 16, 2024 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants