Extract walkDir
parent
46282ac834
commit
ccd64a4367
18
lib/suite.js
18
lib/suite.js
|
@ -1,21 +1,5 @@
|
|||
import { readdir } from 'node:fs/promises'
|
||||
import { walkDir } from './walkDir.js'
|
||||
import { join } from 'node:path'
|
||||
const walkDir = async function* (dir = '.', exclude = []) {
|
||||
const files = await readdir(dir, { withFileTypes: true })
|
||||
|
||||
for (const file of files) {
|
||||
if (exclude.includes(file.name)) continue
|
||||
|
||||
if (file.isDirectory()) {
|
||||
yield* walkDir(join(dir, file.name))
|
||||
} else if (file.isSymbolicLink()) {
|
||||
yield* walkDir(join(dir, file.name))
|
||||
} else {
|
||||
yield join(dir, file.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { dirname } from 'node:path'
|
||||
const getStackAbsolutePaths = () => {
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
import { readdir, stat } from 'fs/promises'
|
||||
import { join } from 'path/posix'
|
||||
|
||||
const walkDir = async function* (dir = '.', exclude = []) {
|
||||
const files = await readdir(dir)
|
||||
|
||||
for await (const file of files) {
|
||||
if (exclude.includes(file)) continue
|
||||
|
||||
try {
|
||||
const stats = await stat(join(dir, file))
|
||||
|
||||
if (stats.isDirectory()) {
|
||||
yield* walkDir(join(dir, file))
|
||||
} else {
|
||||
yield join(dir, file)
|
||||
}
|
||||
}
|
||||
catch (err) { } //Like file not found when symlink to a file that do not exist
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export { walkDir }
|
Loading…
Reference in New Issue