mirror of
https://github.com/ragestudio/relic.git
synced 2025-06-09 10:34:18 +00:00
cleanup rfs
This commit is contained in:
parent
b68c49118a
commit
98401fbf8d
@ -1,29 +1,9 @@
|
|||||||
import path from "node:path"
|
import path from "node:path"
|
||||||
import fs from "node:fs"
|
import fs from "node:fs"
|
||||||
import { execa } from "../../lib/execa"
|
import { execa } from "../../lib/execa"
|
||||||
|
|
||||||
import Vars from "../../vars"
|
import Vars from "../../vars"
|
||||||
|
|
||||||
async function readDirRecurse(dir, maxDepth=3, current = 0) {
|
|
||||||
if (current > maxDepth) {
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
|
|
||||||
const files = await fs.promises.readdir(dir)
|
|
||||||
|
|
||||||
const promises = files.map(async (file) => {
|
|
||||||
const filePath = path.join(dir, file)
|
|
||||||
const stat = await fs.promises.stat(filePath)
|
|
||||||
|
|
||||||
if (stat.isDirectory()) {
|
|
||||||
return readDirRecurse(filePath, maxDepth, current + 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
return filePath
|
|
||||||
})
|
|
||||||
|
|
||||||
return (await Promise.all(promises)).flat()
|
|
||||||
}
|
|
||||||
|
|
||||||
export default class RFS {
|
export default class RFS {
|
||||||
constructor(manifest) {
|
constructor(manifest) {
|
||||||
this.manifest = manifest
|
this.manifest = manifest
|
||||||
@ -58,15 +38,6 @@ export default class RFS {
|
|||||||
stderr: "inherit",
|
stderr: "inherit",
|
||||||
})
|
})
|
||||||
|
|
||||||
await new Promise((r) => {
|
|
||||||
setTimeout(r, 1000)
|
|
||||||
})
|
|
||||||
|
|
||||||
// // try to read from the mount point
|
|
||||||
// let dirs = await readDirRecurse(mountPoint)
|
|
||||||
|
|
||||||
// console.log(dirs)
|
|
||||||
|
|
||||||
if (typeof cb === "function") {
|
if (typeof cb === "function") {
|
||||||
cb(process)
|
cb(process)
|
||||||
}
|
}
|
||||||
|
25
src/main/utils/readDirRecurse.js
Normal file
25
src/main/utils/readDirRecurse.js
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import fs from "node:fs"
|
||||||
|
import path from "node:path"
|
||||||
|
|
||||||
|
async function readDirRecurse(dir, maxDepth = 3, current = 0) {
|
||||||
|
if (current > maxDepth) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
const files = await fs.promises.readdir(dir)
|
||||||
|
|
||||||
|
const promises = files.map(async (file) => {
|
||||||
|
const filePath = path.join(dir, file)
|
||||||
|
const stat = await fs.promises.stat(filePath)
|
||||||
|
|
||||||
|
if (stat.isDirectory()) {
|
||||||
|
return readDirRecurse(filePath, maxDepth, current + 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
return filePath
|
||||||
|
})
|
||||||
|
|
||||||
|
return (await Promise.all(promises)).flat()
|
||||||
|
}
|
||||||
|
|
||||||
|
export default readDirRecurse
|
Loading…
x
Reference in New Issue
Block a user