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()))
    
    
  • 相关阅读:
    centos安装odoo10及安装问题解决
    crontab实现定时任务
    pycharm发布代码
    centos下安装dblib
    windows安装face_recognition并进行人脸对比
    centos安装nginx1.9
    win10安装fast_client
    WIN10搭建python最新环境
    Linux常见命令
    centos安装python3.7
  • 原文地址:https://www.cnblogs.com/weiyinfu/p/11574908.html
Copyright © 2011-2022 走看看