UNPKG

kist

Version:

Lightweight Package Pipeline Processor with Plugin Architecture

37 lines 1.48 kB
import { promises as fsPromises } from "fs"; import path from "path"; import { Action } from "../../core/pipeline/Action.js"; export class DirectoryCreateAction extends Action { async execute(options) { 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 { await this.createDirectories(basePath, directories); this.logInfo("All specified directories have been created successfully."); } catch (error) { this.logError("Failed to create directories.", error); throw error; } } async createDirectories(basePath, directories) { for (const dir of directories) { const dirPath = path.join(basePath, dir); try { await 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