"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var libs_1 = require("./libs");
function formatPath(path, rootDir) {
    path = libs_1.fsPath.resolve(path);
    rootDir = rootDir === true ? libs_1.fsPath.resolve('.') : rootDir;
    var dir = libs_1.fsPath.dirname(path);
    dir = typeof rootDir === 'string' ? dir.substr(rootDir.length) : dir;
    var file = libs_1.fsPath.basename(path);
    return libs_1.log.gray(dir + "/" + libs_1.log.cyan(file));
}
exports.formatPath = formatPath;
function fileStatsTable(args) {
    return tslib_1.__awaiter(this, void 0, void 0, function () {
        var _a, showHeader, dir, toSize, getPaths, paths, sizes, head, table, totalBytes, total;
        return tslib_1.__generator(this, function (_b) {
            _a = args.showHeader, showHeader = _a === void 0 ? false : _a;
            dir = libs_1.fsPath.resolve(args.dir);
            toSize = function (bytes) { return libs_1.filesize(bytes, { round: 0, spacer: '' }); };
            getPaths = function (dir) {
                return libs_1.fs.pathExistsSync(dir)
                    ? libs_1.fs.readdirSync(dir).map(function (path) { return libs_1.fsPath.join(dir, path); })
                    : [];
            };
            paths = getPaths(dir);
            sizes = paths
                .filter(function (path) { return !path.endsWith('.map'); })
                .filter(function (path) { return !path.endsWith('.html'); })
                .map(function (path) {
                var stats = libs_1.fs.statSync(path);
                var bytes = stats.size;
                var size = toSize(bytes);
                return { path: path, bytes: bytes, size: size };
            });
            sizes = libs_1.R.sortBy(libs_1.R.prop('bytes'), sizes);
            sizes.reverse();
            head = showHeader
                ? ['file', 'size'].map(function (label) { return libs_1.log.gray(label); })
                : undefined;
            table = libs_1.log.table({ head: head });
            sizes.forEach(function (e) {
                var file = libs_1.fsPath.basename(e.path);
                if (file.endsWith('.js')) {
                    file = libs_1.log.yellow(file);
                }
                else if (file.endsWith('.css')) {
                    file = libs_1.log.cyan(file);
                }
                else {
                    file = libs_1.log.magenta(file);
                }
                table.add([file, e.size]);
            });
            totalBytes = sizes.reduce(function (acc, next) { return acc + next.bytes; }, 0);
            total = {
                bytes: totalBytes,
                size: toSize(totalBytes),
            };
            return [2, { table: table, dir: dir, paths: paths, isEmpty: paths.length === 0, sizes: sizes, total: total }];
        });
    });
}
exports.fileStatsTable = fileStatsTable;
//# sourceMappingURL=logging.js.map