aicm
Version:
A TypeScript CLI tool for managing AI IDE rules across different projects and teams
22 lines (21 loc) • 596 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.withWorkingDirectory = withWorkingDirectory;
/**
* Helper function to execute a function within a specific working directory
* and ensure the original directory is always restored
*/
async function withWorkingDirectory(targetDir, fn) {
const originalCwd = process.cwd();
if (targetDir !== originalCwd) {
process.chdir(targetDir);
}
try {
return await fn();
}
finally {
if (targetDir !== originalCwd) {
process.chdir(originalCwd);
}
}
}