shaman-website-compiler
Version:
Compile raw HTML, CSS and Javascript into the smallest possible, SEO friendly website.
66 lines • 3.21 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.ProcessModelHandler = void 0;
var app_composition_1 = require("../composition/app.composition");
var event_handler_1 = require("./event-handler");
var models_1 = require("../models");
var ProcessModelHandler = /** @class */ (function (_super) {
__extends(ProcessModelHandler, _super);
function ProcessModelHandler() {
var _this = _super.call(this) || this;
_this.event = 'file-model-added';
_this.processEvent = function (file) {
if (file.extension != "html")
return Promise.resolve();
return _this.addBundlesToDatabase(file)
.then(function (_) { return _this.updateQueryData(file); })
.then(function (_) {
_this.logger.log("Model has been processed for file '".concat(file.name, "'."));
_this.eventService.publish('file-model-processed', file);
});
};
_this.addBundlesToDatabase = function (file) {
file.model.shaman.bundles.forEach(function (b) {
var bundle = new models_1.Bundle(b);
if (_this.config.production)
bundle.extension = "min.".concat(b.type);
_this.context.models.bundles.upsert(b.name, bundle);
});
return _this.context.saveChanges();
};
_this.updateQueryData = function (file) {
var queries = file.model.shaman.query.filter(function (q) { return !q.dynamic; });
var operations = queries.map(function (q) {
return _this.queryAdapter.run(q).then(function (rslt) { return ({ name: q.name, rslt: rslt }); });
});
return Promise.all(operations).then(function (rslt) {
file.query = rslt.reduce(function (a, b) { a[b.name] = b.rslt; return a; }, {});
_this.context.models.files.update(file.name, function (f) {
f.query = file.query;
return f;
});
return _this.context.saveChanges();
});
};
_this.queryAdapter = app_composition_1.IoC.get(app_composition_1.TYPES.QueryAdapter);
return _this;
}
return ProcessModelHandler;
}(event_handler_1.EventHandler));
exports.ProcessModelHandler = ProcessModelHandler;
//# sourceMappingURL=process-model.handler.js.map