shaman-website-compiler
Version:
Compile raw HTML, CSS and Javascript into the smallest possible, SEO friendly website.
68 lines • 3.06 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.AddModelHandler = void 0;
var _fsx = require("fs-extra");
var event_handler_1 = require("./event-handler");
var file_functions_1 = require("../functions/file.functions");
var logger_1 = require("../logger");
var AddModelHandler = /** @class */ (function (_super) {
__extends(AddModelHandler, _super);
function AddModelHandler() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.event = 'file-contents-added';
_this.processEvent = function (file) {
if (file.extension != "html")
return Promise.resolve();
return _this.updateFileModel(file).then(function (_) {
_this.logger.log("Model has been updated for file '".concat(file.name, "'."));
_this.eventService.publish('file-model-added', file);
});
};
_this.updateFileModel = function (file) {
return _this.getJsonData(file).then(function (rslt) {
file.model = rslt;
if (!file.model.shaman)
file.model.shaman = {};
if (!file.model.shaman.bundles)
file.model.shaman.bundles = [];
if (!file.model.shaman.query)
file.model.shaman.query = [];
_this.context.models.files.update(file.name, (function (file) {
file.model = rslt;
return file;
}));
return _this.context.saveChanges();
});
};
_this.getJsonData = function (file) {
return new Promise(function (res) {
var path = (0, file_functions_1.GetJsonExtensionFromHtml)(file.path);
return _fsx.readJSON(path)
.then(res)
.catch(function (_) {
_this.logger.log("WARNING: file '".concat(file.name, "' does not have a model."), logger_1.LogLevels.warn);
res({});
});
});
};
return _this;
}
return AddModelHandler;
}(event_handler_1.EventHandler));
exports.AddModelHandler = AddModelHandler;
//# sourceMappingURL=add-model.handler.js.map