/** * Mock SmartFs implementation for testing until @push.rocks/smartfs is available * This wraps fs-extra to provide the SmartFs interface */ import { ensureDir, pathExists, remove, copy } from 'fs-extra'; import { promises as fsPromises, createReadStream, createWriteStream } from 'fs'; import * as path from 'path'; import { Readable, Writable } from 'stream'; export class MockSmartFs { public file(filePath: string) { return { async read(): Promise { return await fsPromises.readFile(filePath); }, async write(content: string | Buffer): Promise { await ensureDir(path.dirname(filePath)); await fsPromises.writeFile(filePath, content); }, async exists(): Promise { return await pathExists(filePath); }, async delete(): Promise { await remove(filePath); }, async stat(): Promise { return await fsPromises.stat(filePath); }, async readStream(): Promise { return Promise.resolve(createReadStream(filePath)); }, async writeStream(): Promise { await ensureDir(path.dirname(filePath)); return Promise.resolve(createWriteStream(filePath)); }, async copy(dest: string): Promise { await copy(filePath, dest); }, }; } public directory(dirPath: string) { return { async list(options?: { recursive?: boolean }): Promise> { const entries: Array<{ path: string; isFile: boolean; isDirectory: boolean }> = []; if (options?.recursive) { // Recursive listing const walk = async (dir: string) => { const items = await fsPromises.readdir(dir); for (const item of items) { const fullPath = path.join(dir, item); const stats = await fsPromises.stat(fullPath); if (stats.isFile()) { entries.push({ path: fullPath, isFile: true, isDirectory: false }); } else if (stats.isDirectory()) { entries.push({ path: fullPath, isFile: false, isDirectory: true }); await walk(fullPath); } } }; await walk(dirPath); } else { // Non-recursive listing const items = await fsPromises.readdir(dirPath); for (const item of items) { const fullPath = path.join(dirPath, item); const stats = await fsPromises.stat(fullPath); entries.push({ path: fullPath, isFile: stats.isFile(), isDirectory: stats.isDirectory(), }); } } return entries; }, async create(options?: { recursive?: boolean }): Promise { if (options?.recursive) { await ensureDir(dirPath); } else { await fsPromises.mkdir(dirPath); } }, async exists(): Promise { return await pathExists(dirPath); }, async delete(): Promise { await remove(dirPath); }, }; } }