UNPKG

kist

Version:

Lightweight Package Pipeline Processor with Plugin Architecture

42 lines 1.74 kB
import { __awaiter } from "tslib"; import { promises as fsPromises } from "fs"; import path from "path"; import { Action } from "../../core/pipeline/Action.js"; export class DirectoryCreateAction extends Action { execute(options) { return __awaiter(this, void 0, void 0, function* () { const { basePath, directories } = options; if (!basePath || !directories || !Array.isArray(directories)) { throw new Error("Invalid options: 'basePath' (string) and 'directories' (array) are required."); } this.logInfo(`Ensuring directory structure under base path: ${basePath}`); try { yield this.createDirectories(basePath, directories); this.logInfo("All specified directories have been created successfully."); } catch (error) { this.logError("Failed to create directories.", error); throw error; } }); } createDirectories(basePath, directories) { return __awaiter(this, void 0, void 0, function* () { for (const dir of directories) { const dirPath = path.join(basePath, dir); try { yield fsPromises.mkdir(dirPath, { recursive: true }); this.logDebug(`Directory ensured: ${dirPath}`); } catch (error) { this.logError(`Error creating directory: ${dirPath}`, error); throw error; } } }); } describe() { return "Creates specified directory structures under a given base path."; } } //# sourceMappingURL=DirectoryCreateAction.js.map