@n1kk/git-count
    TypeScript icon, indicating that this package has built-in type declarations

    0.1.7 • Public • Published

    Analyzes git diff files and separates them into categories that you specify. Produces colorized output for console.

    Usage

    JavaScript

    // count-lines.js
    const countLines = require("git-count");
    const testConfig = {
        source: {
            code: {
                include: {
                    code: /(src|styles|public)\/.*\.(jsx?|tsx?|[sp]?css|vue|html)/
                },
                exclude: {
                    specs: /\.specs?\./,
                    tests: /\s*tests\//
                }
            },
            tests: {
                include: {
                    specs: /\.specs?\./,
                    tests: /\s*tests\//
                }
            }
        },
        configs: {
            include: {
                dotFiles: /^\..*|\/\..*/,
                dotConfig: /.*\.config\..*/,
                configExts: /\.(json|yml|cgf|rc|toml|ini|properties)/
            },
            exclude: {
                packageLock: /package-lock\.json|yarn\.lock/
            }
        }
    }
    (async () => {
        try {
            const output = await countLines.countLines({
                config: testConfig,
                verbose: true,
                categories: [] // prints all categories
                // categories: ["source"], // will print both source subcats
                // categories: ["source:code"], // will print only code subcat
            });
            console.log(output);
        }
        catch (e) {
            console.error(e);
        }
    })();

    TypeScript

    // count-lines.ts
    
    import { CategoriesConfig, countLines } from "git-count";
    
    const testConfig: CategoriesConfig = {
        source: {
            code: {
                include: {
                    code: /(src|styles|public)\/.*\.(jsx?|tsx?|[sp]?css|vue|html)/
                },
                exclude: {
                    specs: /\.specs?\./,
                    tests: /\s*tests\//
                }
            },
            tests: {
                include: {
                    specs: /\.specs?\./,
                    tests: /\s*tests\//
                }
            }
        },
        configs: {
            include: {
                dotFiles: /^\..*|\/\..*/,
                dotConfig: /.*\.config\..*/,
                configExts: /\.(json|yml|cgf|rc|toml|ini|properties)/
            },
            exclude: {
                packageLock: /package-lock\.json|yarn\.lock/
            }
        }
    };
    
    async function main() {
    
        try {
            const verb = process.argv.includes("--verb")
            const cats = process.argv.slice(2).filter(arg => !arg.startsWith("--"))
    
            const output = await countLines({
                config: testConfig,
                verbose: verb,
                categories: cats
            })
    
            console.log(output)
        } catch (e) {
            console.error(e)
        }
    
    }
    
    main()

    You can add your scipt to git aliases for quick access

    git config --local alias.count "!node count-lines.js"
    git config --local alias.count "!ts-node count-lines.ts"
    $ git count
     source:code     #8   +183  -234   417    (-51)
     source:tests    #2     +2    -2     4      (0)
     configs        #10    +71  -254   325   (-183)
     scripts         #9   +674   -83   757   (+591)
     text            #2    +11   -11    22      (0)
     assets          #0      0     0     0      (0)
     docs            #2    +47   -32    79    (+15)
     uncategorized   #3  +2621  -385  3006  (+2236)
    
    Total:  36 files changed, 3602 insertions(+), 1001 deletions(-)
    
    $ git count source
     source:code   #8  +183  -234  417  (-51)
     source:tests  #2    +2    -2    4    (0)
    
    Total:  36 files changed, 3610 insertions(+), 1001 deletions(-)
    
    $ git count source --verb
     source:code                                                    #8  +183  -234  417   (-51)
       public/index.html                                          code     0    -1    1    (-1)
       src/Application.ts                                         code    +3    -1    4    (+2)
       src/main.ts                                                code   +68   -26   94   (+42)
       src/worker.ts                                              code   +51   -37   88   (+14)
       src/cache.ts                                               code   +52   -29   81   (+23)
       src/shims-global.d.ts                                      code    +2    -1    3    (+1)
       src/views/Main.view.scss                                   code    +5  -107  112  (-102)
       src/views/Main.view.ts                                     code    +2   -32   34   (-30)
     source:tests                                                   #2    +2    -2    4     (0)
       src/LifeGuard.spec.ts                                     specs    +1    -1    2     (0)
       src/gService.spec.ts                                      specs    +1    -1    2     (0)
    
    Total:  36 files changed, 3609 insertions(+), 1001 deletions(-)
    

    Install

    npm i @n1kk/git-count

    DownloadsWeekly Downloads

    2

    Version

    0.1.7

    License

    MIT

    Unpacked Size

    38.5 kB

    Total Files

    21

    Last publish

    Collaborators

    • n1kk