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')); +};