UNPKG

shaman-website-compiler

Version:

Compile raw HTML, CSS and Javascript into the smallest possible, SEO friendly website.

51 lines 2.71 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.BundleService = void 0; var inversify_1 = require("inversify"); var app_composition_1 = require("../composition/app.composition"); var BundleService = /** @class */ (function () { function BundleService() { var _this = this; this.updateBundleContent = function () { _this.context.models.bundles.filter(function (b) { return !b.content; }) .map(function (bundle) { return _this.getBundleContent(bundle); }) .forEach(function (bundle) { return _this.saveBundleContent(bundle); }); return _this.context.saveChanges(); }; this.getBundleContent = function (bundle) { var files = _this.context.models.files .filter(function (file) { return bundle.files.includes(file.name); }); bundle.content = _this.setBundleOrder(bundle, files) .reduce(function (a, b) { return "".concat(a).concat(b.content); }, ''); return bundle; }; this.setBundleOrder = function (bundle, files) { var map = files.reduce(function (a, b) { a[b.name] = b; return a; }, {}); return bundle.files.map(function (f) { return map[f]; }); }; this.saveBundleContent = function (bundle) { _this.context.models.bundles.update(bundle.name, function (b) { b.content = bundle.content; return b; }); }; this.config = app_composition_1.IoC.get(app_composition_1.TYPES.WebsiteConfig); this.context = app_composition_1.IoC.get(app_composition_1.TYPES.CompilerDataContext); } BundleService = __decorate([ (0, inversify_1.injectable)(), __metadata("design:paramtypes", []) ], BundleService); return BundleService; }()); exports.BundleService = BundleService; //# sourceMappingURL=bundle.service.js.map