UNPKG

@atomist/automation-client

Version:
44 lines 1.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const AbstractScriptedFlushable_1 = require("../../internal/common/AbstractScriptedFlushable"); /** * Convenient support for all File implementations */ class AbstractFile extends AbstractScriptedFlushable_1.AbstractScriptedFlushable { get name() { return this.path.split("/").pop(); } get extension() { return this.name.includes(".") ? this.name.split(".").pop() : ""; } recordSetContent(newContent) { return this.recordAction(f => f.setContent(newContent)); } rename(name) { return this.setPath(this.path.replace(new RegExp(`${this.name}$`), name)); } recordRename(name) { return this.recordSetPath(this.path.replace(new RegExp(`${this.name}$`), name)); } recordSetPath(path) { return this.recordAction(f => f.setPath(path)); } replace(re, replacement) { return this.getContent() .then(content => this.setContent(content.replace(re, replacement))); } replaceAll(oldLiteral, newLiteral) { return this.getContent() .then(content => this.setContent(content.split(oldLiteral).join(newLiteral))); } recordReplace(re, replacement) { return this.recordAction(f => f.replace(re, replacement)); } recordReplaceAll(oldLiteral, newLiteral) { return this.recordAction(f => f.replaceAll(oldLiteral, newLiteral)); } } exports.AbstractFile = AbstractFile; //# sourceMappingURL=AbstractFile.js.map