From c37663f0ae29a1168580396734a2d5bd94c20cfe Mon Sep 17 00:00:00 2001 From: "Azat S." Date: Wed, 8 Jan 2025 01:09:02 +0300 Subject: [PATCH] refactor: simplify vite prettier plugin --- vite.config.ts | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/vite.config.ts b/vite.config.ts index 9d93819eb..72e7d385b 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -7,22 +7,20 @@ import fs from 'node:fs/promises' import path from 'node:path' let getAllFiles = async (directory: string): Promise => { - let files = await fs.readdir(directory) - files = (await Promise.all( - files.map(async file => { - let filePath = path.join(directory, file) - let stats = await fs.stat(filePath) - if (stats.isDirectory()) { - return getAllFiles(filePath) - } else if (stats.isFile()) { - return filePath - } - return null - }), - )) as string[] - return files - .reduce((all: string[], folderContents) => [...all, folderContents], []) - .flat() + let entries = await fs.readdir(directory, { withFileTypes: true }) + + let subPromises = entries.map(async entry => { + let filePath = path.join(directory, entry.name) + if (entry.isDirectory()) { + return getAllFiles(filePath) + } else if (entry.isFile()) { + return [filePath] + } + return [] + }) + + let arrayOfArrays = await Promise.all(subPromises) + return arrayOfArrays.flat() } let prettierPlugin = (): Plugin => {