Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ summarize
.idea
.DS_Store
*.log
summaries/
summaries/
bin/
50 changes: 50 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Variables
APP_NAME=summarize
BUILD_DIR=bin
MAIN_PATH=.

# Go build flags
# -s: Strip symbols (reduces binary size)
# -w: Omit DWARF debugging information
LDFLAGS=-ldflags "-s -w"

.PHONY: all mac-intel mac-silicon linux-arm linux windows-arm windows clean test

# Create build directory if it doesn't exist
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)

# Build for all platforms
all: mac-intel mac-silicon linux linux-arm windows windows-arm

# Build for macOS Intel (amd64)
mac-intel: $(BUILD_DIR)
GOOS=darwin GOARCH=amd64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(APP_NAME)-darwin-amd64 $(MAIN_PATH)

# Build for macOS Silicon (arm64)
mac-silicon: $(BUILD_DIR)
GOOS=darwin GOARCH=arm64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(APP_NAME)-darwin-arm64 $(MAIN_PATH)

# Build for Linux ARM64
linux-arm: $(BUILD_DIR)
GOOS=linux GOARCH=arm64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(APP_NAME)-linux-arm64 $(MAIN_PATH)

# Build for Linux AMD64
linux: $(BUILD_DIR)
GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(APP_NAME)-linux-amd64 $(MAIN_PATH)

# Build for Windows AMD64
windows: $(BUILD_DIR)
GOOS=windows GOARCH=amd64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(APP_NAME)-windows-amd64.exe $(MAIN_PATH)

# Build for Windows ARM64
windows-arm: $(BUILD_DIR)
GOOS=windows GOARCH=arm64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(APP_NAME)-windows-arm64.exe $(MAIN_PATH)

# Clean build artifacts
clean:
rm -rf $(BUILD_DIR)

# Run tests
test:
./test.sh
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.0.0
v1.0.1
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/andreimerlescu/summarize

go 1.23.7
go 1.24

require (
github.com/andreimerlescu/checkfs v1.0.2
Expand Down
34 changes: 28 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const (
kVersion string = "v"
kDotFiles string = "ndf"
kMaxFiles string = "mf"
kDebug string = "debug"
)

var (
Expand All @@ -73,6 +74,7 @@ var (
// defaultAvoid are the -avoid list of substrings in file path names to avoid in the summary
defaultAvoid = []string{
".min.js", ".min.css", ".git/", ".svn/", ".vscode/", ".vs/", ".idea/", "logs/", "secrets/",
".venv/", "/site-packages", ".terraform/", "summaries/", "node_modules/",
}
)

Expand All @@ -92,12 +94,13 @@ func init() {
figs.NewString(kSourceDir, ".", "Absolute path of directory you want to summarize.")
figs.NewString(kOutputDir, filepath.Join(".", "summaries"), fmt.Sprintf("Path of the directory to write the %s file to", newSummaryFilename()))
figs.NewString(kFilename, newSummaryFilename(), "Output file of summary.md")
figs.NewList(kIncludeExt, defaultInclude, "List of extensions to include in summary.")
figs.NewList(kExcludeExt, defaultExclude, "List of extensions to include in summary.")
figs.NewList(kSkipContains, defaultAvoid, "List of extensions to avoid.")
figs.NewList(kIncludeExt, defaultInclude, "List of extensions to INCLUDE in summary.")
figs.NewList(kExcludeExt, defaultExclude, "List of extensions to EXCLUDE in summary.")
figs.NewList(kSkipContains, defaultAvoid, "List of path substrings if present to skip over full path.")
figs.NewInt(kMaxFiles, 20, "Maximum number of files to process concurrently")
figs.NewBool(kDotFiles, false, "Include dot files by setting this true")
figs.NewBool(kDotFiles, false, "Any path that is considered a dotfile can be included by setting this to true")
figs.NewBool(kVersion, false, "Display current version of summarize")
figs.NewBool(kDebug, false, "Enable debug mode")
// validators
figs.WithValidator(kSourceDir, figtree.AssureStringNotEmpty)
figs.WithValidator(kOutputDir, figtree.AssureStringNotEmpty)
Expand Down Expand Up @@ -158,6 +161,15 @@ func main() {
// check the -avoid list
for _, avoidThis := range *figs.List(kSkipContains) {
if strings.Contains(filename, avoidThis) {
if *figs.Bool(kDebug) {
fmt.Printf("ignoring %s\n", path)
}
return nil // skip without error
}
if strings.Contains(path, avoidThis) {
if *figs.Bool(kDebug) {
fmt.Printf("ignoring %s\n", path)
}
return nil // skip without error
}
}
Expand All @@ -170,6 +182,9 @@ func main() {
// check the -exc list
for _, excludeThis := range *figs.List(kExcludeExt) {
if strings.EqualFold(excludeThis, ext) {
if *figs.Bool(kDebug) {
fmt.Printf("ignoring %s\n", path)
}
return nil // skip without error
}
}
Expand All @@ -184,6 +199,13 @@ func main() {
return nil
}))

if *figs.Bool(kDebug) {
fmt.Println("data received: ")
for ext, paths := range data {
fmt.Printf("%s: %s\n", ext, strings.Join(paths, ", "))
}
}

maxFileSemaphore := sema.New(*figs.Int(kMaxFiles))
writeChan := make(chan []byte, 10240)
writerWG := sync.WaitGroup{}
Expand All @@ -205,8 +227,8 @@ func main() {
}()

for ext, paths := range data { // range over data to get ext and paths
throttler.Acquire() // throttler is used to protect the runtime from excessive use
wg.Add(1) // wg is used to prevent the runtime from exiting early
throttler.Acquire() // throttler is used to protect the runtime from excessive use
wg.Add(1) // wg is used to prevent the runtime from exiting early
go func(ext string, paths []string) { // run this extension in a goroutine
defer throttler.Release() // when we're done, release the throttler
defer wg.Done() // then tell the sync.WaitGroup that we are done
Expand Down