zoukankan      html  css  js  c++  java
  • 统计代码量

    cloc是一个perl写的统计代码量的工具,使用npm install -g cloc可以安装这个工具。

    tongji.cmd
    node %~dp0/tongji.js

    tongji.py

    /*
     * 统计代码量
     */
    var fs = require("fs")
    var path = require("path")
    
    var ignoreName = new Set(["node_modules", "dist", ".idea", "ElTree", "test"])
    var allowedFileType = new Set(["js", "vue", "less","java","py","c","cpp","go"])
    function go(folder) {
      var lineCount = {}
      for (var i of fs.readdirSync(folder)) {
        if (ignoreName.has(i)) continue
        if (fs.statSync(path.join(folder, i)).isDirectory()) {
          var res = go(path.join(folder, i))
          for (var i in res) {
            if (!lineCount[i]) {
              lineCount[i] = 0
            }
            lineCount[i] += res[i]
          }
        } else {
          var fileType = i.substring(i.lastIndexOf(".") + 1)
          if (!allowedFileType.has(fileType)) {
            continue
          }
          var now = fs
            .readFileSync(path.join(folder, i))
            .toString("utf8")
            .split("
    ").length
          console.log(path.relative(process.cwd(), path.join(folder, i)) + " " + now)
          if (!lineCount[fileType]) lineCount[fileType] = 0
          lineCount[fileType] += now
        }
      }
      return lineCount
    }
    
    console.log(go(process.cwd()))
    
    
  • 相关阅读:
    《构建之法》第五章读后感
    《构建之法》第四章读后感
    《构建之法》第三章读后感
    《构建之法》第二章读后感
    《构建之法》第一章读后感
    web mis系统构建
    异常
    多态
    接口与继承
    个人总结_5.8
  • 原文地址:https://www.cnblogs.com/weiyinfu/p/11574908.html
Copyright © 2011-2022 走看看