tdpw
Version:
CLI tool for uploading Playwright test reports to TestDino platform with TestDino storage support
97 lines • 2.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolvePath = resolvePath;
exports.exists = exists;
exports.isDirectory = isDirectory;
exports.isFile = isFile;
exports.readDir = readDir;
exports.readFile = readFile;
exports.readFileBuffer = readFileBuffer;
const fs_1 = require("fs");
const path_1 = require("path");
const types_1 = require("../types");
const validation_1 = require("./validation");
/**
* Validate and resolve a file or directory path.
*/
function resolvePath(p, context) {
validation_1.ValidationUtils.validateFilePath(p, context);
return (0, path_1.resolve)(p);
}
/**
* Check if a path exists.
*/
async function exists(p) {
try {
await fs_1.promises.stat(p);
return true;
}
catch {
return false;
}
}
/**
* Check if the given path is a directory.
* Returns false if the path doesn't exist or is not accessible.
*/
async function isDirectory(p) {
try {
const stats = await fs_1.promises.stat(p);
return stats.isDirectory();
}
catch (_error) {
// Return false if path doesn't exist or is not accessible
// This allows graceful handling in discovery logic
return false;
}
}
/**
* Check if the given path is a file.
* Returns false if the path doesn't exist or is not accessible.
*/
async function isFile(p) {
try {
const stats = await fs_1.promises.stat(p);
return stats.isFile();
}
catch (_error) {
// Return false if path doesn't exist or is not accessible
// This allows graceful handling in discovery logic
return false;
}
}
/**
* Read directory contents and return full paths.
*/
async function readDir(p) {
try {
const entries = await fs_1.promises.readdir(p);
return entries.map(name => (0, path_1.join)(p, name));
}
catch (error) {
throw new types_1.FileSystemError(`Failed to read directory: ${p}`, error);
}
}
/**
* Read file as text.
*/
async function readFile(p) {
try {
return await fs_1.promises.readFile(p, 'utf-8');
}
catch (error) {
throw new types_1.FileSystemError(`Failed to read file: ${p}`, error);
}
}
/**
* Read file as Buffer.
*/
async function readFileBuffer(p) {
try {
return await fs_1.promises.readFile(p);
}
catch (error) {
throw new types_1.FileSystemError(`Failed to read file buffer: ${p}`, error);
}
}
//# sourceMappingURL=fs.js.map