UNPKG

shaman-website-compiler

Version:

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

90 lines 4.93 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.WebsiteCompiler = void 0; var inversify_1 = require("inversify"); var app_composition_1 = require("./composition/app.composition"); var logger_1 = require("./logger"); var WebsiteCompiler = /** @class */ (function () { function WebsiteCompiler() { var _this = this; this.compile = function () { _this.logger.log('Starting compilation', logger_1.LogLevels.info); var start = new Date(); return _this.queryAdapter.openConnection() .then(_this.importHelperFilesFromGlobs) .then(_this.importAssetFilesFromGlobs) .then(_this.importFilesFromGlobs) .then(_this.waitForFileAvailability) .then(_this.bundleService.updateBundleContent) .then(_this.router.getAllRoutes) .then(function (routes) { var diff = Math.abs(start.getTime() - (new Date()).getTime()); _this.logger.log("Compilation finished (ms): ".concat(diff), logger_1.LogLevels.info); return routes; }); }; this.importHelperFilesFromGlobs = function () { if (_this.helperFiles) return Promise.resolve(); return _this.fileService.importHelperFilesFromGlobs() .then(function (rslt) { _this.helperFiles = rslt; return rslt; }) .then(_this.handlebarsService.registerHelpers); }; this.importAssetFilesFromGlobs = function () { if (_this.assetFiles) return Promise.resolve(); return _this.fileService.importAssetFilesFromGlobs() .then(function (rslt) { _this.assetFiles = rslt; }); }; this.importFilesFromGlobs = function () { if (_this.globFiles) return Promise.resolve(_this.globFiles); return _this.fileService.importPartialFilesFromGlobs() .then(function (_) { return _this.fileService.importFilesFromGlobs(); }) .then(function (files) { _this.globFiles = files; return files; }); }; this.waitForFileAvailability = function () { var allFilesAvailable = function () { var unavailableFiles = _this.context.models.files.filter(function (f) { return !f.available; }); return unavailableFiles.length == 0; }; var filesAvailableListener = new Promise(function (res) { if (allFilesAvailable()) res(); _this.eventService.subscribe('file-available', function () { if (allFilesAvailable()) res(); }); }); return filesAvailableListener.then(function (_) { _this.eventService.removeAllListeners('file-available'); }); }; this.context = app_composition_1.IoC.get(app_composition_1.TYPES.CompilerDataContext); this.logger = app_composition_1.IoC.get(app_composition_1.TYPES.Logger); this.router = app_composition_1.IoC.get(app_composition_1.TYPES.WebsiteRouter); this.eventService = app_composition_1.IoC.get(app_composition_1.TYPES.CompilerEvents); this.eventHandlers = app_composition_1.IoC.getAll(app_composition_1.TYPES.CompilerEventHandler); this.fileService = app_composition_1.IoC.get(app_composition_1.TYPES.FileImportService); this.bundleService = app_composition_1.IoC.get(app_composition_1.TYPES.BundleService); this.handlebarsService = app_composition_1.IoC.get(app_composition_1.TYPES.HandlebarsService); this.queryAdapter = app_composition_1.IoC.get(app_composition_1.TYPES.QueryAdapter); this.eventHandlers.forEach(function (handler) { return handler.listen(); }); } WebsiteCompiler = __decorate([ (0, inversify_1.injectable)(), __metadata("design:paramtypes", []) ], WebsiteCompiler); return WebsiteCompiler; }()); exports.WebsiteCompiler = WebsiteCompiler; //# sourceMappingURL=website-compiler.js.map