diff --git a/package.json b/package.json index 4f0afb7..a32345d 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "preview": "vite preview", "update": "ts-node-esm script/update.ts", "declare": "ts-node-esm script/declare.ts", - "type": "vue-tsc --noEmit" + "type": "vue-tsc --noEmit", + "lines": "ts-node-esm script/lines.ts" }, "dependencies": { "@ant-design/icons-vue": "^6.1.0", diff --git a/script/lines.ts b/script/lines.ts index 2f4443a..77a2097 100644 --- a/script/lines.ts +++ b/script/lines.ts @@ -1,9 +1,11 @@ import fs from 'fs-extra'; -import { resolve } from 'path'; +import { extname, resolve } from 'path'; (async function () { const dir = './src'; - let total = 0; + let totalLines = 0; + let totalFiles = 0; + const list: Record = {}; const check = async (dir: string) => { 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 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 { await check(resolve(dir, one)); @@ -27,5 +34,16 @@ import { resolve } from 'path'; }; 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` + ); })();