From e9821ef1e5a833c3821a38515e42d9a59da0601d Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Sat, 27 May 2023 22:29:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E8=A1=8C=E6=95=B0=E6=98=BE?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 ++- script/lines.ts | 26 ++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) 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` + ); })();