1 Star 1 Fork 0

theajack / count-code-line

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

count-code-line

计算项目代码行数和字符串的工具

0. 特性

  1. 支持计算代码行数和代码字符数
  2. 丰富的配置文件,支持匹配任意规则的文件或文件夹
  3. 支持生成计算结果的json
  4. 支持全局安装命令行使用

1. 安装

1.1 全局安装

npm i count-code-line -g

1.2 本地安装

npm i count-code-line -D

2. 使用

2.1 全局安装使用

在任意项目内打开命令行工具,运行一下命令即可

count-code-line

运行成功会在根目录下输出 count.output.json 文件

2.2 本地安装使用

在 package.json 文件中 的scripts属性中加入如下配置

    ...
    "scripts": {
        ...
        "count": "count-code-line"
    },
    ...

然后在根目录下运行

npm run count

运行成功会在根目录下输出 count.output.json 文件

2.3 nodejs 引用

const count = require('count-code-line');
count();

3. 配置文件

3.1 默认配置文件及配置项

count-code-line 支持自定义配置文件,以下是默认配置

module.exports = {
    includes: [], // 需要包含的目录及文件 默认全部包含
    excludes: [], // 需要排除的目录及文件 默认全部移除
    defaultExcludes: [ // 默认排除的目录及文件
        '.git',
        '.vscode',
        'node_modules',
        'package.json',
        'package-lock.json',
        'yarn-lock.json',
        'count.output.json',
    ],
    defaultExcludesFileType: [ // 默认排除的文件类型
        '.zip', '.rar', '.png', '.jpg', '.jpeg', '.gif', '.bmp', '.mp3', '.wma', '.wav', '.mp4', '.flv', '.mov', '.avi', '.wmv', '.rmvb ', '.ogg', '.avi', '.ppt', '.pptx', '.doc','.docx','.xls','.xlsx','.psd','.ttf','.fon','.exe','.msi',
    ],
    output: 'count.output.json', // 默认的输出结果文件
    outputTrace: '', // 配置输出 trace 结果的文件,默认不输出
    encodings: [ // 支持的文件编码,对于不支持的文件将忽略
        'ascii',
        'utf8',
        'utf-8',
        'unicode'
    ]
};

3.2 自定义配置文件

在项目根目录下新建 count.config.js 文件 写入上述配置覆盖默认配置即可

对于为空的配置项,将使用默认配置

3.3 目录匹配规则

includes excludes 等配置项均支持模糊匹配,匹配规则如下

'a' 将匹配 根目录下 a 文件夹内的所有文件及文件夹;正则: new RegExp(^/a/.*)

'a/a.js' 仅匹配指定文件

'a/*' 仅匹配 a 文件夹内的所有子文件; 正则: new RegExp(^/a/([^/])*$)

'a/**/*.js' 匹配 a 文件夹内的所有以 .js 为后缀的文件; 正则: new RegExp(^/a/([^/])*.js$)

'a/*.js' 仅匹配 a 文件夹内的所有以 .js 为后缀的子文件; 正则: new RegExp(^/a/([^/])*.js$)

The MIT License (MIT) Copyright (c) 2017 - present theajack <contact@theajack.com> All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

Count lines and characters for your project 展开 收起
JavaScript
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
JavaScript
1
https://gitee.com/theajack/count-code-line.git
git@gitee.com:theajack/count-code-line.git
theajack
count-code-line
count-code-line
master

搜索帮助