UNPKG

gulp-armapbo

Version:

The plugin for Gulp which allows to pack ArmA pbo files from sources.

76 lines (74 loc) 2.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const chalk_1 = require("chalk"); const log = require("single-line-log"); const gulp_util_1 = require("gulp-util"); class LzhReporter { constructor(options) { this._options = options; this._normalizeOptions(); } reportOverall(uncompressedSize, compressedSize) { if (this._options.verbose) { const percentage = this._getStyledPercentage(uncompressedSize, compressedSize); const text = `Overall compression: ${percentage}`; this._writeMessage(text); } } reportFile(name, originalSize, compressedSize) { if (this._options.verbose) { const percentage = this._getStyledPercentage(originalSize, compressedSize); const text = `Compression: ${percentage} | ${name}`; this._writeMessage(text); } } reportProgress(name, originalSize, processedSize) { if (this._options.progress) { if (processedSize < originalSize) { const percentage = Math.round(processedSize / originalSize * 100); const formatted = percentage < 10 ? `0${percentage}` : percentage; log.stdout(`Progress: ${formatted}% | ${name}`); } else { log.stdout(''); } } } _normalizeOptions() { this._options.verbose = this._options.verbose !== false; this._options.progress = this._options.progress !== false; } _getStyledPercentage(originalSize, compressedSize) { const percentage = Math.round((1 - compressedSize / originalSize) * 100); const percentageChalk = this._getPercentageChalk(percentage); const formatted = percentage < 10 ? `0${percentage}` : percentage; const text = percentageChalk(`${formatted}%`); return text; } _getPercentageChalk(percentage) { let style; switch (true) { case (percentage > 30): style = chalk_1.default.green; break; case (percentage > 20): style = chalk_1.default.yellow; break; case (percentage > 10): style = chalk_1.default.cyan; break; default: { style = chalk_1.default.red; } } return style; } _writeMessage(message) { gulp_util_1.log(message); } get options() { return this._options; } } exports.LzhReporter = LzhReporter; //# sourceMappingURL=lzhReporter.js.map