mirror of
https://github.com/unanmed/HumanBreak.git
synced 2025-01-18 20:09:27 +08:00
改进行数输出
This commit is contained in:
parent
e9821ef1e5
commit
6404c6f4d0
@ -2,22 +2,37 @@ import fs from 'fs-extra';
|
||||
import { extname, resolve } from 'path';
|
||||
|
||||
(async function () {
|
||||
const dir = './src';
|
||||
const dir = process.argv[2] || './src';
|
||||
let totalLines = 0;
|
||||
let totalFiles = 0;
|
||||
const list: Record<string, [number, number]> = {};
|
||||
const ignoreDir = [
|
||||
'node_modules',
|
||||
'floors',
|
||||
'thirdparty',
|
||||
'dist',
|
||||
'_bundle'
|
||||
];
|
||||
const ignoreFile = ['.d.ts', '.min.'];
|
||||
const exts = [
|
||||
'.ts',
|
||||
'.tsx',
|
||||
'.js',
|
||||
'.jsx',
|
||||
'.vue',
|
||||
'.less',
|
||||
'.css',
|
||||
'.html'
|
||||
];
|
||||
|
||||
const check = async (dir: string) => {
|
||||
if (ignoreDir.some(v => dir.includes(v))) return;
|
||||
const d = await fs.readdir(dir);
|
||||
for await (const one of d) {
|
||||
if (ignoreFile.some(v => one.includes(v))) continue;
|
||||
const stat = await fs.stat(resolve(dir, one));
|
||||
if (stat.isFile()) {
|
||||
if (
|
||||
['.ts', '.tsx', '.js', '.jsx', '.vue', '.less'].some(v =>
|
||||
one.endsWith(v)
|
||||
) &&
|
||||
!one.endsWith('.d.ts')
|
||||
) {
|
||||
if (exts.some(v => one.endsWith(v))) {
|
||||
const file = await fs.readFile(resolve(dir, one), 'utf-8');
|
||||
const lines = file.split('\n').length;
|
||||
const ext = extname(one);
|
||||
@ -34,7 +49,10 @@ import { extname, resolve } from 'path';
|
||||
};
|
||||
await check(dir);
|
||||
|
||||
for (const [ext, [file, lines]] of Object.entries(list)) {
|
||||
const sorted = Object.entries(list).sort((a, b) => {
|
||||
return a[1][1] - b[1][1];
|
||||
});
|
||||
for (const [ext, [file, lines]] of sorted) {
|
||||
console.log(
|
||||
`${ext.slice(1).padEnd(7, ' ')}files: ${file
|
||||
.toString()
|
||||
|
Loading…
Reference in New Issue
Block a user