Kanban Index for Typescript Helper
This commit is contained in:
@ -102,10 +102,10 @@ internal static partial class HelperKanbanMetadata
|
||||
return results;
|
||||
}
|
||||
|
||||
private static void WriteKanbanBoardFile(string fullPath, List<Record> records, string h1)
|
||||
private static void WriteKanbanBoardFile(string directory, List<Record> records, string h1)
|
||||
{
|
||||
string? last = null;
|
||||
List<string> lines = [h1, string.Empty];
|
||||
List<string> lines = [h1];
|
||||
foreach (Record record in records)
|
||||
{
|
||||
if (last is null || record.Group != last)
|
||||
@ -117,56 +117,64 @@ internal static partial class HelperKanbanMetadata
|
||||
lines.Add($"- [ ] {Path.GetFileNameWithoutExtension(record.FileInfo.Name)}");
|
||||
last = record.Group;
|
||||
}
|
||||
File.WriteAllLines(Path.Combine(fullPath, "index.knb.md"), lines);
|
||||
File.WriteAllLines(Path.Combine(directory, "index.knb.md"), lines);
|
||||
}
|
||||
|
||||
internal static void SetMetadata(ILogger log, AppSettings appSettings, string sourceDirectory)
|
||||
internal static void SetMetadata(string sourceDirectory, string indexFile)
|
||||
{
|
||||
bool? match;
|
||||
string? paramCase;
|
||||
string statusLine;
|
||||
List<string> lines;
|
||||
LineNumber lineNumber;
|
||||
if (log is null)
|
||||
throw new NullReferenceException();
|
||||
FileInfo fileInfo = new(indexFile);
|
||||
string? directory = Path.GetDirectoryName(sourceDirectory);
|
||||
(lines, lineNumber) = HelperMarkdown.GetStatusAndFrontMatterYamlEndLineNumbers(fileInfo);
|
||||
ReadOnlyCollection<string> indexFileLines = new(lines);
|
||||
List<Record> records = GetCollectionFromIndex(sourceDirectory, indexFileLines);
|
||||
if (directory is not null && lineNumber.H1 is not null)
|
||||
{
|
||||
string checkDirectory = Path.Combine(directory, ".vscode", "helper");
|
||||
if (Directory.Exists(checkDirectory))
|
||||
WriteKanbanBoardFile(checkDirectory, records, indexFileLines[lineNumber.H1.Value]);
|
||||
}
|
||||
foreach (Record record in records)
|
||||
{
|
||||
if (record.ItemLineNumber == 0)
|
||||
throw new NotSupportedException();
|
||||
(lines, lineNumber) = HelperMarkdown.GetStatusAndFrontMatterYamlEndLineNumbers(record.FileInfo);
|
||||
if (lines.Count == 0)
|
||||
continue;
|
||||
statusLine = $"status: \"{record.GroupCount}-{record.Group}\"";
|
||||
paramCase = lineNumber.H1 is null ? null : GetParamCase(lines[lineNumber.H1.Value]);
|
||||
match = lineNumber.H1 is null || paramCase is null ? null : Path.GetFileNameWithoutExtension(record.FileInfo.Name) == paramCase;
|
||||
if (lineNumber.FrontMatterYamlEnd is null)
|
||||
throw new NotSupportedException($"{nameof(SetMetadata)} must be executed first!");
|
||||
if (lineNumber.H1 is not null && paramCase is not null && match is not null && !match.Value)
|
||||
lines[lineNumber.H1.Value] = $"# {paramCase}";
|
||||
if (lineNumber.Status is null)
|
||||
lines.Insert(lineNumber.FrontMatterYamlEnd.Value, statusLine);
|
||||
else
|
||||
{
|
||||
if ((match is null || match.Value) && lines[lineNumber.Status.Value] == statusLine)
|
||||
continue;
|
||||
lines[lineNumber.Status.Value] = statusLine;
|
||||
}
|
||||
File.WriteAllLines(record.FileInfo.FullName, lines);
|
||||
}
|
||||
}
|
||||
|
||||
internal static void SetMetadata(ILogger logger, string sourceDirectory)
|
||||
{
|
||||
TestParamCases();
|
||||
string fullPath = Path.GetFullPath(sourceDirectory);
|
||||
if (!Directory.Exists(fullPath))
|
||||
_ = Directory.CreateDirectory(fullPath);
|
||||
string indexFile = Path.Combine(fullPath, "index.md");
|
||||
if (File.Exists(indexFile))
|
||||
{
|
||||
FileInfo fileInfo = new(indexFile);
|
||||
(lines, lineNumber) = HelperMarkdown.GetStatusAndFrontMatterYamlEndLineNumbers(fileInfo);
|
||||
ReadOnlyCollection<string> indexFileLines = new(lines);
|
||||
List<Record> records = GetCollectionFromIndex(sourceDirectory, indexFileLines);
|
||||
if (lineNumber.H1 is not null)
|
||||
WriteKanbanBoardFile(fullPath, records, indexFileLines[lineNumber.H1.Value]);
|
||||
foreach (Record record in records)
|
||||
{
|
||||
if (record.ItemLineNumber == 0)
|
||||
throw new NotSupportedException();
|
||||
(lines, lineNumber) = HelperMarkdown.GetStatusAndFrontMatterYamlEndLineNumbers(record.FileInfo);
|
||||
if (lines.Count == 0)
|
||||
continue;
|
||||
statusLine = $"status: \"{record.GroupCount}-{record.Group}\"";
|
||||
paramCase = lineNumber.H1 is null ? null : GetParamCase(lines[lineNumber.H1.Value]);
|
||||
match = lineNumber.H1 is null || paramCase is null ? null : Path.GetFileNameWithoutExtension(record.FileInfo.Name) == paramCase;
|
||||
if (lineNumber.FrontMatterYamlEnd is null)
|
||||
throw new NotSupportedException($"{nameof(SetMetadata)} must be executed first!");
|
||||
if (lineNumber.H1 is not null && paramCase is not null && match is not null && !match.Value)
|
||||
lines[lineNumber.H1.Value] = $"# {paramCase}";
|
||||
if (lineNumber.Status is null)
|
||||
lines.Insert(lineNumber.FrontMatterYamlEnd.Value, statusLine);
|
||||
else
|
||||
{
|
||||
if ((match is null || match.Value) && lines[lineNumber.Status.Value] == statusLine)
|
||||
continue;
|
||||
lines[lineNumber.Status.Value] = statusLine;
|
||||
}
|
||||
File.WriteAllLines(record.FileInfo.FullName, lines);
|
||||
}
|
||||
}
|
||||
SetMetadata(fullPath, indexFile);
|
||||
else
|
||||
logger.LogInformation("<{indexFile}> doesn't exist!", indexFile);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user