Empty file ISO Add date back for just .kanbn Removed HardcodedFileSearchAndSort Sync with 01-23 JsonToTsv System.Text.Json White-List Ready to move to Move Helper Remove Whitelist Force Start At Check for .git directory before ls Optional Allow root for unc path nuget bump PreVerify EnforceCodeStyleInBuild dotnet_analyzer_diagnostic HelperGit searchDelegate Host File AlertIfNewDeviceIsConnected AOT SetFrontMatterAndH1 Match Error Unknown with better logging Undo 04-05 WriteAppendToHostConfFile MonA IsKanbanIndex Dotnet Format Pre-commit NPM CreateWindowsShortcut Working directory Split description Copy tests Ready to test Delete after a couple of days GitConfigCleanUp knb Files
62 lines
2.7 KiB
C#
62 lines
2.7 KiB
C#
using File_Folder_Helper.Helpers;
|
|
using Microsoft.Extensions.Logging;
|
|
using System.Collections.ObjectModel;
|
|
|
|
namespace File_Folder_Helper.Day;
|
|
|
|
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);
|
|
}
|
|
|
|
} |