ctrlshiftleft
Version:
AI-powered toolkit for embedding QA and security testing into development workflows
75 lines • 2.23 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.isValidSourcePath = isValidSourcePath;
exports.isValidTestPath = isValidTestPath;
exports.ensureDirectoryExists = ensureDirectoryExists;
exports.getRelativePath = getRelativePath;
exports.getBaseName = getBaseName;
const promises_1 = __importDefault(require("fs/promises"));
const path_1 = __importDefault(require("path"));
/**
* Check if a source path is valid
* @param sourcePath Path to check
* @returns True if path exists and is readable
*/
async function isValidSourcePath(sourcePath) {
try {
const stats = await promises_1.default.stat(sourcePath);
return stats.isFile() || stats.isDirectory();
}
catch (error) {
return false;
}
}
/**
* Check if a test path is valid
* @param testPath Path to check
* @returns True if path exists and is readable
*/
async function isValidTestPath(testPath) {
try {
const stats = await promises_1.default.stat(testPath);
return stats.isFile() || stats.isDirectory();
}
catch (error) {
return false;
}
}
/**
* Ensure a directory exists, creating it if necessary
* @param dirPath Directory path to ensure
*/
async function ensureDirectoryExists(dirPath) {
try {
await promises_1.default.mkdir(dirPath, { recursive: true });
}
catch (error) {
// Ignore if directory already exists
if (error.code !== 'EEXIST') {
throw error;
}
}
}
/**
* Get relative path between two absolute paths
* @param from Source path
* @param to Target path
* @returns Relative path
*/
function getRelativePath(from, to) {
return path_1.default.relative(from, to);
}
/**
* Get base name of a file without extension
* @param filePath File path
* @returns Base name without extension
*/
function getBaseName(filePath) {
const basename = path_1.default.basename(filePath);
const extname = path_1.default.extname(filePath);
return basename.substring(0, basename.length - extname.length);
}
//# sourceMappingURL=fileUtils.js.map