diff --git a/script/lines.ts b/script/lines.ts index 77a2097..17ea672 100644 --- a/script/lines.ts +++ b/script/lines.ts @@ -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 = {}; + 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()