Moved to ADO2024 PI#
Ran SortCodeMethods
This commit is contained in:
62
ADO2024/PI1/Helper-2024-04-17.cs
Normal file
62
ADO2024/PI1/Helper-2024-04-17.cs
Normal file
@ -0,0 +1,62 @@
|
||||
using File_Folder_Helper.Helpers;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace File_Folder_Helper.ADO2024.PI1;
|
||||
|
||||
internal static partial class Helper20240417
|
||||
{
|
||||
|
||||
private static void RunCommand(ILogger<Worker> logger, string directory, string commandFileName, List<string> files, int before, CancellationToken cancellationToken)
|
||||
{
|
||||
bool usePathCombine = false;
|
||||
string command = $"npx eclint fix {string.Join(' ', files)}";
|
||||
string output = HelperNPM.RunCommand(commandFileName, command, directory);
|
||||
logger.LogInformation(output);
|
||||
if (output.Contains("error", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Environment.ExitCode = 2;
|
||||
logger.LogCritical("Setting exit code {ExitCode}", Environment.ExitCode);
|
||||
throw new Exception(output);
|
||||
}
|
||||
ReadOnlyCollection<string> afterGitOthersModifiedAndDeletedExcludingStandardFiles = HelperGit.GetOthersModifiedAndDeletedExcludingStandardFiles(directory, usePathCombine, cancellationToken);
|
||||
int after = afterGitOthersModifiedAndDeletedExcludingStandardFiles.Count;
|
||||
if (before != after)
|
||||
{
|
||||
List<string> fileNames = [];
|
||||
foreach (string file in afterGitOthersModifiedAndDeletedExcludingStandardFiles)
|
||||
{
|
||||
if (file.Contains(' '))
|
||||
continue;
|
||||
if (files.Contains(file))
|
||||
continue;
|
||||
fileNames.Add(Path.GetFileName(file));
|
||||
}
|
||||
Environment.ExitCode = 1;
|
||||
throw new Exception($"Files were modified exiting with exit code {Environment.ExitCode}!{Environment.NewLine}{string.Join(Environment.NewLine, fileNames)}");
|
||||
}
|
||||
}
|
||||
|
||||
internal static void FilteredRunCommand(ILogger<Worker> logger, List<string> args, CancellationToken cancellationToken)
|
||||
{
|
||||
List<string> files = [];
|
||||
string directory = args[0];
|
||||
bool usePathCombine = false;
|
||||
string commandFileName = args[2];
|
||||
ReadOnlyCollection<string> gitOthersModifiedAndDeletedExcludingStandardFiles = HelperGit.GetOthersModifiedAndDeletedExcludingStandardFiles(directory, usePathCombine, cancellationToken);
|
||||
int before = gitOthersModifiedAndDeletedExcludingStandardFiles.Count;
|
||||
foreach (string file in gitOthersModifiedAndDeletedExcludingStandardFiles)
|
||||
{
|
||||
if (file.Contains(' '))
|
||||
{
|
||||
logger.LogInformation("Skipping <{File}>", file);
|
||||
continue;
|
||||
}
|
||||
files.Add(file);
|
||||
}
|
||||
logger.LogInformation("{directory} has {files} file(s)", directory, before);
|
||||
if (files.Count > 0)
|
||||
RunCommand(logger, directory, commandFileName, files, before, cancellationToken);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user