rest-chronicle
Version:
autodocumentate rest api
45 lines (44 loc) • 1.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _fsExtra = _interopRequireDefault(require("fs-extra"));
var _handlebars = _interopRequireDefault(require("../handlebars"));
var _Base = _interopRequireDefault(require("./Base"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class TemplateReporter extends _Base.default {
constructor(file, {
path,
templateOpts = {}
} = {}) {
super(file);
this.templatePath = path;
this.templateOpts = templateOpts;
}
_generate(groups, map) {
return this._template({
groups,
actions: map,
options: this.templateOpts
});
}
async _init() {
const templateContent = await _fsExtra.default.readFile(this.templatePath);
this._template = _handlebars.default.compile(templateContent.toString(), {
preventIndent: true
});
}
async write(actions) {
await this._init();
const {
groups,
map
} = this._build(actions, {
groupBy: ['context.group', 'context.title']
});
const content = this._generate(groups, map, actions);
await _fsExtra.default.writeFile(this.file, content);
}
}
exports.default = TemplateReporter;