統計代碼量


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("\n").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()))


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM