UNPKG

kist

Version:

Lightweight Package Pipeline Processor with Plugin Architecture

41 lines 1.66 kB
import { __awaiter } from "tslib"; import { promises as fsPromises } from "fs"; import path from "path"; import { Action } from "../../core/pipeline/Action.js"; export class FileRenameAction extends Action { execute(options) { return __awaiter(this, void 0, void 0, function* () { const { srcPath, targetPath } = options; if (!srcPath || !targetPath) { throw new Error("Invalid options: 'srcPath' and 'targetPath' are required."); } this.logInfo(`Renaming file: ${srcPath}${targetPath}`); try { yield this.renameFile(srcPath, targetPath); this.logInfo(`File successfully renamed to ${targetPath}`); } catch (error) { this.logError("Failed to rename file.", error); throw error; } }); } renameFile(srcPath, targetPath) { return __awaiter(this, void 0, void 0, function* () { try { const resolvedSrcPath = path.resolve(srcPath); const resolvedTargetPath = path.resolve(targetPath); yield fsPromises.rename(resolvedSrcPath, resolvedTargetPath); this.logDebug(`File renamed: ${resolvedSrcPath}${resolvedTargetPath}`); } catch (error) { this.logError(`Error renaming file: ${srcPath}${targetPath}`, error); throw error; } }); } describe() { return "Renames a file from a specified source path to a target path."; } } //# sourceMappingURL=FileRenameAction.js.map