projectinfo

package module
v1.3.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 30, 2024 License: BSD-3-Clause Imports: 15 Imported by: 1

README

projectinfo

Go Report Card GoDoc License

Given a directory of source code, gather all sorts of info and output is as chunks of JSON.

Example usage:

package main

import (
    "fmt"
    "os"

    "github.com/xyproto/projectinfo"
)

func OutputChunks(dir string) error {
    const printWarnings = true
    pInfo, err := projectinfo.New(dir, printWarnings)
    if err != nil {
        return err
    }
    chunks, err := pInfo.Chunk(true, true)
    if err != nil {
        return err
    }
    for _, chunk := range chunks {
        fmt.Println(chunk)
    }
    return nil
}

func main() {
    // Check for command line arguments
    if len(os.Args) < 2 {
        fmt.Println("Usage: info [directory]")
        os.Exit(1)
    }

    // The first argument should be the directory to scan
    dir := os.Args[1]

    // Set the maximum token limit per chunk (approximate)
    projectinfo.SetMaxTokensPerChunk(16 * 1024)

    if err := OutputChunks(dir); err != nil {
        fmt.Printf("Failed to output project chunks: %v\n", err)
        os.Exit(1)
    }

}

General info

  • Version: 1.3.6
  • License: BSD-3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertToUTF8

func ConvertToUTF8(b []byte) ([]byte, error)

ConvertToUTF8 attempts to convert a byte slice to UTF-8 encoding, managing non-UTF8 encoded parts.

func CountLines

func CountLines(content string) (int, error)

CountLines counts the number of lines in a string, often used to determine the size of file contents

func CountTokens

func CountTokens(input string) int

CountTokens estimates the number of tokens in a string based on UTF-8 rune count

func DetectProjectType

func DetectProjectType(files []FileInfo) string

DetectProjectType determines the most common programming language used in the project files to suggest the project's type

func GitContributors

func GitContributors(path string) ([]string, error)

Contributors uses the Git command line to fetch a list of contributors sorted by the number of commits

func LanguageFromExtension

func LanguageFromExtension(ext string) string

LanguageFromExtension determines the programming language from the file extension

func LoadIgnorePatterns

func LoadIgnorePatterns(filenames ...string) (map[string]struct{}, error)

LoadIgnorePatterns loads patterns from specified filenames to ignore during file operations

func OptimizeCode

func OptimizeCode(source string, ext string) string

OptimizeCode optimizes the source code by normalizing line breaks, trimming unnecessary whitespace, and reducing blank lines.

func ParseContributor

func ParseContributor(line string) string

parseContributor extracts the name of the contributor from a line of git shortlog output.

func PossiblyAPIServer added in v1.1.1

func PossiblyAPIServer(dir string) bool

PossiblyAPIServer tries to detect if the source code in the given directory is likely to be an API server.

func ReadProjectName

func ReadProjectName(dir string) (string, error)

ReadProjectName tries to deduce the project name from common configuration files.

func RecognizedExtension

func RecognizedExtension(path string, docAndConf bool) bool

RecognizedExtension checks if the file extension is recognized and should be included based on the docAndConf flag

func RecognizedFilename added in v1.2.3

func RecognizedFilename(path string, docAndConf bool) bool

RecognizedFilename checks if the given path is a recgonized filename, like "LICENSE"

func ShouldSkip

func ShouldSkip(path string, ignores map[string]struct{}) bool

ShouldSkip determines if a directory should be skipped based on ignore patterns

func StripCodeBlockMarkers

func StripCodeBlockMarkers(input string) string

StripCodeBlockMarkers removes leading and trailing Markdown code block markers (```)

func URLFromGitConfig

func URLFromGitConfig(configFilePath string) (string, error)

URLFromGitConfig reads the .git/config file and extracts the repository URL from the "remote origin" section

Types

type CsProj

type CsProj struct {
	XMLName        xml.Name        `xml:"Project"`
	PropertyGroups []PropertyGroup `xml:"PropertyGroup"`
}

type FileInfo

type FileInfo struct {
	Path         string   `json:"path"`
	Language     string   `json:"language"`
	LastModified string   `json:"last_modified,omitempty"`
	Contents     string   `json:"contents,omitempty"`
	LineCount    int      `json:"line_count,omitempty"`
	TokenCount   int      `json:"token_count"`
	Contributors []string `json:"contributors"`
}

FileInfo represents information about a file in the project, including its content-related attributes

func CollectFiles

func CollectFiles(dir string, ignores map[string]struct{}, alsoDocOrConf, alsoContributors, verbose bool) ([]FileInfo, error)

CollectFiles walks through a directory recursively and collects files that have the right extensions

func FindFileName

func FindFileName(files []FileInfo, searchString string) FileInfo

FindFileName returns the first file that has a filename that matches the given string

type PomProject

type PomProject struct {
	XMLName xml.Name `xml:"project"`
	Name    string   `xml:"name"`
}

type ProjectInfo

type ProjectInfo struct {
	Name            string     `json:"name"`
	RepoURL         string     `json:"repositoryURL"`
	SourceFiles     []FileInfo `json:"sourceFiles"`
	ConfAndDocFiles []FileInfo `json:"confAndDocFiles"`
	Type            string     `json:"type"`
	Contributors    string     `json:"contributors"`
	APIServer       bool       `json:"apiServer"`
}

ProjectInfo holds information about the entire project, useful for generating documentation or other reports.

func New

func New(dir string, verbose bool) (ProjectInfo, error)

func (*ProjectInfo) AllFiles added in v1.2.0

func (project *ProjectInfo) AllFiles() []FileInfo

type PropertyGroup

type PropertyGroup struct {
	ProjectName string `xml:"AssemblyName"`
}

Directories

Path Synopsis
cmd
info command
projectname command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL