From fbc02c2efd253271af68107d1bf4b2bc2802bfe5 Mon Sep 17 00:00:00 2001 From: ch1ny Date: Thu, 26 Oct 2023 20:12:01 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=B8=BB=E8=BF=9B?= =?UTF-8?q?=E7=A8=8B=E7=BC=96=E8=AF=91=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/creta/src/cli/utils/build.ts | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/creta/src/cli/utils/build.ts b/src/creta/src/cli/utils/build.ts index 2d0084f..a8b7c07 100644 --- a/src/creta/src/cli/utils/build.ts +++ b/src/creta/src/cli/utils/build.ts @@ -28,10 +28,24 @@ export const buildPreload = async () => path.resolve(scriptsCwd, 'src', 'preload', 'tsconfig.json') ); -export const buildMain = async () => - tscBuild( - (await fs.promises.readdir(path.resolve(scriptsCwd, 'src', 'main'))) - .filter((file) => file.endsWith('.js') || file.endsWith('.ts')) - .map((file) => path.resolve(scriptsCwd, 'src', 'main', file)), - path.resolve(scriptsCwd, 'src', 'main', 'tsconfig.json') - ); +export const buildMain = async () => { + const mainRootDir = path.resolve(scriptsCwd, 'src', 'main'); + const nextDirList = [mainRootDir]; + const filesToBuild: string[] = []; + + let nextDir: string | undefined; + while ((nextDir = nextDirList.shift())) { + const files = await fs.promises.readdir(path.resolve(nextDir)); + files.map(async (fileName) => { + const filePath = path.resolve(nextDir!, fileName); + const fsStatus = await fs.promises.stat(filePath); + if (fsStatus.isDirectory()) { + nextDirList.push(filePath); + } else if (filePath.endsWith('.js') || filePath.endsWith('.ts')) { + filesToBuild.push(filePath); + } + }); + } + + await tscBuild(filesToBuild, path.resolve(scriptsCwd, 'src', 'main', 'tsconfig.json')); +};