UNPKG

shaman-website-compiler

Version:

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

90 lines 4.87 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.FileImportService = void 0; var fsx = require("fs-extra"); var inversify_1 = require("inversify"); var app_composition_1 = require("../composition/app.composition"); var file_functions_1 = require("../functions/file.functions"); var FileImportService = /** @class */ (function () { function FileImportService() { var _this = this; this.fsx = fsx; this.importPartialFilesFromGlobs = function () { return _this.globService.GetFilesFromGlob(_this.config.partials).then(function (files) { var operations = files.map(function (file) { return _this.importFileText(file); }); return Promise.all(operations) .then(function (files) { return files.map(function (file) { file.extension = 'partial.html'; file.available = true; return file; }); }) .then(_this.handlebarsService.registerPartials) .then(function (files) { return _this.addFilesToDatabase(files); }) .then(function (_) { return (files); }); }); }; this.importFilesFromGlobs = function () { var operations = [ _this.globService.GetFilesFromGlob(_this.config.pages), _this.globService.GetFilesFromGlob(_this.config.styles), _this.globService.GetFilesFromGlob(_this.config.scripts) ]; return Promise.all(operations) .then(file_functions_1.ReduceFileData) .then(function (files) { _this.addFilesToDatabase(files); return files; }) .then(function (files) { files.forEach(_this.alertFileAdded); return files; }); }; this.importAssetFilesFromGlobs = function () { return _this.globService.GetFilesFromGlob(_this.config.assets) .then(function (files) { _this.addAssetFilesToDatabase(files); return files; }); }; this.importHelperFilesFromGlobs = function () { return _this.globService.GetFilesFromGlob(_this.config.helpers); }; this.importFileText = function (file) { return _this.fsx.readFile(file.path, "utf8").then(function (text) { file.text = file.content = text; return file; }); }; this.addFilesToDatabase = function (files) { files.forEach(function (file) { _this.context.models.files.add(file.name, file); _this.logger.log("File '".concat(file.name, "' has been added to database.")); }); return _this.context.saveChanges(); }; this.addAssetFilesToDatabase = function (files) { files.forEach(function (file) { _this.context.models.assets.add(file.name, file); _this.logger.log("Asset file '".concat(file.name, "' has been added to database.")); }); return _this.context.saveChanges(); }; this.alertFileAdded = function (file) { setTimeout(function () { return _this.eventService.publish('file-added', file); }); }; this.config = app_composition_1.IoC.get(app_composition_1.TYPES.WebsiteConfig); this.logger = app_composition_1.IoC.get(app_composition_1.TYPES.Logger); this.context = app_composition_1.IoC.get(app_composition_1.TYPES.CompilerDataContext); this.globService = app_composition_1.IoC.get(app_composition_1.TYPES.GlobService); this.eventService = app_composition_1.IoC.get(app_composition_1.TYPES.CompilerEvents); this.handlebarsService = app_composition_1.IoC.get(app_composition_1.TYPES.HandlebarsService); } FileImportService = __decorate([ (0, inversify_1.injectable)(), __metadata("design:paramtypes", []) ], FileImportService); return FileImportService; }()); exports.FileImportService = FileImportService; //# sourceMappingURL=file-import.service.js.map