hataraku
Version:
An autonomous coding agent for building AI-powered development tools. The name "Hataraku" (働く) means "to work" in Japanese.
83 lines • 3.25 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createDirectoriesForFile = createDirectoriesForFile;
exports.fileExistsAtPath = fileExistsAtPath;
const promises_1 = __importDefault(require("fs/promises"));
const path = __importStar(require("path"));
/**
* Asynchronously creates all non-existing subdirectories for a given file path
* and collects them in an array for later deletion.
*
* @param filePath - The full path to a file.
* @returns A promise that resolves to an array of newly created directories.
*/
async function createDirectoriesForFile(filePath) {
const newDirectories = [];
const normalizedFilePath = path.normalize(filePath); // Normalize path for cross-platform compatibility
const directoryPath = path.dirname(normalizedFilePath);
let currentPath = directoryPath;
const dirsToCreate = [];
// Traverse up the directory tree and collect missing directories
while (!(await fileExistsAtPath(currentPath))) {
dirsToCreate.push(currentPath);
currentPath = path.dirname(currentPath);
}
// Create directories from the topmost missing one down to the target directory
for (let i = dirsToCreate.length - 1; i >= 0; i--) {
await promises_1.default.mkdir(dirsToCreate[i]);
newDirectories.push(dirsToCreate[i]);
}
return newDirectories;
}
/**
* Helper function to check if a path exists.
*
* @param path - The path to check.
* @returns A promise that resolves to true if the path exists, false otherwise.
*/
async function fileExistsAtPath(filePath) {
try {
await promises_1.default.access(filePath);
return true;
}
catch {
return false;
}
}
//# sourceMappingURL=fs.js.map