shaman-website-compiler
Version:
Compile raw HTML, CSS and Javascript into the smallest possible, SEO friendly website.
58 lines • 2.64 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.CssContentHandler = void 0;
var CleanCss = require("clean-css");
var event_handler_1 = require("./event-handler");
var file_functions_1 = require("../functions/file.functions");
var CssContentHandler = /** @class */ (function (_super) {
__extends(CssContentHandler, _super);
function CssContentHandler() {
var _this = _super.call(this) || this;
_this.event = 'file-contents-added';
_this.processEvent = function (file) {
if (file.extension != "css")
return Promise.resolve();
return _this.minifyCss(file).then(function (_) {
_this.logger.log("Content has been updated for file '".concat(file.name, "'."));
return _this.alertFileAvailable(file);
});
};
_this.minifyCss = function (file) {
if (!_this.config.production)
return _this.updateFileContents(file, file.text);
return new Promise(function (res) {
var rslt = _this.minify.minify(file.text);
_this.updateFileContents(file, rslt.styles).then(res);
});
};
_this.updateFileContents = function (file, content) {
_this.context.models.files.update(file.name, function (file) {
file.content = content;
if (_this.config.production)
file.routePath = (0, file_functions_1.ChangeExtension)(file.name, 'css', 'min.css');
return file;
});
return _this.context.saveChanges();
};
_this.minify = new CleanCss({});
return _this;
}
return CssContentHandler;
}(event_handler_1.EventHandler));
exports.CssContentHandler = CssContentHandler;
//# sourceMappingURL=css-content.handler.js.map