@uizard/nx-fast-s3-cache
Version:
Nx s3 cache using GNU tar, pigz and multipart s3 uploads/downloads
31 lines (30 loc) • 2.52 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkFailure = exports.storeFailure = exports.storeSuccess = exports.setupFailure = exports.retrieveFailure = exports.retrieveSuccess = void 0;
const chalk_1 = require("chalk");
const path_1 = __importDefault(require("path"));
const DELIMITER_LENGTH = 78;
const DELIMITER = Array.from({ length: DELIMITER_LENGTH }, () => "-").join("");
const log = console.log;
const formatSection = (...content) => (0, chalk_1.grey)([DELIMITER, ...content, DELIMITER].join("\n"));
const getTimings = (timings) => `(total:${Object.entries(timings).reduce((p, c) => p + c[1], 0)}ms/${Object.entries(timings)
.map(([k, v]) => `${k}:${v}ms`)
.join("/")})`;
const retrieveSuccess = ({ name }, file, timings = {}) => log(formatSection(`Remote cache hit: ${(0, chalk_1.green)(name)} ${getTimings(timings)}`, `File: ${file}`));
exports.retrieveSuccess = retrieveSuccess;
const retrieveFailure = ({ name }, file, error) => log(formatSection(`${(0, chalk_1.yellow)(`Warning`)}: Failed to retrieve cache from ${(0, chalk_1.red)(name)}`, `File: ${file}`, `Error: ${error === null || error === void 0 ? void 0 : error.message}`));
exports.retrieveFailure = retrieveFailure;
const setupFailure = (error) => {
var _a;
return log(formatSection(`${(0, chalk_1.yellow)(`Warning`)}: Failed to setup remote cache. Check your nx.json.`, `Error: ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`));
};
exports.setupFailure = setupFailure;
const storeSuccess = ({ name }, file, timings = {}) => log(formatSection(`Stored to remote cache: ${(0, chalk_1.green)(name)} ${getTimings(timings)}`, `File: ${path_1.default.basename(file)}`));
exports.storeSuccess = storeSuccess;
const storeFailure = ({ name }, file, error) => log(formatSection(`${(0, chalk_1.yellow)(`Warning`)}: Failed to store cache to ${(0, chalk_1.red)(name)}`, `File: ${file}`, `Error: ${error === null || error === void 0 ? void 0 : error.message}`));
exports.storeFailure = storeFailure;
const checkFailure = ({ name }, file, error) => log(formatSection(`${(0, chalk_1.yellow)(`Warning`)}: Failed to check if cache file exists in ${(0, chalk_1.red)(name)}`, `File: ${file}`, `Error: ${error === null || error === void 0 ? void 0 : error.message}`));
exports.checkFailure = checkFailure;