@atomist/automation-client
Version:
Atomist API for software low-level client
38 lines • 1.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const _ = require("lodash");
const AbstractScriptedFlushable_1 = require("../../internal/common/AbstractScriptedFlushable");
/**
* Convenient support for all File implementations
*/
class AbstractFile extends AbstractScriptedFlushable_1.AbstractScriptedFlushable {
constructor() {
super(...arguments);
this.cache = {};
}
get name() {
return this.path.split("/").pop();
}
get extension() {
return this.name.includes(".") ?
this.name.split(".").pop() :
"";
}
rename(name) {
return this.setPath(this.path.replace(new RegExp(`${this.name}$`), name));
}
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)));
}
invalidateCache() {
_.keys(this.cache).forEach(k => delete this.cache[k]);
return this;
}
}
exports.AbstractFile = AbstractFile;
//# sourceMappingURL=AbstractFile.js.map