Skip to content

Commit

Permalink
refactor: simplify vite prettier plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
azat-io committed Jan 7, 2025
1 parent 8fb41c6 commit 80b1f6d
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,20 @@ import fs from 'node:fs/promises'
import path from 'node:path'

let getAllFiles = async (directory: string): Promise<string[]> => {
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 childPathsPromises = 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 nestedPaths = await Promise.all(childPathsPromises)
return nestedPaths.flat()
}

let prettierPlugin = (): Plugin => {
Expand Down

0 comments on commit 80b1f6d

Please sign in to comment.