改进行数显示

This commit is contained in:
unanmed 2023-05-27 22:29:02 +08:00
parent c179f05602
commit e9821ef1e5
2 changed files with 24 additions and 5 deletions

View File

@ -11,7 +11,8 @@
"preview": "vite preview", "preview": "vite preview",
"update": "ts-node-esm script/update.ts", "update": "ts-node-esm script/update.ts",
"declare": "ts-node-esm script/declare.ts", "declare": "ts-node-esm script/declare.ts",
"type": "vue-tsc --noEmit" "type": "vue-tsc --noEmit",
"lines": "ts-node-esm script/lines.ts"
}, },
"dependencies": { "dependencies": {
"@ant-design/icons-vue": "^6.1.0", "@ant-design/icons-vue": "^6.1.0",

View File

@ -1,9 +1,11 @@
import fs from 'fs-extra'; import fs from 'fs-extra';
import { resolve } from 'path'; import { extname, resolve } from 'path';
(async function () { (async function () {
const dir = './src'; const dir = './src';
let total = 0; let totalLines = 0;
let totalFiles = 0;
const list: Record<string, [number, number]> = {};
const check = async (dir: string) => { const check = async (dir: string) => {
const d = await fs.readdir(dir); const d = await fs.readdir(dir);
@ -18,7 +20,12 @@ import { resolve } from 'path';
) { ) {
const file = await fs.readFile(resolve(dir, one), 'utf-8'); const file = await fs.readFile(resolve(dir, one), 'utf-8');
const lines = file.split('\n').length; const lines = file.split('\n').length;
total += lines; const ext = extname(one);
list[ext] ??= [0, 0];
list[ext][0]++;
list[ext][1] += lines;
totalLines += lines;
totalFiles++;
} }
} else { } else {
await check(resolve(dir, one)); await check(resolve(dir, one));
@ -27,5 +34,16 @@ import { resolve } from 'path';
}; };
await check(dir); await check(dir);
console.log(total); for (const [ext, [file, lines]] of Object.entries(list)) {
console.log(
`${ext.slice(1).padEnd(7, ' ')}files: ${file
.toString()
.padEnd(6, ' ')}lines: ${lines}`
);
}
console.log(
`\x1b[33mtotal files: ${totalFiles
.toString()
.padEnd(6, ' ')}lines: ${totalLines}\x1b[0m`
);
})(); })();