@qbyco/tjs-cli
Version:
TrafaletJS CLI Tool
59 lines (47 loc) • 1.02 kB
JavaScript
const fs = require('fs');
const path = require('path');
/**
* @module lib/stub/Stub
*/
class Stub {
/**
* @constructor
* @param {String} stubName
*/
constructor (stubName) {
this.stubName = stubName;
this.stubContent = "";
this.build();
}
getStubName () {
return this.stubName + ".stub";
}
getStubPath () {
return path.join(__dirname, "../../resources/stubs", this.getStubName());
}
/**
* @method setStubContent
* @param {String} content
*/
setStubContent (content) {
this.stubContent = content;
}
/**
* @method getStubContent
* @returns {String|*}
*/
getStubContent () {
return this.stubContent;
}
parse (key, value) {
let tmpStub = this.getStubContent(),
regex;
regex = new RegExp('{' + key + '}', 'gm');
tmpStub = tmpStub.replace(regex, value);
this.setStubContent(tmpStub);
}
build () {
this.setStubContent(fs.readFileSync(this.getStubPath()).toString());
}
}
module.exports = Stub;