Can you get the number of lines of code from a GitHub repository?

前端 未结 15 1191
庸人自扰
庸人自扰 2020-12-04 04:26

In a GitHub repository you can see “language statistics”, which displays the percentage of the project that’s written in a language. It doesn’t, however, display ho

15条回答
  •  死守一世寂寞
    2020-12-04 04:54

    npm install sloc -g
    
    git clone --depth 1 https://github.com/vuejs/vue/
    sloc ".\vue\src" --format cli-table
    rm -rf ".\vue\"
    

    Instructions and Explanation

    1. Install sloc from npm, a command line tool (Node.js needs to be installed).
    npm install sloc -g
    
    1. Clone shallow repository (faster download than full clone).
    git clone --depth 1 https://github.com/facebook/react/
    
    1. Run sloc and specifiy the path that should be analyzed.
    sloc ".\react\src" --format cli-table
    

    sloc supports formatting the output as a cli-table, as json or csv. Regular expressions can be used to exclude files and folders (Further information on npm).

    1. Delete repository folder (optional)

    Powershell: rm -r -force ".\react\" or on Mac/Unix: rm -rf ".\react\"

    Screenshots of the executed steps (cli-table):

    sloc output (no arguments):

    It is also possible to get details for every file with the --details option:

    sloc ".\react\src" --format cli-table --details     
    

提交回复
热议问题