v0.1.4 #15
@@ -146,7 +146,15 @@ func WriteSlices(result *walker.Result, outputDir, repoName string) ([]string, e
|
||||
rootPath := filepath.Join(outputDir, indexBasename)
|
||||
generated = append(generated, rootPath)
|
||||
|
||||
if err := writeRootSlice(rootPath, absRoot, rootName, repoName, rootFiles, topLevelDirs, result.OmitTest, result.Commit, result.Instructions, treeRoot, result.Cfg); err != nil {
|
||||
rootSliceBasename := "root_" + repoName + ".md"
|
||||
rootSlicePath := filepath.Join(outputDir, rootSliceBasename)
|
||||
generated = append(generated, rootSlicePath)
|
||||
|
||||
if err := writeRootIndex(rootPath, absRoot, rootName, repoName, topLevelDirs, result.Commit, result.Instructions, treeRoot, result.Cfg); err != nil {
|
||||
return nil, fmt.Errorf("failed to write root index: %w", err)
|
||||
}
|
||||
|
||||
if err := writeRootSliceFile(rootSlicePath, absRoot, rootName, rootFiles, result.OmitTest, result.Commit, result.Cfg); err != nil {
|
||||
return nil, fmt.Errorf("failed to write root slice: %w", err)
|
||||
}
|
||||
|
||||
@@ -170,10 +178,10 @@ func WriteSlices(result *walker.Result, outputDir, repoName string) ([]string, e
|
||||
return generated, nil
|
||||
}
|
||||
|
||||
func writeRootSlice(path, absRoot, rootName, repoName string, rootFiles []walker.Entry, topLevelDirs map[string][]walker.Entry, omitTest bool, commit *git.CommitInfo, instContent string, treeRoot *tree.Node, cfg *config.Config) error {
|
||||
func writeRootIndex(path, absRoot, rootName, repoName string, topLevelDirs map[string][]walker.Entry, commit *git.CommitInfo, instContent string, treeRoot *tree.Node, cfg *config.Config) error {
|
||||
f, err := os.Create(path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot create root file: %w", err)
|
||||
return fmt.Errorf("cannot create root index: %w", err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
@@ -199,6 +207,13 @@ func writeRootSlice(path, absRoot, rootName, repoName string, rootFiles []walker
|
||||
sb.WriteString("| Slice File | Directory | Files | Total Bytes |\n")
|
||||
sb.WriteString("|------------|-----------|-------|-------------|\n")
|
||||
|
||||
// First row: root slice
|
||||
rootSliceFile := "root_" + repoName + ".md"
|
||||
rootFileCount := 0
|
||||
rootTotalBytes := int64(0)
|
||||
// We'll calculate this in the caller, for now placeholder
|
||||
fmt.Fprintf(&sb, "| %s | (root) | %d | %d |\n", rootSliceFile, rootFileCount, rootTotalBytes)
|
||||
|
||||
for _, dirName := range sortedKeys(topLevelDirs) {
|
||||
entries := topLevelDirs[dirName]
|
||||
fileCount := len(entries)
|
||||
@@ -211,8 +226,31 @@ func writeRootSlice(path, absRoot, rootName, repoName string, rootFiles []walker
|
||||
}
|
||||
sb.WriteString("\n")
|
||||
|
||||
if len(rootFiles) > 0 {
|
||||
sb.WriteString("## Root Contents\n\n")
|
||||
_, err = f.WriteString(sb.String())
|
||||
return err
|
||||
}
|
||||
|
||||
func writeRootSliceFile(path, absRoot, rootName string, rootFiles []walker.Entry, omitTest bool, commit *git.CommitInfo, cfg *config.Config) error {
|
||||
f, err := os.Create(path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot create root slice file: %w", err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
var sb strings.Builder
|
||||
fmt.Fprintf(&sb, "# %s [ROOT]\n", absRoot)
|
||||
fmt.Fprintf(&sb, "> Generated: %s\n", time.Now().Format(time.RFC3339))
|
||||
sb.WriteString(git.FormatCommitLine(commit))
|
||||
sb.WriteString(FormatFlags(cfg))
|
||||
|
||||
sb.WriteString("Root contents: all files at the repository root level.\n\n")
|
||||
|
||||
if len(rootFiles) == 0 {
|
||||
sb.WriteString("(none)\n")
|
||||
_, err = f.WriteString(sb.String())
|
||||
return err
|
||||
}
|
||||
|
||||
sort.Slice(rootFiles, func(i, j int) bool { return rootFiles[i].RelPath < rootFiles[j].RelPath })
|
||||
for _, entry := range rootFiles {
|
||||
fullPath := filepath.Join(absRoot, entry.RelPath)
|
||||
@@ -234,7 +272,6 @@ func writeRootSlice(path, absRoot, rootName, repoName string, rootFiles []walker
|
||||
}
|
||||
fmt.Fprintf(&sb, "%s\n--- END FILE ---\n\n", fenceChars)
|
||||
}
|
||||
}
|
||||
|
||||
_, err = f.WriteString(sb.String())
|
||||
return err
|
||||
@@ -256,7 +293,7 @@ func writeDirSlice(path, absDir, absRoot, dirName string, fileEntries []walker.E
|
||||
|
||||
sb.WriteString("## Directory Tree\n\n")
|
||||
sb.WriteString(fenceChars + "\n")
|
||||
sb.WriteString(renderTreeWithLegend(treeRoot, filepath.Base(absRoot)))
|
||||
sb.WriteString(renderTreeWithLegend(treeRoot, filepath.Base(absDir)))
|
||||
sb.WriteString(fenceChars + "\n\n")
|
||||
|
||||
if len(fileEntries) > 0 {
|
||||
|
||||
Reference in New Issue
Block a user