UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

39 lines (38 loc) • 1.11 kB
import path from "node:path"; import fs from "node:fs/promises"; import os from "node:os"; //#region src/infra/host-directory-listing.ts /** Lists one absolute host directory, defaulting to that host's home directory. */ async function listHostDirectories(e) { const t = os.homedir(); const n = e || t; if (!path.isAbsolute(n)) throw new Error("fs.listDir path must be absolute"); const r = path.resolve(n); const i = await fs.readdir(r, { withFileTypes: true }); const a = []; for (const e of i) { const t = path.join(r, e.name); let n = e.isDirectory(); if (e.isSymbolicLink()) n = await fs.stat(t).then((e) => e.isDirectory(), () => false); if (!n) continue; const i = e.name.startsWith("."); a.push({ name: e.name, path: t, ...i ? { hidden: true } : {} }); } a.sort((e, t) => { if (Boolean(e.hidden) !== Boolean(t.hidden)) return e.hidden ? 1 : -1; return e.name < t.name ? -1 : e.name > t.name ? 1 : 0; }); const o = path.dirname(r); return { path: r, ...o !== r ? { parent: o } : {}, home: t, entries: a }; } //#endregion export { listHostDirectories as t };