From c179f056025a325a040142bb4952079386b5771c Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Fri, 26 May 2023 21:39:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A3=80=E6=B5=8B=E8=A1=8C=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/build.ts | 21 ++++++++++----------- script/lines.ts | 31 +++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 11 deletions(-) create mode 100644 script/lines.ts diff --git a/script/build.ts b/script/build.ts index 8885573..c354a50 100644 --- a/script/build.ts +++ b/script/build.ts @@ -1,6 +1,5 @@ -import fs from 'fs/promises'; import fss from 'fs'; -import fse from 'fs-extra'; +import fs from 'fs-extra'; import Fontmin from 'fontmin'; import * as babel from '@babel/core'; import * as rollup from 'rollup'; @@ -45,11 +44,11 @@ import commonjs from '@rollup/plugin-commonjs'; }); }) ); - if (process.argv[2] !== '1') await fse.remove('./dist/maps/'); + if (process.argv[2] !== '1') await fs.remove('./dist/maps/'); // 在线查看什么都看不到,这编辑器难道还需要留着吗? - await fse.remove('./dist/_server'); - await fse.remove('./dist/editor.html'); - await fse.remove('./dist/server.cjs'); + await fs.remove('./dist/_server'); + await fs.remove('./dist/editor.html'); + await fs.remove('./dist/server.cjs'); } catch {} // 2. 压缩字体 @@ -106,19 +105,19 @@ import commonjs from '@rollup/plugin-commonjs'; ]); await Promise.all([ ...fonts.map(v => { - return fse.rename( + return fs.rename( `./dist/project/fonts/${v}.ttf`, `./dist/project/fonts/${v}-${timestamp}.ttf` ); }) ]); } catch (e) { - await fse.copy('./public/project/fonts', './dist/project/fonts'); + await fs.copy('./public/project/fonts', './dist/project/fonts'); } // 3. 压缩js插件 try { - await fse.remove('./dist/project/plugin.min.js'); + await fs.remove('./dist/project/plugin.min.js'); const build = await rollup.rollup({ input: 'src/plugin/game/index.js', @@ -141,7 +140,7 @@ import commonjs from '@rollup/plugin-commonjs'; file: './dist/project/plugin.min.js' }); - await fse.remove('./dist/project/plugin/'); + await fs.remove('./dist/project/plugin/'); } catch (e) { console.log(e); @@ -169,6 +168,6 @@ import commonjs from '@rollup/plugin-commonjs'; // 5. 杂项 try { - await fse.copy('./LICENSE', './dist/LICENSE'); + await fs.copy('./LICENSE', './dist/LICENSE'); } catch {} })(); diff --git a/script/lines.ts b/script/lines.ts new file mode 100644 index 0000000..2f4443a --- /dev/null +++ b/script/lines.ts @@ -0,0 +1,31 @@ +import fs from 'fs-extra'; +import { resolve } from 'path'; + +(async function () { + const dir = './src'; + let total = 0; + + const check = async (dir: string) => { + const d = await fs.readdir(dir); + for await (const one of d) { + 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') + ) { + const file = await fs.readFile(resolve(dir, one), 'utf-8'); + const lines = file.split('\n').length; + total += lines; + } + } else { + await check(resolve(dir, one)); + } + } + }; + await check(dir); + + console.log(total); +})();