From 8c635f09b2af30001735fe4fee4eb1fd0ac1a3d1 Mon Sep 17 00:00:00 2001 From: zkz098 Date: Sat, 21 Sep 2024 13:01:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BC=A0=E7=BB=9F?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E5=8F=AF=E7=BB=B4=E6=8A=A4=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- toolbox/compiler.mjs | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/toolbox/compiler.mjs b/toolbox/compiler.mjs index 0086093..0a67296 100644 --- a/toolbox/compiler.mjs +++ b/toolbox/compiler.mjs @@ -12,30 +12,12 @@ const CONFIG = { legacyScript: false, } -async function deleteFileRecursive(dir) { - const files = await fs.readdir(dir) - for (const f of files) { - const fullPath = path.join(dir, f) - const stat = await fs.lstat(fullPath) - if (stat.isDirectory()) { - await deleteFileRecursive(fullPath) - } else { - const fileExt = path.extname(f) - if (fileExt === '.ts' || fileExt === '.json' || fileExt === '.tsbuildinfo') { - await fs.unlink(fullPath) - } - } - } -} console.log('ShokaX ToolBox - Compiler') console.log('Start compiling...') -let hexoRoot = path.join(import.meta.url, './../../../../').trim() -if (hexoRoot.startsWith('file:/')) { - hexoRoot = hexoRoot.slice(5); // 去除 'file://' -} else if (hexoRoot.startsWith('file:\\')) { - hexoRoot = hexoRoot.slice(8); // 去除 'file:\' -} +const entryPoints = await glob('./scripts/**/*.ts'); +const jsons = await glob('./scripts/**/*.json'); + if (CONFIG.legacyScript) { console.log('Simulating legacy script compiler...') let sPath = path.join(import.meta.url, './../../scripts/').trim() @@ -51,14 +33,18 @@ if (CONFIG.legacyScript) { cwd: sPath }, async (code, stdout, stderr) => { console.log('Deleting typescript files...') - await deleteFileRecursive(sPath) + for (const entry of entryPoints) { + await fs.unlink(entry) + } + for (const entry of jsons) { + await fs.unlink(entry) + } console.log('Finished compiling.') }) }) } else { console.log('RUN THIS SCRIPT IN YOUR SHOKAX THEME ROOT DIRECTORY!') console.log('Using esbuild compiler...') - const entryPoints = glob.sync('./scripts/**/*.ts'); buildSync({ entryPoints: entryPoints, outdir: 'scripts', @@ -68,7 +54,12 @@ if (CONFIG.legacyScript) { platform: 'node', loader: { '.ts': 'ts' }, }) - await deleteFileRecursive('./scripts/') + entryPoints.forEach(async (entry) => { + await fs.unlink(entry) + }) + jsons.forEach(async (entry)=>{ + await fs.unlink(entry) + }) console.log('Finished compiling.') }